Skip to content

Commit

Permalink
Merge pull request #4122 from hathach/fix-3986
Browse files Browse the repository at this point in the history
Fix 3986 background reset remove existing usb callback
  • Loading branch information
dhalbert authored Feb 5, 2021
2 parents 0a55cfb + 25d456a commit 5bb722b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ STATIC void stop_mp(void) {
#endif

background_callback_reset();
usb_background();

gc_deinit();
}
Expand Down
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0

SUPEROPT_GC = 0
SUPEROPT_VM = 0
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/seeeduino_xiao/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0

SUPEROPT_GC = 0
SUPEROPT_VM = 0
3 changes: 1 addition & 2 deletions supervisor/shared/background_callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion supervisor/shared/usb/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,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();
}

//--------------------------------------------------------------------+
Expand Down
3 changes: 3 additions & 0 deletions supervisor/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 5bb722b

Please sign in to comment.