# 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: 1. **LED Blink Task**: Uses a custom C++ class `Pico2LED` to toggle the built-in LED every 200ms. 2. **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: 1. **Initialization (Core 0)**: - Initialize standard I/O. - Launch Core 1 using `multicore_launch_core1()`. 2. **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`). 3. **RTOS Execution (Core 0)**: - Create FreeRTOS tasks for LED control and USB logging. - Start the scheduler via `vTaskStartScheduler()`. 4. **Inter-core Communication**: - Core 0 reads the `core1_counter` variable (marked as `volatile` to prevent compiler optimization) to display the hardware timer\'s progress. ## Installation and Setup ### 1. Prerequisites Ensure you have the Raspberry Pi Pico SDK installed and configured. ### 2. FreeRTOS Sources Setup ```bash 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 1. `mkdir build && cd build` 2. `cmake ..` 3. `make` 4. Flash the `.uf2` file 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.