summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-11-04 17:52:55 +0700
committerhathach <[email protected]>2021-11-04 17:52:55 +0700
commit310f287f4476d22f126c9fc2995f6be7e2b64662 (patch)
tree7816c84b6200bbaa6b190e90d32393cf08a474df
parentf90f5ea3699facfd5681c3bf21e0500f169f8f07 (diff)
couldn't get g4 usb clock and pin setup just yet. Leave it as it is for now
-rw-r--r--hw/bsp/stm32g4/boards/stm32g474nucleo/board.h35
-rw-r--r--hw/bsp/stm32g4/family.c21
2 files changed, 52 insertions, 4 deletions
diff --git a/hw/bsp/stm32g4/boards/stm32g474nucleo/board.h b/hw/bsp/stm32g4/boards/stm32g474nucleo/board.h
index 8d33373af..fd9d50183 100644
--- a/hw/bsp/stm32g4/boards/stm32g474nucleo/board.h
+++ b/hw/bsp/stm32g4/boards/stm32g474nucleo/board.h
@@ -31,6 +31,10 @@
extern "C" {
#endif
+// G474RE Nucleo does not has usb connection. We need to manually connect
+// - PA11 for D+, CN10.14
+// - PA12 for D-, CN10.12
+
// LED
#define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_5
@@ -49,6 +53,7 @@
#define UART_TX_PIN GPIO_PIN_2
#define UART_RX_PIN GPIO_PIN_3
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -81,6 +86,36 @@ static inline void board_clock_init(void)
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_8);
+
+#if 0 // TODO need to check if USB clock is enabled
+ /* Enable HSI48 */
+ memset(&RCC_OscInitStruct, 0, sizeof(RCC_OscInitStruct));
+
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
+ RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+ HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+ /*Enable CRS Clock*/
+ RCC_CRSInitTypeDef RCC_CRSInitStruct= {0};
+ __HAL_RCC_CRS_CLK_ENABLE();
+
+ /* Default Synchro Signal division factor (not divided) */
+ RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
+
+ /* Set the SYNCSRC[1:0] bits according to CRS_Source value */
+ RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
+
+ /* HSI48 is synchronized with USB SOF at 1KHz rate */
+ RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000);
+ RCC_CRSInitStruct.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT;
+
+ /* Set the TRIM[5:0] to the default value */
+ RCC_CRSInitStruct.HSI48CalibrationValue = RCC_CRS_HSI48CALIBRATION_DEFAULT;
+
+ /* Start automatic synchronization */
+ HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct);
+#endif
}
static inline void board_vbus_sense_init(void)
diff --git a/hw/bsp/stm32g4/family.c b/hw/bsp/stm32g4/family.c
index cddd85af0..318f50746 100644
--- a/hw/bsp/stm32g4/family.c
+++ b/hw/bsp/stm32g4/family.c
@@ -31,14 +31,19 @@
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
-void OTG_FS_IRQHandler(void)
+void USB_HP_IRQHandler(void)
{
tud_int_handler(0);
}
-void OTG_HS_IRQHandler(void)
+void USB_LP_IRQHandler(void)
{
- tud_int_handler(1);
+ tud_int_handler(0);
+}
+
+void USBWakeUp_IRQHandler(void)
+{
+ tud_int_handler(0);
}
//--------------------------------------------------------------------+
@@ -111,7 +116,15 @@ void board_init(void)
HAL_UART_Init(&UartHandle);
#endif
- // TODO Configure USB GPIOs
+ // USB Pins TODO double check USB clock and pin setup
+ // Configure USB DM and DP pins. This is optional, and maintained only for user guidance.
+// GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
+// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+// GPIO_InitStruct.Pull = GPIO_NOPULL;
+// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
+// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+//
+// __HAL_RCC_USB_CLK_ENABLE();
board_vbus_sense_init();
}