summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2026-01-30 19:27:05 +0100
committerHiFiPhile <[email protected]>2026-01-31 00:21:23 +0100
commitf89ef31a3ac2b3b388a6d4b371ddedd7901e45d9 (patch)
tree98a6ba21852668e47c7b8bc89d78499432d80f89
parent6c4be07c74883290f5fbb13787be63f3be533898 (diff)
bsp/stm32h7: update vbus sense
Signed-off-by: HiFiPhile <[email protected]>
-rw-r--r--hw/bsp/stm32h7/boards/stm32h743eval/board.h2
-rw-r--r--hw/bsp/stm32h7/boards/stm32h747disco/board.h2
-rw-r--r--hw/bsp/stm32h7/family.c46
3 files changed, 23 insertions, 27 deletions
diff --git a/hw/bsp/stm32h7/boards/stm32h743eval/board.h b/hw/bsp/stm32h7/boards/stm32h743eval/board.h
index 96bfc24e1..44ca58dc5 100644
--- a/hw/bsp/stm32h7/boards/stm32h743eval/board.h
+++ b/hw/bsp/stm32h7/boards/stm32h743eval/board.h
@@ -44,7 +44,7 @@
// VBUS Sense detection
#define OTG_FS_VBUS_SENSE 1
-#define OTG_HS_VBUS_SENSE 0
+#define OTG_HS_VBUS_SENSE 1
// USB HS External PHY Pin: CLK, STP, DIR, NXT, D0-D7
#define ULPI_PINS \
diff --git a/hw/bsp/stm32h7/boards/stm32h747disco/board.h b/hw/bsp/stm32h7/boards/stm32h747disco/board.h
index 71e8b1427..458aa48b6 100644
--- a/hw/bsp/stm32h7/boards/stm32h747disco/board.h
+++ b/hw/bsp/stm32h7/boards/stm32h747disco/board.h
@@ -42,7 +42,7 @@
// VBUS Sense detection
#define OTG_FS_VBUS_SENSE 1
-#define OTG_HS_VBUS_SENSE 0
+#define OTG_HS_VBUS_SENSE 1
// USB HS External PHY Pin: CLK, STP, DIR, NXT, D0-D7
#define ULPI_PINS \
diff --git a/hw/bsp/stm32h7/family.c b/hw/bsp/stm32h7/family.c
index 054d7855f..920f222d7 100644
--- a/hw/bsp/stm32h7/family.c
+++ b/hw/bsp/stm32h7/family.c
@@ -180,18 +180,16 @@ void board_init(void) {
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- // Enable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
-#else
- // Disable VBUS sense (B device) via pin PA9
- USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // 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
+#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
+
//------------- USB HS -------------//
#if (CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1) || (CFG_TUH_ENABLED && BOARD_TUH_RHPORT == 1)
// Despite being call USB2_OTG
@@ -216,28 +214,26 @@ void board_init(void) {
__HAL_RCC_USB1_OTG_HS_ULPI_CLK_ENABLE();
__HAL_RCC_USB1_OTG_HS_CLK_ENABLE();
-#if OTG_HS_VBUS_SENSE
- #error OTG HS VBUS Sense enabled is not implemented
-#else
- // No VBUS sense
- USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
-
- // B-peripheral session valid override enable
- USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
- USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
-#endif
-
- // Force device mode
- USB_OTG_HS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD;
- USB_OTG_HS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
+ #if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1
+ tud_configure_dwc2_t cfg = {
+ .bm_double_buffered = 0,
+ .vbus_sensing = OTG_HS_VBUS_SENSE
+ };
+ tud_configure(1, TUD_CFGID_DWC2, &cfg);
+ #endif
#endif
HAL_PWREx_EnableUSBVoltageDetector();
board_init2(); // optional init
+ // 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
}