Summary:
In this blog post I wanted to document the steps to create a minimal firmware project to demonstrate running FreeRTOS kernel on the Raspberry Pico 2. I would use the offical FreeRTOS kernel repo on Github and add it as a dependency to be compiled insde a simple Pico Cmake project. The Raspberry Pi Pico 2 which hosts the RP2350 chip is listed as one of the community supported ports by the FreeRTOS project.
Installing Pico SDK and toolchain with VSCode:
To prepare the developement environment for writing a FreeRTOS project with VSCode IDE, the Raspberry Pi Pico extension need to be installed. It provides the latest SDK along with compiler and debugger toolchain. It also simplifies the process of creating cmkae project template and example projects from the Pico SDK.
![]() |
| RaspberryPi Pico VSCode Extension |
Create C++ project and add FreeRTOS kernel :
The starting point is to create an empty C++ project using the Pico VScode extension. This will generate a template project structure with basic Cmake confgiuration files in addition to .c source file to host the code for the program to be run on the Pico.
![]() |
| Empty project configuration for Pico 2 board |
![]() |
| Initial file strcutre for Pico 2 project |
To verify that the toolchain and sdk installation work we can run the "Compile Project" task from VScode Terminal > Run Task menu. If the command is susccesfull we should see a binary .elf image generated in the build folder. This image could then be flashed to a connected Pico board via the "Run Project" task.
Moving on .. To run FreeRTOS on the Pico 2 we need to add it as library to our existing project and include some Pico 2 specific configuration such that the kernel could run without compatibility issues. After that we can include FreeRTOS header files in our source code and write some example code to demonstarte the usage of RTOS tasks on the Pico.
First we need to add the FreeRTOS kernel repoistory to our existing folder as a git submodule. I have added it inside a new folder named "lib". We also need to fetch the submodules of FreeRTOS kernel repo which include the "ThirdParty" portable configrutions for the Pico board. These steps could be achieved with the following commands:
- mkdir lib # create folder for adding the FreeRTOS kernel repo inside it.
- git init # initialize a git repo for the current project
- cd lib
- git submodule add https://github.com/FreeRTOS/FreeRTOS-Kernel # add the FreeRTOS kernel
- cd FreeRTOS-Kernel
- git submodule update --init # get submodules also within FreeRTOS
- git checkout --recurse-submodules V11.3.0 # checkout out a stable release version of the kernel.
After adding the FreeRTOS kernel files to our project we need to add a Cmake file to signal the location of the kernel files for the target platform (i.e. Pico RP2350). we can copy this file over from the community supported port folder for the RP2350 as shown below:
In addition to the above .cmake file we need to include "FreeRTOSConfig.h" file to define the kernel configuration for the RP2350 hardware platform. I simply copied over a template config file from the raspberry pi pico-examples folder which also include the RP2350 specific options for the port to work. You can customize the config file later on according to your application need (e.g. enable static memory allocation instead of dynamic heap).
After the above additions. The project file structure will look as follows:
Now we need to update the project CMakeLists.txt file to include reference to the FreeRTOS kernel to be compiled and linked with the Pico program executable. I have additionally enabled USB output so printf statement from the Pico program can be observed from serial terminal during runtime.
After done with addition, configuration of FreeRTOS kernel and adaption of CMakeList.txt file, I create a simple FreeRTOS program which inludes one task to blink the onboard LED of the Pico 2 every 500 ms. print statements are added to the task to signal the toggiling process to serial terminal over USB.
Thus, the "freertos-pico.c" looks as follows:
Compile and flash the program:
To compile the project we simply run the "Compile Project" task from VSCode Pico extension. If all runs smoothly with no errors we should see that couple of executable and binary files are generated inside the build folder.
To trnasfter the executable over to the Pico 2 board, we need to hold the "BOOTSEL" button before connecting the board to the host system via USB. Then we can either copy the ".uf2" binary generated above to the storage desk named "RP2350" or run the "Run Program" task from VSCode Pico extension. Both ways, the board will restart after the transfer process and we should see the green onboard blinking every 500 ms.
To inspect our program during runtime we can open a serial terminal to our Pico device and observe the trace messages printed from our FreeRTOS blink task.
Congratulations !. We just built a very simple Pico firmware based on the FreeRTOS kernel.









0 comments:
Post a Comment