Skip to content

Commit 9a43989

Browse files
projectgusdpgeorge
authored andcommitted
shared/tinyusb: Stall the CDC IN endpoint while disconnecting.
Only when dynamic USB devices are enabled. The issue here is that when the USB reset triggers, the dynamic USB device reset callback is called from inside the TinyUSB task. If that callback tries to print something then it'll call through to tud_cdc_write_flush(), but TinyUSB hasn't finished updating state yet to know it's no longer configured. Subsequently it may try to queue a transfer and then the low-level DCD layer panics. By explicitly stalling the endpoint first, usbd_edpt_claim() will fail and tud_cdc_write_flush() returns immediately. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 8762fe8 commit 9a43989

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

shared/tinyusb/mp_usbd_runtime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ static void mp_usbd_disconnect(mp_obj_usb_device_t *usbd) {
472472
#if MICROPY_HW_USB_CDC
473473
// Ensure no pending static CDC writes, as these can cause TinyUSB to crash
474474
tud_cdc_write_clear();
475+
// Prevent cdc write flush from initiating any new transfers while disconnecting
476+
usbd_edpt_stall(USBD_RHPORT, USBD_CDC_EP_IN);
475477
#endif
476478

477479
bool was_connected = tud_connected();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy