diff options
| author | hathach <[email protected]> | 2026-08-12 23:05:59 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-08-13 11:45:36 +0700 |
| commit | 91fbbd192ca9539221d3dc096f00ce77836a5d3d (patch) | |
| tree | 801ad543cc2608eb5804c3d3d0fd547246d08d83 /src/device | |
| parent | a52562b2be7ea728a176ae94d8a18d9ae0a4423a (diff) | |
usbd: clear endpoint busy/claimed when a completion event is dropped
An XFER_COMPLETE dropped by a full event queue leaves its endpoint's
BUSY|CLAIMED state set forever - the consumer that normally clears it
never sees the event, so usbd_edpt_claim()/usbd_edpt_xfer() fail from
then on and the class never re-arms the endpoint. Clear both flags when
the enqueue fails: the completion is lost either way, but the endpoint
stays usable.
Unit test: arm a bulk endpoint, drop its completion against a full
queue, verify the endpoint can be claimed and re-armed.
Diffstat (limited to 'src/device')
| -rw-r--r-- | src/device/usbd.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c index 79802e70f..f5c3046d6 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -1475,10 +1475,18 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const* event, bool in_isr) break; } - if (send && !queue_event(event, in_isr) && event->event_id == DCD_EVENT_SETUP_RECEIVED) { - // dropped by a full queue: undo the increment, else every later SETUP is skipped as - // "other SETUP in queue" and EP0 is deaf until re-init - _usbd_queued_setup--; + if (send && !queue_event(event, in_isr)) { + // event dropped by a full queue: undo state that would otherwise wedge permanently + if (event->event_id == DCD_EVENT_SETUP_RECEIVED) { + // undo the increment, else every later SETUP is skipped as "other SETUP in queue" + // and EP0 is deaf until re-init + _usbd_queued_setup--; + } else if (event->event_id == DCD_EVENT_XFER_COMPLETE) { + // clear busy + claimed, else the endpoint can never be claimed or re-armed again + uint8_t const epnum = tu_edpt_number(event->xfer_complete.ep_addr); + uint8_t const ep_dir = tu_edpt_dir(event->xfer_complete.ep_addr); + _usbd_dev.ep_status[epnum][ep_dir] &= (uint8_t) ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED); + } } } |
