Closed flo2k closed 3 years ago
Unexpected outcome. AFK. Will replicate and respond from Monday.
If I can help you diagnosing and testing, don't hesitate to contact me.
A FreeRTOS tasks MUST never ending.
Tipically you have a for (; ;) { ... your task ... } ... for more info: https://www.freertos.org/implementing-a-FreeRTOS-task.html where you can also read "Task functions should never return so are typically implemented as a continuous loop."
If you need, you can suspend the task using FreeRTOS vTaskSuspend() function.
Guglielmo
@gpb01 Thank you for that hint. I just tested with:
void worker_task(void* pvParameters) {
Serial.println("worker_task started...");
vTaskDelay(pdMS_TO_TICKS(1000));
vTaskDelete(nullptr);
}
and now, no restart is performed anymore.
Thx a lot, I wasn't aware of that rule.
@flo2k : you're welcome !
Guglielmo
@feilipu do we need any further investigations? For me, I have a working solution now. If everything is clear, we could close the issue.
Please close if you're ok. The resolution is correct, afaik.
Here, I have a minimal example of FreeRTOS on an Arduino Mega 2560 with one task and the idle hook activated.
When the
worker_task
runs, it prints "worker_task started...", and then it finishes after 1000ms (after the delay). Unexpectedly, after theworker_task
has finished, the Arduino Mega 2560 restarts. I also use FreeRTOS on an ST NUCLEO L433RC-P (Cortex M4) in combination with the ST HAL driver, and there, the same example does not force a restart.If I don't start the task in the
setup()
function, then the idle task still works and no restart is performed.My expected behaviour is, that after the
worker_task
has finished, the idle task should run forever. I don't want that the Arduino Mega 2560 restarts automatically.Is there any possibility to change this behaviour or to investigate what causes the restart?
Best, flo2k