summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2026-01-30 19:29:32 +0100
committerHiFiPhile <[email protected]>2026-01-31 00:21:23 +0100
commit0e88879f676fd44c1c48f2b1427c441f70d82d97 (patch)
tree42899aedaa43fdff7da16ce24f74d0dfc5d0f50f
parente19dace3fb83754891d7c05f6e00237b02323fdc (diff)
bsp/stm32l4: update vbus sense
Signed-off-by: HiFiPhile <[email protected]>
-rw-r--r--hw/bsp/stm32l4/boards/stm32l476disco/board.h11
-rw-r--r--hw/bsp/stm32l4/boards/stm32l496nucleo/board.h8
-rw-r--r--hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h8
-rw-r--r--hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h8
-rw-r--r--hw/bsp/stm32l4/family.c12
5 files changed, 18 insertions, 29 deletions
diff --git a/hw/bsp/stm32l4/boards/stm32l476disco/board.h b/hw/bsp/stm32l4/boards/stm32l476disco/board.h
index 8c766d8ea..cf84d3e66 100644
--- a/hw/bsp/stm32l4/boards/stm32l476disco/board.h
+++ b/hw/bsp/stm32l4/boards/stm32l476disco/board.h
@@ -51,6 +51,8 @@
#define UART_TX_PIN GPIO_PIN_5
#define UART_RX_PIN GPIO_PIN_6
+#define VBUS_SENSE_EN 0
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -128,15 +130,6 @@ static inline void board_clock_init(void)
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
}
-static inline void board_vbus_sense_init(void)
-{
- // L476Disco use general GPIO PC11 for VBUS sensing instead of dedicated PA9 as others
- // Disable VBUS Sense and force device mode
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN | USB_OTG_GOTGCTL_BVALOVAL;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32l4/boards/stm32l496nucleo/board.h b/hw/bsp/stm32l4/boards/stm32l496nucleo/board.h
index 607210cec..3b031e00f 100644
--- a/hw/bsp/stm32l4/boards/stm32l496nucleo/board.h
+++ b/hw/bsp/stm32l4/boards/stm32l496nucleo/board.h
@@ -52,6 +52,8 @@
#define UART_TX_PIN GPIO_PIN_7
#define UART_RX_PIN GPIO_PIN_8
+#define VBUS_SENSE_EN 1
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -145,12 +147,6 @@ static inline void board_clock_init(void)
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}
-static inline void board_vbus_sense_init(void)
-{
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h b/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h
index f522e7522..94978638e 100644
--- a/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h
+++ b/hw/bsp/stm32l4/boards/stm32l4p5nucleo/board.h
@@ -51,6 +51,8 @@
#define UART_TX_PIN GPIO_PIN_7
#define UART_RX_PIN GPIO_PIN_8
+#define VBUS_SENSE_EN 1
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -129,12 +131,6 @@ static inline void board_clock_init(void)
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}
-static inline void board_vbus_sense_init(void)
-{
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h b/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h
index c181f5d4a..f603ae855 100644
--- a/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h
+++ b/hw/bsp/stm32l4/boards/stm32l4r5nucleo/board.h
@@ -51,6 +51,8 @@
#define UART_TX_PIN GPIO_PIN_7
#define UART_RX_PIN GPIO_PIN_8
+#define VBUS_SENSE_EN 1
+
//--------------------------------------------------------------------+
// RCC Clock
//--------------------------------------------------------------------+
@@ -129,12 +131,6 @@ static inline void board_clock_init(void)
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}
-static inline void board_vbus_sense_init(void)
-{
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/stm32l4/family.c b/hw/bsp/stm32l4/family.c
index e69ae8e3b..b51a9fc8f 100644
--- a/hw/bsp/stm32l4/family.c
+++ b/hw/bsp/stm32l4/family.c
@@ -170,10 +170,18 @@ void board_init(void) {
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
#endif
- /* Enable USB FS Clocks */
#if defined(USB_OTG_FS)
+ /* Enable USB FS Clocks */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
- board_vbus_sense_init();
+
+ #if CFG_TUD_ENABLED
+ /* Set Vbus sense */
+ tud_configure_dwc2_t cfg = {
+ .bm_double_buffered = 0,
+ .vbus_sensing = VBUS_SENSE_EN
+ };
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+ #endif
#else
__HAL_RCC_USB_CLK_ENABLE();
#endif