The Stream (and Message) Buffer is one of the more recent additions to FreeRTOS. A construct that's useful in specific (yet commons) situations:
- moving data from an interrupt (e.g.: UART TX interrupt) to an RTOS task for processing
- in a multi-core setting (like my test here on Pico's dual cores) to send data from a task running on one core to a task on the other core.
quotes from FreeRTOS: "Unlike most other FreeRTOS communications primitives, stream buffers are optimised for single reader single writer scenarios, such as passing data from an interrupt service routine to a task, or from one microcontroller core to another on a dual core CPU." "basic and light weight core to core communication" |
The goal of this post is to get a demo working on Raspberry Pico. On the 2 ARM cores. In a later post I 'll visit the details.
the two ARM Cortex cores in action
The Raspberry Pico RP2040 controller has 2 ARM cores. Most projects on the internet use one core, and let the other sleep. FreeRTOS SMP allows you to run code on both cores in a scalable and simple way. |
This mechanism is lighter and has less concurrency guards compared to the other FreeRTOS mechanisms. That's on purpose. If you use it for what it is intended for, these guards are unnecessary overhead.
There's a good document that explains principles and use. And an example that has a lot of comments that explain the intrinsics. The example isn't part of the Pico port, but all sources are available. It took me some time to get it to build. I've attached my project at the end of this post.
Get a recent FreeRTOS on your development machine. Minimum version V10.0.0. You can get it by executing
git clone https://github.com/FreeRTOS/FreeRTOS.git --recursive
Then create an environment variable FREERTOS_KERNEL_PATH that point to the FreeRTOS/FreeRTOS/Source subdirectory. You can do that in your OS settings, or in your IDE.
In VSCode, I set it in the Extensions - > CMake -> CMake Tools -> Environment
In VSCode, to use the project, expand the attached zip file, and add the extracted dir to your workspace. For other IDEs, and from the command line, this will most likely work too, if you have CMake.
As long as you are able to build one of the Raspberry Pico examples, you will be able to build this one too, if you set that variable.
All necessary changes to the CMake and source files are part of my project. You don't need to change FreeRTOS code. You can build and compile (or use the .ul2 binary that's included in my zip, although that doesn't do anything you can see from the outside. You need a debugger to understand what's happening).
Project: bufferedqueue_20240921.zip