Libraries for the Pico: FreeRTOS Kernel

Libraries for the Pico: FreeRTOS Kernel

FreeRTOS Kernelis the most common library I use in my projects on the Raspberry PI Pico and Pico-W. What brought me to the FreeRTOS and why do I use it so often?

This blog post from DrJonEA.co.uk is part of an occasional series of blogs on C/C++ libraries for the Raspberry Pi Pico and Pico-W.

FreeRTOS Kernel is a Real-Time Operating System for embedded systems and one that has an official port for the RP2040 processor at the heart of the Pico and Pico-W. It enables preemptive multitasking threads to run on a single core of the RP2040 or across both of the processor cores under the control of a scheduler. It then provides mechanisms for these tasks to interact through semaphores and messaging.

Not every project needs a RTOS and even some that do can make do with other techniques. I wrote a set of LED animation patterns for an animated LED ring using a collaborative multitasking or polling strategy, see video clip. Basically to keep calling a “poll” function on each of my tasks and for each task to work out what it needs to do next, take a small step forward and release control back to the main poll loop. This works well and I could control the animation using a rotary encoder switch, also running through the poll loop.

Where RTOS really come into their own, in my experience, is when you start to look at protocol communication with the outside world. Maintaining the hardware (often serial) communication channel, then parsing the messages, and operating on data all need to happen concurrently. It is so much easier to write these as separate tasks. I’m obviously not the only one who thinks this as most of the major libraries implementing network protocols make use of a RTOS.

In projects like my IoT Saber Wall Light I have made extensive use of FreeRTOS. It runs the network communication that sets the colour of the light blade and notifies other devices when it is turned on and off. A simple use case but one that would be difficult to do without using FreeRTOS.

So if you are getting into Web Services, MQTT, IoT or just using SNTP to synchronise your time, I think it is well worth the time to learn FreeRTOS. I can help you with that learning too, as I have a Udemy course available for FreeRTOS for the Raspberry PI Pico.

Leave a comment