summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-03-17 13:58:01 +0700
committerhathach <[email protected]>2023-03-17 13:58:01 +0700
commitf349ae77029c3a82bd9509c1ad57e3e6cd815596 (patch)
tree2aa0afe96ebaf238ec152ab5599a0bd4a5d9aeda /src
parent6b84a29f8c7737e4cc832e2b61080dcb7c29974f (diff)
fix enumerate one device at a time
Diffstat (limited to 'src')
-rw-r--r--src/host/usbh.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 12b0ed203..45a2a0c66 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -54,8 +54,6 @@
// USBH-HCD common data structure
//--------------------------------------------------------------------+
-// device0 struct must be strictly a subset of normal device struct
-// TODO refactor later
typedef struct
{
// port
@@ -63,15 +61,13 @@ typedef struct
uint8_t hub_addr;
uint8_t hub_port;
uint8_t speed;
+ volatile uint8_t enumerating;
- struct TU_ATTR_PACKED
- {
- volatile uint8_t connected : 1;
- volatile uint8_t addressed : 1;
- volatile uint8_t configured : 1;
- volatile uint8_t suspended : 1;
- };
-
+// struct TU_ATTR_PACKED {
+// uint8_t speed : 4; // packed speed to save footprint
+// volatile uint8_t enumerating : 1;
+// uint8_t TU_RESERVED : 3;
+// };
} usbh_dev0_t;
typedef struct {
@@ -402,10 +398,18 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
switch (event.event_id)
{
case HCD_EVENT_DEVICE_ATTACH:
- // TODO due to the shared _usbh_ctrl_buf, we must complete enumerating
+ // due to the shared _usbh_ctrl_buf, we must complete enumerating
// one device before enumerating another one.
- TU_LOG_USBH("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
- enum_new_device(&event);
+ if ( _dev0.enumerating )
+ {
+ TU_LOG1("[%u:] USBH Defer Attach until current enumeration complete\r\n", event.rhport);
+ osal_queue_send(_usbh_q, &event, in_isr);
+ }else
+ {
+ TU_LOG1("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
+ _dev0.enumerating = 1;
+ enum_new_device(&event);
+ }
break;
case HCD_EVENT_DEVICE_REMOVE:
@@ -1623,6 +1627,9 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
static void enum_full_complete(void)
{
+ // mark enumeration as complete
+ _dev0.enumerating = 0;
+
#if CFG_TUH_HUB
// get next hub status
if (_dev0.hub_addr) hub_edpt_status_xfer(_dev0.hub_addr);