bsp/stm32h7: update vbus sense

Signed-off-by: HiFiPhile <admin@hifiphile.com>
This commit is contained in:
HiFiPhile
2026-01-30 19:27:05 +01:00
parent 6c4be07c74
commit f89ef31a3a
3 changed files with 23 additions and 27 deletions

View File

@ -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 \

View File

@ -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 \

View File

@ -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
}