diff --git a/hw/bsp/stm32f4/boards/feather_stm32f405/board.h b/hw/bsp/stm32f4/boards/feather_stm32f405/board.h index 11e976a42..2db42b98a 100644 --- a/hw/bsp/stm32f4/boards/feather_stm32f405/board.h +++ b/hw/bsp/stm32f4/boards/feather_stm32f405/board.h @@ -43,6 +43,8 @@ #define PINID_UART_TX 2 #define PINID_UART_RX 3 +#define VBUS_SENSE_EN 1 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOC, @@ -106,14 +108,6 @@ static inline void board_clock_init(void) __HAL_RCC_USART3_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - if (rhport == 0) { - // Enable VBUS sense (B device) via pin PA9 - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { (void) rhport; (void) state; } diff --git a/hw/bsp/stm32f4/boards/pyboardv11/board.h b/hw/bsp/stm32f4/boards/pyboardv11/board.h index 9583a924b..319d2336a 100644 --- a/hw/bsp/stm32f4/boards/pyboardv11/board.h +++ b/hw/bsp/stm32f4/boards/pyboardv11/board.h @@ -43,6 +43,8 @@ #define PINID_UART_TX 2 #define PINID_UART_RX 3 +#define VBUS_SENSE_EN 1 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOB, @@ -106,14 +108,6 @@ static inline void board_clock_init(void) __HAL_RCC_USART2_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - if (rhport == 0) { - // Enable VBUS sense (B device) via pin PA9 - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { (void) rhport; (void) state; } diff --git a/hw/bsp/stm32f4/boards/stm32f401blackpill/board.h b/hw/bsp/stm32f4/boards/stm32f401blackpill/board.h index 8a3fe8409..b69ebbeaf 100644 --- a/hw/bsp/stm32f4/boards/stm32f401blackpill/board.h +++ b/hw/bsp/stm32f4/boards/stm32f401blackpill/board.h @@ -44,6 +44,8 @@ #define PINID_UART_TX 2 #define PINID_UART_RX 3 +#define VBUS_SENSE_EN 0 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOC, @@ -107,15 +109,6 @@ static inline void board_clock_init(void) __HAL_RCC_USART2_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - // Blackpill doesn't use VBUS sense (B device) explicitly disable it - if (rhport == 0) { - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN; - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { (void) rhport; (void) state; } diff --git a/hw/bsp/stm32f4/boards/stm32f407blackvet/board.h b/hw/bsp/stm32f4/boards/stm32f407blackvet/board.h index effbf2be8..ebefeb988 100644 --- a/hw/bsp/stm32f4/boards/stm32f407blackvet/board.h +++ b/hw/bsp/stm32f4/boards/stm32f407blackvet/board.h @@ -44,6 +44,8 @@ #define PINID_UART_TX 2 #define PINID_UART_RX 3 +#define VBUS_SENSE_EN 0 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOA, @@ -106,15 +108,6 @@ static inline void board_clock_init(void) __HAL_RCC_USART2_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - if (rhport == 0) { - // Black F407VET6 doesn't use VBUS sense (B device) explicitly disable it - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN; - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { (void) rhport; (void) state; } diff --git a/hw/bsp/stm32f4/boards/stm32f407disco/board.h b/hw/bsp/stm32f4/boards/stm32f407disco/board.h index 19a029768..bcfa6059a 100644 --- a/hw/bsp/stm32f4/boards/stm32f407disco/board.h +++ b/hw/bsp/stm32f4/boards/stm32f407disco/board.h @@ -46,6 +46,8 @@ #define PINID_UART_RX 3 #define PINID_VBUS0_EN 4 +#define VBUS_SENSE_EN 1 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOD, @@ -114,14 +116,6 @@ static inline void board_clock_init(void) __HAL_RCC_USART2_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - if (rhport == 0) { - // Enable VBUS sense (B device) via pin PA9 - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { if (rhport == 0) { board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN]; diff --git a/hw/bsp/stm32f4/boards/stm32f411blackpill/board.h b/hw/bsp/stm32f4/boards/stm32f411blackpill/board.h index 61e5de70d..0faf6fe11 100644 --- a/hw/bsp/stm32f4/boards/stm32f411blackpill/board.h +++ b/hw/bsp/stm32f4/boards/stm32f411blackpill/board.h @@ -43,6 +43,8 @@ #define PINID_UART_TX 2 #define PINID_UART_RX 3 +#define VBUS_SENSE_EN 0 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOC, @@ -106,15 +108,6 @@ static inline void board_clock_init(void) __HAL_RCC_USART2_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - // Blackpill doesn't use VBUS sense (B device) explicitly disable it - if (rhport == 0) { - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN; - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { (void) rhport; (void) state; } diff --git a/hw/bsp/stm32f4/boards/stm32f411disco/board.h b/hw/bsp/stm32f4/boards/stm32f411disco/board.h index d7b02e79d..1a289dfb5 100644 --- a/hw/bsp/stm32f4/boards/stm32f411disco/board.h +++ b/hw/bsp/stm32f4/boards/stm32f411disco/board.h @@ -44,6 +44,8 @@ #define PINID_UART_RX 3 #define PINID_VBUS0_EN 4 +#define VBUS_SENSE_EN 1 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOD, @@ -111,14 +113,6 @@ static inline void board_clock_init(void) { __HAL_RCC_USART2_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - // Enable VBUS sense (B device) via pin PA9 - if (rhport == 0) { - USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { if (rhport == 0) { board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN]; diff --git a/hw/bsp/stm32f4/boards/stm32f412disco/board.h b/hw/bsp/stm32f4/boards/stm32f412disco/board.h index d5146ae3c..0689dfe87 100644 --- a/hw/bsp/stm32f4/boards/stm32f412disco/board.h +++ b/hw/bsp/stm32f4/boards/stm32f412disco/board.h @@ -45,6 +45,8 @@ #define PINID_UART_RX 3 #define PINID_VBUS0_EN 4 +#define VBUS_SENSE_EN 1 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOE, @@ -127,13 +129,6 @@ static inline void board_clock_init(void) { __HAL_RCC_USART2_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - if (rhport == 0) { - // Enable VBUS sense (B device) via pin PA9 - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { if (rhport == 0) { board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN]; diff --git a/hw/bsp/stm32f4/boards/stm32f412nucleo/board.h b/hw/bsp/stm32f4/boards/stm32f412nucleo/board.h index f7026ce61..be58f8ae7 100644 --- a/hw/bsp/stm32f4/boards/stm32f412nucleo/board.h +++ b/hw/bsp/stm32f4/boards/stm32f412nucleo/board.h @@ -45,6 +45,8 @@ #define PINID_UART_RX 3 #define PINID_VBUS0_EN 4 +#define VBUS_SENSE_EN 1 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOB, @@ -128,13 +130,6 @@ static inline void board_clock_init(void) __HAL_RCC_USART3_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - if (rhport == 0) { - // Enable VBUS sense (B device) via pin PA9 - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { if (rhport == 0) { board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN]; diff --git a/hw/bsp/stm32f4/boards/stm32f439nucleo/board.h b/hw/bsp/stm32f4/boards/stm32f439nucleo/board.h index 9a348f33f..b1633b395 100644 --- a/hw/bsp/stm32f4/boards/stm32f439nucleo/board.h +++ b/hw/bsp/stm32f4/boards/stm32f439nucleo/board.h @@ -46,6 +46,8 @@ #define PINID_UART_RX 3 #define PINID_VBUS0_EN 4 +#define VBUS_SENSE_EN 1 + static board_pindef_t board_pindef[] = { { // LED .port = GPIOB, @@ -117,14 +119,6 @@ static inline void board_clock_init(void) __HAL_RCC_USART3_CLK_ENABLE(); } -static inline void board_vbus_sense_init(uint8_t rhport) { - if (rhport == 0) { - // Enable VBUS sense (B device) via pin PA9 - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; - } -} - static inline void board_vbus_set(uint8_t rhport, bool state) { if (rhport == 0) { board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN]; diff --git a/hw/bsp/stm32f4/family.c b/hw/bsp/stm32f4/family.c index 025f6a08c..2170faca7 100644 --- a/hw/bsp/stm32f4/family.c +++ b/hw/bsp/stm32f4/family.c @@ -180,11 +180,16 @@ void board_init(void) { #endif #if CFG_TUD_ENABLED - board_vbus_sense_init(BOARD_TUD_RHPORT); + tud_configure_dwc2_t cfg = { + .bm_double_buffered = 0, + .vbus_sensing = VBUS_SENSE_EN + }; + tud_configure(BOARD_TUD_RHPORT, TUD_CFGID_DWC2, &cfg); + board_vbus_set(BOARD_TUD_RHPORT, false); #endif #if CFG_TUH_ENABLED - board_vbus_set(BOARD_TUD_RHPORT, true); + board_vbus_set(BOARD_TUH_RHPORT, true); #endif }