FreeRTOS Symmetric Multiprocessing (SMP) is a version of the RTOS that can schedule tasks across multiple controller cores.
|
Download and install FreeRTOS
Check Raspberry Pico - Play with multi-core FreeRTOS SMP ("the double blinky") . You can also get the original code from there. This firmware is based on it.
The Double Blinky With Timer example
In the first posts, I created two tasks, and asked FreeRTOS to schedule them. In this post, I replace one of the "to be scheduled" tasks by a timer controlled one (a timer callback), I then create a FreeRTOS timer, and let the timer call that blinky callback.
For tasks that have to run an a regular base, this is a good option. Timers run tasks at a given interval, while the scheduler will determine who's to run next based on priorities.
This is the timer callback. It toggles LED1.
static void led_blinky_cb(TimerHandle_t xTimer) { (void) xTimer; gpio_xor_mask(1u << mainTASK_LED1); }
Here's the part of our startup call that initialises our setup. The commented out code is the part of the previous post that's replaced by the timer one.
// xTaskCreate(prvLedTask, "LED", configMINIMAL_STACK_SIZE, (void *)mainTASK_LED1, mainLED_TASK_PRIORITY, &(xHandle) ); // // Define the core affinity mask such that this task can only run on core 0 // vTaskCoreAffinitySet(xHandle, (1 << 0)); xTaskCreate(prvLedTask, "LED2", configMINIMAL_STACK_SIZE, (void *)mainTASK_LED2, mainLED_TASK_PRIORITY, &(xHandle) ); // Define the core affinity mask such that this task can only run on core 1 // vTaskCoreAffinitySet(xHandle, (1 << 1)); blinky_tm = xTimerCreate("LED1", mainLED_FREQUENCY_MS, true, NULL, led_blinky_cb); xTimerStart(blinky_tm, 0); vTaskStartScheduler();
Differences compared to the previous blog code:
- LED2 task is scheduled, but I let the scheduler decide on what core it executes. (commented out the core affinity command)
- LED1 task is not scheduled (commented out). It's replaced by a timer and a callback that blinks LED1.
Enjoy the FreeRTOS SMP double blinky with timer. The download below includes the .uf2 file, that can be copied directly onto the Pico.