summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2026-01-30 19:29:07 +0100
committerHiFiPhile <[email protected]>2026-01-31 00:21:23 +0100
commite19dace3fb83754891d7c05f6e00237b02323fdc (patch)
tree65bd3067ac9e50834584aa550afd0e6cc313ef47
parentf89ef31a3ac2b3b388a6d4b371ddedd7901e45d9 (diff)
bsp/stm32h7rs: update vbus sense
Signed-off-by: HiFiPhile <[email protected]>
-rw-r--r--hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h2
-rw-r--r--hw/bsp/stm32h7rs/family.c53
2 files changed, 27 insertions, 28 deletions
diff --git a/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h b/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h
index 4fb72cce8..16c2fd335 100644
--- a/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h
+++ b/hw/bsp/stm32h7rs/boards/stm32h7s3nucleo/board.h
@@ -44,7 +44,7 @@
#define UART_CLK_EN __HAL_RCC_USART3_CLK_ENABLE
// VBUS Sense detection
-#define OTG_FS_VBUS_SENSE 1
+#define OTG_FS_VBUS_SENSE 0
#define OTG_HS_VBUS_SENSE 0
#define PINID_LED 0
diff --git a/hw/bsp/stm32h7rs/family.c b/hw/bsp/stm32h7rs/family.c
index 784c92465..b1980f2ed 100644
--- a/hw/bsp/stm32h7rs/family.c
+++ b/hw/bsp/stm32h7rs/family.c
@@ -356,17 +356,16 @@ void board_init(void) {
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOM, &GPIO_InitStruct);
+#endif // vbus sense
- // Enable VBUS sense (B device) via pin PM14
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-#else
- // Disable VBUS sense (B device)
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
+#if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 0
+ tud_configure_dwc2_t cfg = {
+ .bm_double_buffered = 0,
+ .vbus_sensing = OTG_FS_VBUS_SENSE
+ };
+ tud_configure(0, TUD_CFGID_DWC2, &cfg);
+#endif
- // B-peripheral session valid override enable
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
- USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
-#endif // vbus sense
#endif
//------------- USB HS -------------//
@@ -382,33 +381,33 @@ void board_init(void) {
#if OTG_HS_VBUS_SENSE
// Configure VBUS Pin
- GPIO_InitStruct.Pin = GPIO_PIN_9;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
- HAL_GPIO_Init(GPIOM, &GPIO_InitStruct);
-
- // Enable VBUS sense (B device) via pin PM9
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-#else
- // Disable VBUS sense (B device)
- USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
+ GPIO_InitTypeDef GPIO_InitStruct2;
+ GPIO_InitStruct2.Pin = GPIO_PIN_8;
+ GPIO_InitStruct2.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct2.Pull = GPIO_NOPULL;
+ GPIO_InitStruct2.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOM, &GPIO_InitStruct2);
+#endif
#if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1
- // B-peripheral session valid override enable
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
-#else
- USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_PULLDOWNEN;
+ tud_configure_dwc2_t cfg = {
+ .bm_double_buffered = 0,
+ .vbus_sensing = OTG_HS_VBUS_SENSE
+ };
+ tud_configure(1, TUD_CFGID_DWC2, &cfg);
#endif
#endif
-#endif
board_init2();
+ // Turn off device vbus
+#if CFG_TUD_ENABLED
+ board_vbus_set(BOARD_TUD_RHPORT, false);
+#endif
+ // Turn on host vbus
#if CFG_TUH_ENABLED
- board_vbus_set(BOARD_TUH_RHPORT, 1);
+ board_vbus_set(BOARD_TUH_RHPORT, true);
#endif
}