Skip to content

smittytone/RP2040-FreeRTOS

Repository files navigation

RP2040-FreeRTOS Template 1.6.0

This repo contains my base project for FreeRTOS on the Raspberry Pi RP2040 microcontroller. It can be run as a demo and then used as the basis of a new project.

More details in this blog post.

Project Structure

/RP2040-FreeRTOS
|
|___/App-Template           // Application 1 (FreeRTOS template) source code (C)
|   |___CMakeLists.txt      // Application-level CMake config file
|
|___/App-Scheduling         // Application 2 (scheduling demo) source code (C++)
|   |___CMakeLists.txt      // Application-level CMake config file
|
|___/App-IRQs               // Application 3 (IRQs demo) source code (C++)
|   |___CMakeLists.txt      // Application-level CMake config file
|
|___/App-Timers             // Application 4 (timers demo) source code (C++)
|   |___CMakeLists.txt      // Application-level CMake config file
|
|___/Common                 // Source code common to applications 2-4 (C++)
|
|___/Config
|   |___FreeRTOSConfig.h    // FreeRTOS project config file
|
|___/FreeRTOS-Kernel        // FreeRTOS kernel files, included as a submodule
|___/pico-sdk               // Raspberry Pi Pico SDK, included as a submodule
|
|___CMakeLists.txt          // Top-level project CMake config file
|___pico_sdk_import.cmake   // Raspberry Pi Pico SDK CMake import script
|___deploy.sh               // Build-and-deploy shell script
|
|___rp2040.code-workspace   // Visual Studio Code workspace
|___rp2040.xcworkspace      // Xcode workspace
|
|___README.md
|___LICENSE.md

Prerequisites

To use the code in this repo, your system must be set up for RP2040 C/C++ development. See this blog post of mine for setup details.

Usage

  1. Clone the repo: git clone https://github.com/smittytone/RP2040-FreeRTOS.
  2. Enter the repo: cd RP2040-FreeRTOS.
  3. Install the submodules: git submodule update --init. Important Do not use --recursive: you do not want to update FreeRTOS.
  4. Fully install the Pico SDK: cd pico-sdk && git submodule update --init && cd ..
  5. Optionally, edit CMakeLists.txt and /<Application>/CMakeLists.txt to rename the project.
  6. Create a pico tools directory: mkdir tools.
  7. Configure the build process: cmake -S . -B build.
  8. Build the app: cmake --build build.
  9. Connect your device so it’s ready for file transfer.
  10. Install the app: ./deploy.sh.
    • Pass the app you wish to deploy:
      • ./deploy.sh build/App-Template/TEMPLATE.uf2.
      • ./deploy.sh build/App-Scheduling/SCHEDULING_DEMO.uf2.
    • To trigger a build, include the --build or -b flag: ./deploy.sh -b.

Pico SDK

The repo has been updated for the Pico SDK 2.2.0. The SDK assumes you’re using an RP2350-based Pico 2 board, so please set the following environment variable before building these examples:

export PICO_BOARD={YOUR_BOARD_TYPE}

For the original Pico, for example:

export PICO_BOARD=pico

Additionally, issue these commands:

export PICOTOOL_FETCH_FROM_GIT_PATH=/path/to/RP2040-FreeRTOS/tools
mdkir /path/to/RP2040-FreeRTOS/tools

Note If you have updated from a previous version of the this repo, I recommend deleting your build folder and re-running the build process from Step 6, above.

Debug vs Release

You can switch between build types when you make the cmake call in step 6, above. A debug build is made explicit with:

cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug

For a release build, which among various optimizations omits UART debugging code, call:

cmake -S . -B build -D CMAKE_BUILD_TYPE=Release

Follow both of these commands with the usual

cmake --build build

The Apps

This repo includes a number of deployable apps. The project builds them all, sequentially. Exclude apps from the build process by commenting out their add_subdirectory() lines in the top-level CMakeLists.txt.

App One: Template

This C app provides a simple flip-flop using an on-board LED and an LED wired between GPIO 20 and GND. The board LED flashes every 500ms under one task. When its state changes, a message containing its state is added to a FreeRTOS inter-task xQueue. A second task checks for an enqueued message: if one is present, it reads the message and sets the LED it controls — the GPIO LED — accordingly to the inverse of the board LED’s state.

Circuit layout

The code demonstrates a basic FreeRTOS setup, but you can replace it entirely with your own code if you’re using this repo’s contents as a template for your own projects.

App Two: Scheduling

This C++ app builds on the first by adding an MCP9808 temperature sensor and an HT16K33-based LED display. It is used in this blog post.

Circuit layout

App Three: IRQs

This C++ app builds on the second by using the MCP9808 temperature sensor to trigger an interrupt. It is used in this blog post.

Circuit layout

App Four: Timers

This C++ app provides an introduction to FreeRTOS’ software timers. No extra hardware is required. It is used in this blog post.

IDEs

Workspace files are included for the Visual Studio Code and Xcode IDEs.

Release Notes

Please see CHANGELOG.md.

Credits

The version of the FreeRTOSConfig.h file included here was derived from work by @yunka2.

Copyright and Licences

Application source © 2025, Tony Smith and licensed under the terms of the MIT Licence.

FreeRTOS © 2021, Amazon Web Services, Inc. It is also licensed under the terms of the MIT Licence.

The Raspberry Pi Pico SDK is © 2025, Raspberry Pi (Trading) Ltd. It is licensed under the terms of the BSD 3-Clause "New" or "Revised" Licence.