I use FreeRTOS but under the Espressif ESP32 multicore architecture.
I took a quick look at some online examples for Arduino and it appears that there is a lot of wiggle-room in how authors set things up. From what I can tell without getting too deep into a rabbit hole is that once the scheduler is started, you can add tasks but single line code that is in the setup{} no longer runs. Some implementations (flavors) pin the loop(){} block to the idle queue, so code in loop() may execute, but unscheduled and at the lowest priority.
So IMO, "yes" what you are witnessing is normal behavior. (For the way the Maple RTOS library is configured.) But I would not rely upon the behavior crossing into another flavor or FreeRTOS, say on the ESP32.
My honest opinion is that using FreeRTOS on a single core uC is simply resource wasteful. Everything can generally be done without the overhead; however, FreeRTOS does have a legitimate use when forcing tic allocation between competing code segments, maybe updating two displays that have different backend functions.
From an example in the Roger's core under the FreeRTOS library. It appears that putting Arduino commands at the end of setup() does not work because the scheduler has already been activated. In loop() the word "background" is meant to be the sum of all free time allocated by the scheduler (technically, unallocated time.)
Code: Select all
#include <MapleFreeRTOS900.h>
static void vLEDFlashTask(void *pvParameters) {
for (;;) {
vTaskDelay(1000);
digitalWrite(BOARD_LED_PIN, HIGH);
vTaskDelay(50);
digitalWrite(BOARD_LED_PIN, LOW);
}
}
void setup() {
// initialize the digital pin as an output:
pinMode(BOARD_LED_PIN, OUTPUT);
xTaskCreate(vLEDFlashTask,
"Task1",
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY + 2,
NULL);
vTaskStartScheduler();
}
void loop() {
// Insert background code here
}
As Steve stated, victorpv was the more knowledgeable FreeRTOS individual when considering Roger's (libmaple) core and I have not seen him around the forum in a while ( Last active:Thu Jan 23, 2020 10:42 am)
For readers that may wonder what an appropriate use-case may be for FreeRTOS on the Arduino microcontroller platform, I have found this article to be enlightening:
https://microcontrollerslab.com/arduino ... resources/
Here is the key quote of why the RTOS is useful:
Receiver Task
“TaskLcd” is a receiver task that reads structure data from struct_queue. The receiving task has the highest priority. Therefore, at the start of program execution, it will run first, but it will enter the blocking state. Because the queue will be empty. Hence, it will execute as soon as when one of the senders will write data to the queue.
Using an ESP32 and the already linked FreeRTOS, I think just publishing the results to a web-server page would be more fun than to a serial console.
Allow me to briefly elaborate on the above statement for context. ESP32 using Arduino already binds the FreeRTOS services into the Arduino code. Therefore, using these services does not significantly affect the size of the user binary / flash usage. And, if one is not using the RF section and dedicated processing core, you can easily direct Arduino functions to process on both cores. Even using WiFi, there is generally unused capacity on core_0 (RF section) with core_1 dedicated to Arduino.
Ray