diff options
Diffstat (limited to 'shared/tinyusb')
-rw-r--r-- | shared/tinyusb/mp_usbd_runtime.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/shared/tinyusb/mp_usbd_runtime.c b/shared/tinyusb/mp_usbd_runtime.c index fe28a4a727..4955382577 100644 --- a/shared/tinyusb/mp_usbd_runtime.c +++ b/shared/tinyusb/mp_usbd_runtime.c @@ -501,6 +501,15 @@ void mp_usbd_task_callback(mp_sched_node_t *node) { // Task function can be called manually to force processing of USB events // (mostly from USB-CDC serial port when blocking.) void mp_usbd_task(void) { + #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL + if (!mp_thread_is_main_thread()) { + // Avoid race with the scheduler callback by scheduling TinyUSB to run + // on the main thread. + mp_usbd_schedule_task(); + return; + } + #endif + if (in_usbd_task) { // If this exception triggers, it means a USB callback tried to do // something that itself became blocked on TinyUSB (most likely: read or |