572723a9d462eb4ace481839dcd21756d2f3c250
RTOS Sample Project for Raspberry Pi Pico 2 (Multicore)
This project demonstrates a hybrid implementation of FreeRTOS and Bare-metal execution on the Raspberry Pi Pico 2 (RP2350), utilizing both processor cores.
Project Description
The project showcases how to run a Real-Time Operating System (FreeRTOS) on one core while maintaining a high-precision hardware-timer-driven process on the second core.
Core 0: FreeRTOS
Core 0 runs the FreeRTOS scheduler and manages multiple concurrent tasks:
- LED Blink Task: Uses a custom C++ class
Pico2LEDto toggle the built-in LED every 200ms. - USB Print Task: Prints the system status to the USB serial console every 1 second, including counters from both cores.
Core 1: Bare-metal (Hardware Timers)
Core 1 operates in a bare-metal mode to ensure maximum predictability and precision:
- It creates a dedicated Hardware Alarm Pool.
- It runs a Repeating Timer that increments a global counter every 1000ms via a hardware interrupt.
- The core remains in a low-power state (
__wfi) until the next interrupt occurs.
Algorithm Description
The project implements a multi-core synchronization and execution flow:
- Initialization (Core 0):
- Initialize standard I/O.
- Launch Core 1 using
multicore_launch_core1().
- Bare-metal Execution (Core 1):
- Initialize a hardware alarm pool specifically for Core 1.
- Schedule a repeating timer interrupt.
- Enter a loop of "Wait For Interrupt" (
__wfi).
- RTOS Execution (Core 0):
- Create FreeRTOS tasks for LED control and USB logging.
- Start the scheduler via
vTaskStartScheduler().
- Inter-core Communication:
- Core 0 reads the
core1_countervariable (marked asvolatileto prevent compiler optimization) to display the hardware timer's progress.
- Core 0 reads the
Installation and Setup
1. Prerequisites
Ensure you have the Raspberry Pi Pico SDK installed and configured.
2. FreeRTOS Sources Setup
mkdir freertos_sources
cd freertos_sources
git clone https://github.com/raspberrypi/FreeRTOS-Kernel
git clone https://github.com/jondurrant/RPIPico2-Exp
cp -r RPIPico2-Exp/examples/FreeRTOSBlink/port ../port/FreeRTOS-Kernel
cp RPIPico2-Exp/examples/FreeRTOSBlink/FreeRTOS_Kernel_import.cmake ../FreeRTOS_Kernel_import.cmake
3. Build Process
mkdir build && cd buildcmake ..make- Flash the
.uf2file to the Pico 2.
Project Structure
rtos_sample.cpp: Main application code (Multi-core logic).CMakeLists.txt: Build configuration.port/: FreeRTOS configuration and port files.freertos_sources/: FreeRTOS kernel and support libraries.
Languages
C
61.8%
CMake
25.1%
C++
13.1%