Handle external interrupt with FreeRTOS

I have not used the Raspberry Pi Pico, but since it’s an ARM Cortex-M0+ based microcontroller, which I have written code for, I know it has an NVIC (or at least should), so there are priorities on the interrupts, and it’s important to have the interrupt at a priority that does not interrupt the scheduler (so a higher priority than the PENDSV or the timer is probably a bad idea).

I routinely handle external interrupts in FreeRTOS, however I do register the interrupt controller and then the ISR with the OS using the xPortInstallInterruptHandler() interface and enable the interrupt via the vPortEnableInterrupt() interface. Most of the time, I don’t actually do the I/O in the ISR, instead I disable the interrupt in the ISR using vPortDisableInterrupt() and then call xEventGroupSetBitsFromISR() or xTaskNotifyFromISR() then calls portYIELD_FROM_ISR() and returns; I have an IO task that blocks on the event group or task notification that is higher priority than anything else more important; it is waken by the RTOS when the notification or event group is set, services the device, then reenables interrupts on that device and loops back to where it blocks while waiting for the next event/notification.

Works like a charm for me. I’ve used this same technique on several Cortex-M platforms, MicroBlaze and MIPS.