Skip to content

Commit 365c416

Browse files
authored
Merge pull request hathach#2107 from hathach/fix-usbh-enum-issue
fix usbh issue when device genreate multiple attach/detach/attach when plugging in
2 parents bbc76e7 + 9593ab7 commit 365c416

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/host/usbh.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,14 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
411411
if ( _dev0.enumerating )
412412
{
413413
TU_LOG_USBH("[%u:] USBH Defer Attach until current enumeration complete\r\n", event.rhport);
414+
415+
bool is_empty = osal_queue_empty(_usbh_q);
414416
osal_queue_send(_usbh_q, &event, in_isr);
417+
418+
if (is_empty) {
419+
// Exit if this is the only event in the queue, otherwise we may loop forever
420+
return;
421+
}
415422
}else
416423
{
417424
TU_LOG_USBH("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
@@ -1461,7 +1468,10 @@ static bool enum_new_device(hcd_event_t* event)
14611468
hcd_port_reset_end( _dev0.rhport);
14621469

14631470
// device unplugged while delaying
1464-
if ( !hcd_port_connect_status(_dev0.rhport) ) return true;
1471+
if ( !hcd_port_connect_status(_dev0.rhport) ) {
1472+
enum_full_complete();
1473+
return true;
1474+
}
14651475

14661476
_dev0.speed = hcd_port_speed_get(_dev0.rhport );
14671477
TU_LOG_USBH("%s Speed\r\n", tu_str_speed[_dev0.speed]);

0 commit comments

Comments
 (0)