Skip to content

Commit f349ae7

Browse files
committed
fix enumerate one device at a time
1 parent 6b84a29 commit f349ae7

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/host/usbh.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -54,24 +54,20 @@
5454
// USBH-HCD common data structure
5555
//--------------------------------------------------------------------+
5656

57-
// device0 struct must be strictly a subset of normal device struct
58-
// TODO refactor later
5957
typedef struct
6058
{
6159
// port
6260
uint8_t rhport;
6361
uint8_t hub_addr;
6462
uint8_t hub_port;
6563
uint8_t speed;
64+
volatile uint8_t enumerating;
6665

67-
struct TU_ATTR_PACKED
68-
{
69-
volatile uint8_t connected : 1;
70-
volatile uint8_t addressed : 1;
71-
volatile uint8_t configured : 1;
72-
volatile uint8_t suspended : 1;
73-
};
74-
66+
// struct TU_ATTR_PACKED {
67+
// uint8_t speed : 4; // packed speed to save footprint
68+
// volatile uint8_t enumerating : 1;
69+
// uint8_t TU_RESERVED : 3;
70+
// };
7571
} usbh_dev0_t;
7672

7773
typedef struct {
@@ -402,10 +398,18 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
402398
switch (event.event_id)
403399
{
404400
case HCD_EVENT_DEVICE_ATTACH:
405-
// TODO due to the shared _usbh_ctrl_buf, we must complete enumerating
401+
// due to the shared _usbh_ctrl_buf, we must complete enumerating
406402
// one device before enumerating another one.
407-
TU_LOG_USBH("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
408-
enum_new_device(&event);
403+
if ( _dev0.enumerating )
404+
{
405+
TU_LOG1("[%u:] USBH Defer Attach until current enumeration complete\r\n", event.rhport);
406+
osal_queue_send(_usbh_q, &event, in_isr);
407+
}else
408+
{
409+
TU_LOG1("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
410+
_dev0.enumerating = 1;
411+
enum_new_device(&event);
412+
}
409413
break;
410414

411415
case HCD_EVENT_DEVICE_REMOVE:
@@ -1623,6 +1627,9 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
16231627

16241628
static void enum_full_complete(void)
16251629
{
1630+
// mark enumeration as complete
1631+
_dev0.enumerating = 0;
1632+
16261633
#if CFG_TUH_HUB
16271634
// get next hub status
16281635
if (_dev0.hub_addr) hub_edpt_status_xfer(_dev0.hub_addr);

0 commit comments

Comments
 (0)