bsp/stm32f4: update vbus sense

Signed-off-by: HiFiPhile <admin@hifiphile.com>
This commit is contained in:
HiFiPhile
2026-01-30 19:25:52 +01:00
parent 1a299a0a0c
commit d0594fbd86
11 changed files with 27 additions and 83 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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];

View File

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

View File

@ -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];

View File

@ -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];

View File

@ -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];

View File

@ -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];

View File

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