Skip to content

Commit 1e683f3

Browse files
Dynamically pick task IRQ for Pico SDK 1.4.0
The hardcoded periodic USB task IRQ conflicts with the IRQ used by the new Pico SDK 1.4.0 WiFi support. A new API call was added in 1.4.0 to allow the system to select a free IRQ, so use it. Default to the hardcoded one on earlier SDK versions (since those don't have the new API call). Fixes a crash found in earlephilhower/arduino-pico#670
1 parent 122544c commit 1e683f3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/arduino/ports/rp2040/Adafruit_TinyUSB_rp2040.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ extern "C" {
4242

4343
// USB processing will be a periodic timer task
4444
#define USB_TASK_INTERVAL 1000
45-
#define USB_TASK_IRQ 31
45+
46+
// SDK >= 1.4.0 need to dynamically request the IRQ to avoid conflicts
47+
#if (PICO_SDK_VERSION_MAJOR * 100 + PICO_SDK_VERSION_MINOR) < 104
48+
#define USB_TASK_IRQ 31
49+
#else
50+
static unsigned int USB_TASK_IRQ;
51+
#endif
4652

4753
//--------------------------------------------------------------------+
4854
// Forward USB interrupt events to TinyUSB IRQ Handler
@@ -118,6 +124,9 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
118124
tusb_init();
119125

120126
// soft irq for periodically task runner
127+
#if (PICO_SDK_VERSION_MAJOR * 100 + PICO_SDK_VERSION_MINOR) >= 104
128+
USB_TASK_IRQ = user_irq_claim_unused(true);
129+
#endif
121130
irq_set_exclusive_handler(USB_TASK_IRQ, usb_irq);
122131
irq_set_enabled(USB_TASK_IRQ, true);
123132
setup_periodic_usb_hanlder(USB_TASK_INTERVAL);

0 commit comments

Comments
 (0)