Skip to content

Commit 7bfe186

Browse files
authored
Merge pull request #2 from hathach/tinyusb-update
fix rp2040 with new shared irq usb handler
2 parents daa927a + b432cf6 commit 7bfe186

File tree

2 files changed

+9
-12
lines changed
  • ports/raspberrypi/supervisor
  • supervisor/shared/usb

2 files changed

+9
-12
lines changed

ports/raspberrypi/supervisor/usb.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,8 @@ STATIC void _usb_irq_wrapper(void) {
3939
}
4040

4141
void post_usb_init(void) {
42-
irq_set_enabled(USBCTRL_IRQ, false);
43-
44-
irq_handler_t usb_handler = irq_get_exclusive_handler(USBCTRL_IRQ);
45-
if (usb_handler) {
46-
irq_remove_handler(USBCTRL_IRQ, usb_handler);
47-
}
48-
irq_set_exclusive_handler(USBCTRL_IRQ, _usb_irq_wrapper);
49-
50-
irq_set_enabled(USBCTRL_IRQ, true);
42+
irq_add_shared_handler(USBCTRL_IRQ, _usb_irq_wrapper,
43+
PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY);
5144

5245
// There is a small window where the USB interrupt may be handled by the
5346
// pico-sdk instead of CircuitPython. If that is the case, then we'll have

supervisor/shared/usb/usb.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,17 @@ void usb_background_schedule(void) {
225225
}
226226

227227
void usb_irq_handler(int instance) {
228+
#if CFG_TUSB_MCU != OPT_MCU_RP2040
229+
// For rp2040, IRQ handler is already installed and invoked automatically
228230
if (instance == CIRCUITPY_USB_DEVICE_INSTANCE) {
229231
tud_int_handler(instance);
230-
} else if (instance == CIRCUITPY_USB_HOST_INSTANCE) {
231-
#if CIRCUITPY_USB_HOST
232+
}
233+
#if CIRCUITPY_USB_HOST
234+
else if (instance == CIRCUITPY_USB_HOST_INSTANCE) {
232235
tuh_int_handler(instance);
233-
#endif
234236
}
237+
#endif
238+
#endif
235239

236240
usb_background_schedule();
237241
}

0 commit comments

Comments
 (0)