diff --git a/.idea/cmake.xml b/.idea/cmake.xml
index b8383a5ff..dd219bc77 100644
--- a/.idea/cmake.xml
+++ b/.idea/cmake.xml
@@ -12,7 +12,7 @@
-
+
@@ -94,7 +94,8 @@
-
+
+
@@ -166,7 +167,6 @@
-
\ No newline at end of file
diff --git a/.idea/debugServers/rt1060.xml b/.idea/debugServers/rt1060.xml
index 3325cc81f..cbd295b4e 100644
--- a/.idea/debugServers/rt1060.xml
+++ b/.idea/debugServers/rt1060.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.idea/debugServers/rt1064.xml b/.idea/debugServers/rt1064.xml
index 4dc38ef63..b908b59e2 100644
--- a/.idea/debugServers/rt1064.xml
+++ b/.idea/debugServers/rt1064.xml
@@ -1,11 +1,11 @@
-
+
-
+
diff --git a/.idea/debugServers/sam21.xml b/.idea/debugServers/sam21.xml
index d8763b33b..3f6735bd1 100644
--- a/.idea/debugServers/sam21.xml
+++ b/.idea/debugServers/sam21.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.idea/debugServers/sam51.xml b/.idea/debugServers/sam51.xml
index 0d15ff856..99a92c174 100644
--- a/.idea/debugServers/sam51.xml
+++ b/.idea/debugServers/sam51.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.idea/debugServers/stm32f769.xml b/.idea/debugServers/stm32f769.xml
index 2fb322a0f..22a452218 100644
--- a/.idea/debugServers/stm32f769.xml
+++ b/.idea/debugServers/stm32f769.xml
@@ -1,11 +1,11 @@
-
+
-
+
diff --git a/.idea/debugServers/stm32h563.xml b/.idea/debugServers/stm32h563.xml
index 9bf6db6e9..637839314 100644
--- a/.idea/debugServers/stm32h563.xml
+++ b/.idea/debugServers/stm32h563.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.idea/debugServers/stm32h743.xml b/.idea/debugServers/stm32h743.xml
index 63680b78c..b04e4a708 100644
--- a/.idea/debugServers/stm32h743.xml
+++ b/.idea/debugServers/stm32h743.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 8469aee83..fbb61e10e 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -275,6 +275,7 @@ typedef struct {
typedef struct {
uint8_t controller_id; // controller ID
uint8_t enumerating_daddr; // device address of the device being enumerated
+ uint8_t attach_debouncing_bm; // bitmask for roothub port attach debouncing
tuh_bus_info_t dev0_bus; // bus info for dev0 in enumeration
usbh_ctrl_xfer_info_t ctrl_xfer_info; // control transfer
} usbh_data_t;
@@ -349,7 +350,7 @@ bool tuh_rhport_is_active(uint8_t rhport) {
bool tuh_rhport_reset_bus(uint8_t rhport, bool active) {
TU_VERIFY(tuh_rhport_is_active(rhport));
- if ( active ) {
+ if (active) {
hcd_port_reset(rhport);
} else {
hcd_port_reset_end(rhport);
@@ -512,28 +513,19 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
case HCD_EVENT_DEVICE_ATTACH:
// due to the shared control buffer, we must fully complete enumerating one device first.
// TODO better to have an separated queue for newly attached devices
- if (_usbh_data.enumerating_daddr != TUSB_INDEX_INVALID_8) {
- if (event.rhport == _usbh_data.dev0_bus.rhport &&
- event.connection.hub_addr == _usbh_data.dev0_bus.hub_addr && event.connection.hub_port == _usbh_data.dev0_bus.hub_port) {
- // Some device can cause multiple duplicated attach events
- // drop current enumerating and start over for a proper port reset
- // abort/cancel current enumeration and start new one
- TU_LOG1("[%u:] USBH Device Attach (duplicated)\r\n", event.rhport);
- tuh_edpt_abort_xfer(0, 0);
- enum_new_device(&event);
- } else {
- TU_LOG_USBH("[%u:] USBH Defer Attach until current enumeration complete\r\n", event.rhport);
- bool is_empty = osal_queue_empty(_usbh_q);
- queue_event(&event, in_isr);
-
- if (is_empty) {
- // Exit if this is the only event in the queue, otherwise we may loop forever
- return;
- }
- }
- } else {
+ if (_usbh_data.enumerating_daddr == TUSB_INDEX_INVALID_8) {
+ // New device attached and we are ready
TU_LOG1("[%u:] USBH Device Attach\r\n", event.rhport);
+ _usbh_data.enumerating_daddr = 0; // enumerate new device with address 0
enum_new_device(&event);
+ } else {
+ // currently enumerating another device
+ TU_LOG_USBH("[%u:] USBH Defer Attach until current enumeration complete\r\n", event.rhport);
+ const bool is_empty = osal_queue_empty(_usbh_q);
+ queue_event(&event, in_isr);
+ if (is_empty) {
+ return; // Exit if this is the only event in the queue, otherwise we loop forever
+ }
}
break;
@@ -1021,10 +1013,18 @@ bool tuh_bus_info_get(uint8_t daddr, tuh_bus_info_t* bus_info) {
TU_ATTR_FAST_FUNC void hcd_event_handler(hcd_event_t const* event, bool in_isr) {
switch (event->event_id) {
case HCD_EVENT_DEVICE_ATTACH:
-
- break;
-
case HCD_EVENT_DEVICE_REMOVE:
+ // Attach debouncing on roothub: skip attach/remove while debouncing delay
+ if (event->connection.hub_addr == 0) {
+ if (tu_bit_test(_usbh_data.attach_debouncing_bm, event->rhport)) {
+ return;
+ }
+
+ if (event->event_id == HCD_EVENT_DEVICE_ATTACH) {
+ // No debouncing, set flag if attach event
+ _usbh_data.attach_debouncing_bm |= TU_BIT(event->rhport);
+ }
+ }
break;
default: break;
@@ -1363,6 +1363,7 @@ enum { // USB 2.0 specs 7.1.7 for timing
ENUM_RESET_ROOT_DELAY_MS = 50, // T(DRSTr) minimum 50 ms for reset from root port
ENUM_RESET_HUB_DELAY_MS = 20, // T(DRST) 10-20 ms for hub reset
ENUM_RESET_RECOVERY_DELAY_MS = 10, // T(RSTRCY) minimum 10 ms for reset recovery
+ ENUM_SET_ADDRESS_RECOVERY_DELAY_MS = 2, // USB 2.0 Spec 9.2.6.3 min is 2 ms
};
enum {
@@ -1401,11 +1402,14 @@ static bool enum_new_device(hcd_event_t* event) {
dev0_bus->hub_addr = event->connection.hub_addr;
dev0_bus->hub_port = event->connection.hub_port;
- _usbh_data.enumerating_daddr = 0;
-
// wait until device connection is stable TODO non blocking
tusb_time_delay_ms_api(ENUM_DEBOUNCING_DELAY_MS);
+ // clear roothub debouncing delay
+ if (dev0_bus->hub_addr == 0) {
+ _usbh_data.attach_debouncing_bm &= (uint8_t) ~TU_BIT(dev0_bus->rhport);
+ }
+
if (dev0_bus->hub_addr == 0) {
// connected directly to roothub
// USB bus not active and frame number is not available yet.
@@ -1570,8 +1574,7 @@ static void process_enumeration(tuh_xfer_t* xfer) {
}
case ENUM_GET_DEVICE_DESC: {
- // Allow 2ms for address recovery time, Ref USB Spec 9.2.6.3
- tusb_time_delay_ms_api(2);
+ tusb_time_delay_ms_api(ENUM_SET_ADDRESS_RECOVERY_DELAY_MS); // set address recovery
const uint8_t new_addr = (uint8_t) tu_le16toh(xfer->setup->wValue);
usbh_device_t* new_dev = get_device(new_addr);
diff --git a/src/host/usbh.h b/src/host/usbh.h
index 6f09f0c80..6f34d8bb3 100644
--- a/src/host/usbh.h
+++ b/src/host/usbh.h
@@ -86,6 +86,9 @@ typedef struct {
uint8_t speed;
} tuh_bus_info_t;
+// backward compatibility for hcd_devtree_info_t, maybe removed in the future
+#define hcd_devtree_info_t tuh_bus_info_t
+#define hcd_devtree_get_info(_daddr, _bus_info) tuh_bus_info_get(_daddr, _bus_info)
// ConfigID for tuh_configure()
enum {
diff --git a/src/portable/chipidea/ci_hs/hcd_ci_hs.c b/src/portable/chipidea/ci_hs/hcd_ci_hs.c
index 22eb22690..b5324a754 100644
--- a/src/portable/chipidea/ci_hs/hcd_ci_hs.c
+++ b/src/portable/chipidea/ci_hs/hcd_ci_hs.c
@@ -93,12 +93,6 @@ bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
hcd_reg->USBMODE = USBMODE_CM_HOST;
#endif
- // FIXME force full speed, still have issue with Highspeed enumeration
- // probably due to physical connection bouncing when plug/unplug
- // 1. Have issue when plug/unplug devices, maybe the port is not reset properly
- // 2. Also does not seems to detect disconnection
- hcd_reg->PORTSC1 |= PORTSC1_FORCE_FULL_SPEED;
-
return ehci_init(rhport, (uint32_t) &hcd_reg->CAPLENGTH, (uint32_t) &hcd_reg->USBCMD);
}
diff --git a/src/portable/synopsys/dwc2/hcd_dwc2.c b/src/portable/synopsys/dwc2/hcd_dwc2.c
index 7c29a03cf..2de15068a 100644
--- a/src/portable/synopsys/dwc2/hcd_dwc2.c
+++ b/src/portable/synopsys/dwc2/hcd_dwc2.c
@@ -107,7 +107,6 @@ typedef struct {
typedef struct {
hcd_xfer_t xfer[DWC2_CHANNEL_COUNT_MAX];
hcd_endpoint_t edpt[CFG_TUH_DWC2_ENDPOINT_MAX];
- bool attach_debounce; // if true: wait for the debounce delay before issuing new attach events
} hcd_data_t;
hcd_data_t _hcd_data;
@@ -423,11 +422,6 @@ uint32_t hcd_frame_number(uint8_t rhport) {
// Get the current connect status of roothub port
bool hcd_port_connect_status(uint8_t rhport) {
- // this is called from enum_new_device() - after the debouncing delays
- if (_hcd_data.attach_debounce) {
- _hcd_data.attach_debounce = false; // allow new attach events again
- }
-
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
return dwc2->hprt & HPRT_CONN_STATUS;
}
@@ -1328,10 +1322,7 @@ static void handle_hprt_irq(uint8_t rhport, bool in_isr) {
hprt |= HPRT_CONN_DETECT;
if (hprt_bm.conn_status) {
- if (!_hcd_data.attach_debounce) {
- _hcd_data.attach_debounce = true; // block new attach events until the debounce delay is over
- hcd_event_device_attach(rhport, in_isr);
- }
+ hcd_event_device_attach(rhport, in_isr);
}
}
@@ -1398,12 +1389,8 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
// Device disconnected
dwc2->gintsts = GINTSTS_DISCINT;
- // ignore device removal if attach debounce is active
- // it will evaluate the port status after the debounce delay
- if (!_hcd_data.attach_debounce) {
- if (!(dwc2->hprt & HPRT_CONN_STATUS)) {
- hcd_event_device_remove(rhport, in_isr);
- }
+ if (!(dwc2->hprt & HPRT_CONN_STATUS)) {
+ hcd_event_device_remove(rhport, in_isr);
}
}