diff --git a/main.c b/main.c index d9cdcca1da59e..f85109e2fdf2b 100755 --- a/main.c +++ b/main.c @@ -184,6 +184,7 @@ STATIC void stop_mp(void) { #endif background_callback_reset(); + usb_background_schedule(); gc_deinit(); } diff --git a/supervisor/shared/background_callback.c b/supervisor/shared/background_callback.c index 288c9a4df297a..68a0a9667dadb 100644 --- a/supervisor/shared/background_callback.c +++ b/supervisor/shared/background_callback.c @@ -33,7 +33,7 @@ #include "supervisor/shared/tick.h" #include "shared-bindings/microcontroller/__init__.h" -STATIC volatile background_callback_t *callback_head, *callback_tail; +STATIC volatile background_callback_t * volatile callback_head, * volatile callback_tail; #define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts()) #define CALLBACK_CRITICAL_END (common_hal_mcu_enable_interrupts()) @@ -50,7 +50,6 @@ void background_callback_add_core(background_callback_t *cb) { cb->prev = (background_callback_t*)callback_tail; if (callback_tail) { callback_tail->next = cb; - cb->prev = (background_callback_t*)callback_tail; } if (!callback_head) { callback_head = cb; diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 07c6aee6c1a31..9cbb295c8a841 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -98,9 +98,14 @@ static void usb_background_do(void* unused) { usb_background(); } +void usb_background_schedule(void) +{ + background_callback_add(&usb_callback, usb_background_do, NULL); +} + void usb_irq_handler(void) { tud_int_handler(0); - background_callback_add(&usb_callback, usb_background_do, NULL); + usb_background_schedule(); } //--------------------------------------------------------------------+ diff --git a/supervisor/usb.h b/supervisor/usb.h index ccb35470cd0d5..1c709926a7118 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -35,6 +35,9 @@ // it may be necessary to call it directly. void usb_background(void); +// Schedule usb background +void usb_background_schedule(void); + // Ports must call this from their particular USB IRQ handler void usb_irq_handler(void);