summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2026-02-13 22:29:14 +0700
committerhathach <[email protected]>2026-02-13 22:29:14 +0700
commitf0b44ec6154237a4bd65a5a9d8f8bf944669af64 (patch)
treea19e77e93d1e9b690dd0ac27cf1f22682f142c86
parent8f14cf4bfa061690084c7c32b3f8b70301f5e0ff (diff)
use CFG_TUD_CONFIGURE_DWC2_DEFAULT to make it easier to add more value
-rw-r--r--hw/bsp/stm32f2/family.c6
-rw-r--r--hw/bsp/stm32f4/family.c6
-rw-r--r--hw/bsp/stm32f7/family.c12
-rw-r--r--hw/bsp/stm32h7/family.c12
-rw-r--r--hw/bsp/stm32h7rs/family.c12
-rw-r--r--hw/bsp/stm32l4/family.c6
-rw-r--r--hw/bsp/stm32u5/family.c12
-rw-r--r--src/device/usbd.h4
-rw-r--r--src/portable/synopsys/dwc2/dcd_dwc2.c2
-rw-r--r--src/tusb_option.h10
10 files changed, 31 insertions, 51 deletions
diff --git a/hw/bsp/stm32f2/family.c b/hw/bsp/stm32f2/family.c
index f863a59f0..f95128040 100644
--- a/hw/bsp/stm32f2/family.c
+++ b/hw/bsp/stm32f2/family.c
@@ -106,10 +106,8 @@ void board_init(void) {
#if CFG_TUD_ENABLED
// Enable VBUS sense (B device) via pin PA9
- tud_configure_dwc2_t cfg = {
- .bm_double_buffered = 0,
- .vbus_sensing = true
- };
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = true;
tud_configure(0, TUD_CFGID_DWC2, &cfg);
#endif
}
diff --git a/hw/bsp/stm32f4/family.c b/hw/bsp/stm32f4/family.c
index 2170faca7..f0e9620f2 100644
--- a/hw/bsp/stm32f4/family.c
+++ b/hw/bsp/stm32f4/family.c
@@ -180,10 +180,8 @@ void board_init(void) {
#endif
#if CFG_TUD_ENABLED
- tud_configure_dwc2_t cfg = {
- .bm_double_buffered = 0,
- .vbus_sensing = VBUS_SENSE_EN
- };
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = VBUS_SENSE_EN;
tud_configure(BOARD_TUD_RHPORT, TUD_CFGID_DWC2, &cfg);
board_vbus_set(BOARD_TUD_RHPORT, false);
#endif
diff --git a/hw/bsp/stm32f7/family.c b/hw/bsp/stm32f7/family.c
index fc1c0bd13..d8f0da201 100644
--- a/hw/bsp/stm32f7/family.c
+++ b/hw/bsp/stm32f7/family.c
@@ -157,10 +157,8 @@ void board_init(void) {
#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_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_FS_VBUS_SENSE;
tud_configure(0, TUD_CFGID_DWC2, &cfg);
#endif
@@ -239,10 +237,8 @@ void board_init(void) {
__HAL_RCC_USB_OTG_HS_CLK_ENABLE();
#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_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_HS_VBUS_SENSE;
tud_configure(1, TUD_CFGID_DWC2, &cfg);
#endif
diff --git a/hw/bsp/stm32h7/family.c b/hw/bsp/stm32h7/family.c
index 920f222d7..a320a7e72 100644
--- a/hw/bsp/stm32h7/family.c
+++ b/hw/bsp/stm32h7/family.c
@@ -183,10 +183,8 @@ void board_init(void) {
#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_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_FS_VBUS_SENSE;
tud_configure(0, TUD_CFGID_DWC2, &cfg);
#endif
@@ -215,10 +213,8 @@ void board_init(void) {
__HAL_RCC_USB1_OTG_HS_CLK_ENABLE();
#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_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_HS_VBUS_SENSE;
tud_configure(1, TUD_CFGID_DWC2, &cfg);
#endif
#endif
diff --git a/hw/bsp/stm32h7rs/family.c b/hw/bsp/stm32h7rs/family.c
index b1980f2ed..2cc39b7ac 100644
--- a/hw/bsp/stm32h7rs/family.c
+++ b/hw/bsp/stm32h7rs/family.c
@@ -359,10 +359,8 @@ void board_init(void) {
#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_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_FS_VBUS_SENSE;
tud_configure(0, TUD_CFGID_DWC2, &cfg);
#endif
@@ -390,10 +388,8 @@ void board_init(void) {
#endif
#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_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = OTG_HS_VBUS_SENSE;
tud_configure(1, TUD_CFGID_DWC2, &cfg);
#endif
diff --git a/hw/bsp/stm32l4/family.c b/hw/bsp/stm32l4/family.c
index b51a9fc8f..65f6b9ab3 100644
--- a/hw/bsp/stm32l4/family.c
+++ b/hw/bsp/stm32l4/family.c
@@ -176,10 +176,8 @@ void board_init(void) {
#if CFG_TUD_ENABLED
/* Set Vbus sense */
- tud_configure_dwc2_t cfg = {
- .bm_double_buffered = 0,
- .vbus_sensing = VBUS_SENSE_EN
- };
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = VBUS_SENSE_EN;
tud_configure(0, TUD_CFGID_DWC2, &cfg);
#endif
#else
diff --git a/hw/bsp/stm32u5/family.c b/hw/bsp/stm32u5/family.c
index c2ea270df..dfcf5c537 100644
--- a/hw/bsp/stm32u5/family.c
+++ b/hw/bsp/stm32u5/family.c
@@ -182,10 +182,8 @@ void board_init(void) {
#endif // vbus sense
#if CFG_TUD_ENABLED
- tud_configure_dwc2_t cfg = {
- .bm_double_buffered = 0,
- .vbus_sensing = VBUS_SENSE_EN
- };
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = VBUS_SENSE_EN;
tud_configure(0, TUD_CFGID_DWC2, &cfg);
#endif
@@ -217,10 +215,8 @@ void board_init(void) {
HAL_SYSCFG_EnableOTGPHY(SYSCFG_OTG_HS_PHY_ENABLE);
#if CFG_TUD_ENABLED
- tud_configure_dwc2_t cfg = {
- .bm_double_buffered = 0,
- .vbus_sensing = VBUS_SENSE_EN
- };
+ tud_configure_dwc2_t cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
+ cfg.vbus_sensing = VBUS_SENSE_EN;
tud_configure(0, TUD_CFGID_DWC2, &cfg);
#endif
#endif // USB_OTG_FS
diff --git a/src/device/usbd.h b/src/device/usbd.h
index eaf07b81e..825fdba90 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -44,7 +44,9 @@ typedef struct {
bool vbus_sensing; // Vbus pin is used for device connection detection, mandatory for tud_umount_cb()
} tud_configure_dwc2_t;
-#define TUD_CONFIGURE_DWC2_DEFAULT { .bm_double_buffered = 0, .vbus_sensing = CFG_TUD_VBUS_SENSE }
+ #ifndef CFG_TUD_CONFIGURE_DWC2_DEFAULT
+ #define CFG_TUD_CONFIGURE_DWC2_DEFAULT {.bm_double_buffered = 0, .vbus_sensing = CFG_TUD_VBUS_DETECT_HW}
+ #endif
typedef union {
tud_configure_dwc2_t dwc2;
diff --git a/src/portable/synopsys/dwc2/dcd_dwc2.c b/src/portable/synopsys/dwc2/dcd_dwc2.c
index a6a598dbf..97e83f4e1 100644
--- a/src/portable/synopsys/dwc2/dcd_dwc2.c
+++ b/src/portable/synopsys/dwc2/dcd_dwc2.c
@@ -77,7 +77,7 @@ CFG_TUD_MEM_SECTION static struct {
TUD_EPBUF_DEF(setup_packet, 8);
} _dcd_usbbuf;
-static tud_configure_dwc2_t _tud_cfg = TUD_CONFIGURE_DWC2_DEFAULT;
+static tud_configure_dwc2_t _tud_cfg = CFG_TUD_CONFIGURE_DWC2_DEFAULT;
TU_ATTR_ALWAYS_INLINE static inline uint8_t dwc2_ep_count(const dwc2_regs_t* dwc2) {
#if TU_CHECK_MCU(OPT_MCU_GD32VF103)
diff --git a/src/tusb_option.h b/src/tusb_option.h
index ebf366e17..d87c2dc8b 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -579,13 +579,13 @@
#define CFG_TUD_TEST_MODE 0
#endif
-#ifndef CFG_TUD_VBUS_SENSE_DEFAULT
- #define CFG_TUD_VBUS_SENSE_DEFAULT 0
+#ifndef CFG_TUD_VBUS_DETECT_HW_DEFAULT
+ #define CFG_TUD_VBUS_DETECT_HW_DEFAULT 0
#endif
-// Enable VBUS Sensing
-#ifndef CFG_TUD_VBUS_SENSE
- #define CFG_TUD_VBUS_SENSE CFG_TUD_VBUS_SENSE_DEFAULT
+// Enable VBUS Detect hardware, usually via functional GPIO
+#ifndef CFG_TUD_VBUS_DETECT_HW
+ #define CFG_TUD_VBUS_DETECT_HW CFG_TUD_VBUS_DETECT_HW_DEFAULT
#endif
//------------- Device Class Driver -------------//