Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.5k
esp32: Re-initialise USB after soft reset.#18375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
Necessary if USBDevice has been active with USB-CDC, so the USB-CDC stateresets successfully from the host.There is still a bug here, because calling tud_disconnect() doesn't causeany UNPLUG or BUS_RESET events to arrive from TinyUSB - which means the USBdevice state stays out of sync until we call mp_usbd_init() again...This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
| #ifMICROPY_HW_ENABLE_USB_RUNTIME_DEVICE | ||
| // matches mp_usbd_deinit() above, ensure we have USB-CDC after soft reset | ||
| mp_usbd_init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Do you think it makes sense to move this to the top of the soft reset loop, aftermp_init()? And then remove the call tomp_usbd_init() fromusb.c:usb_init()?
That would then match most of the other ports (eg rp2) in the way they callmp_usbd_init andmp_usbd_deinit.
Uh oh!
There was an error while loading.Please reload this page.
Summary
Necessary if runtime
USBDevicehas been active on ESP32-S3 along with the default USB-CDC REPL. Without this fix, two things happen after a soft reset:Testing
Note this PR needs to be cherry-picked onto#18332 if PSRAM is enabled.
mpremote a0 run pr18332.py- where the file has the sample code fromesp32/boards: Configure S2/S3 PSRAM boards to use USB in IRQ mode. #18332mpremote runthen mpremote will error out as it disconnects to change USB device config.mpremote a0Without fix: USB-CDC disappears along with the keyboard device, never comes back. Connecting to the UART REPL and interacting with it will eventually slow UART TX down to a trickle (quickest way to trigger is
print("a"*500).)With fix: USB-CDC disappears and re-enumerates again as plain USB-CDC device.
Related bugs
There is still a related bug here, because calling TinyUSB
tud_disconnect()on ESP32-S3 doesn't trigger anyDCD_EVENT_UNPLUGGEDorDCD_EVENT_BUS_RESETevent. This means that the USB device driver state goes out of sync (i.e. TinyUSB thinks it's still connected).This PR avoids this in soft reset because the host will reconfigure the USB device and the state will correct itself, but there's still a problem if Python code does something like this:
mpremote a0 run pr18332.pympremote a0import machine; u = machine.USBDevice(); u.active(0)In this situation the USB device disappears from the host as expected, but the issue with very slow stdout will happen as the CDC device driver still thinks it's connected and configured.
I've opened a Discussion on the TinyUSB repo to try and find out the expected behaviour:hathach/tinyusb#3331
This work was funded through GitHub Sponsors.