arduino MEGA2560. system Task loop 1 time and stop after the first return task. Thank you for your help

Hello, New with RTOS and beginner programming. It’s not right with me but I’m progressing. I have a question, to know why my code is doing a good loop but the second Task stops. I am on arduino MEGA2560. Thanks for your help. ~~~

include <Arduino_FreeRTOS.h>

include <FreeRTOSConfig.h>

include <FreeRTOSVariant.h>

include <task.h>

TaskHandlet TaskHandle1; TaskHandlet TaskHandle2; TaskHandlet TaskHandle3; TaskHandlet TaskHandle4; void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println(F(“*****Setup function*****”)); Serial.println(F(“************************”)); delay(2000); xTaskCreate(TaskReadCalcPID, “Task1”, configMINIMALSTACKSIZE, NULL, 4, &TaskHandle1); // paramètre de la TASK ici. //xTaskCreate(TaskNxtParamP0ConsMes, “Task2”, configMINIMALSTACKSIZE, NULL, 4, &TaskHandle2); //xTaskCreate(TaskReadCalcPID, “Task3”, configMINIMALSTACKSIZE, NULL, 3, &TaskHandle3); //xTaskCreate(TaskNxtParamP0PID, “Task4”, configMINIMALSTACKSIZE, NULL, 1, &TaskHandle4); } void loop() { Serial.println(F(“Loop function”)); delay(4000); } /////////////////////////////// TASKS//////////////////////////////////////////////////// //************************************************1******************************************************************************* void TaskReadCalcPID(void *pvParameters) // Ici c’est la tache avec le rappel de ses paramètres: TaskReadCalcPID , Priorité=6/7 { while(1) { Serial.println(“*****START****TASK 1***********”); Serial.println(“*******************************”); Serial.println(“1ReadCalcPID : reafect priority 4 at: 1ReadCalcPID”); vTaskPrioritySet(TaskHandle_1,4); //Now task1 has priority 4 Serial.println(“1ReadCalcPID run: Creating Task2(ParamP0ConsMes)”); xTaskCreate(TaskNxtParamP0ConsMes, “Task2”, configMINIMALSTACKSIZE, NULL, 7, &TaskHandle2); } } //***********************************************2********************************************************************************** void TaskNxtParamP0ConsMes(void *pvParameters) // Ici c’est la tache : TaskNxtParamP0ConsMes Priorité=5/7 { while(1) { Serial.println(“2ParamP0ConsMes : Suspend 1ReadCalcPID”); vTaskSuspend(TaskHandle1); Serial.println(“2ParamP0ConsMes s’octroie Prorité=6″); vTaskPrioritySet(TaskHandle_2,6); //Now task2 has priority 6 Serial.println(“2ParamP0ConsMes run: Creating Task3(CourbP0)”); xTaskCreate(TaskNxtCourbP0, “Task3”, configMINIMALSTACKSIZE, NULL, 7, &TaskHandle_3); } } //***********************************************3*********************************************************************************** void TaskNxtCourbP0(void *pvParameters) // Ici c’est la tache : TaskNxtCourbP0 Priorité=4/7 { while(1) { Serial.println(“3CourbP0 delete 2ParamP0ConsMes”); vTaskDelete(TaskHandle2); Serial.println(“3CourbP0 s’octroie Prorité=6″); vTaskPrioritySet(TaskHandle3,6); //Now task3 has priority 6 Serial.println(“3CourbP0 run: Creating Task4(ParamP0PID)”); xTaskCreate(TaskNxtParamP0PID, “Task4”, configMINIMALSTACKSIZE, NULL, 6, &TaskHandle4); } } //*********************************************4************************************************************************************* void TaskNxtParamP0_PID(void *pvParameters) // Ici c’est la tache : TaskNxtParamP0 Priorité=3/7 { while(1) { Serial.println(“4ParamP0PID delete 3CourbP0″); vTaskDelete(TaskHandle3); Serial.println(“4ParamP0PID run: Make Resume task1(ReadCalcPID)”); vTaskResume(TaskHandle_1); Serial.println(“4ParamP0PID autodelete”); vTaskDelete(TaskHandle_4); } } ~~~ Serial Line Response : *****Setup function*****
*****START****TASK 1***********
1ReadCalcPID : reafect priority 4 at: 1ReadCalcPID 1ReadCalcPID run: Creating Task2(ParamP0ConsMes) 2ParamP0ConsMes : Suspend 1ReadCalcPID 2ParamP0ConsMes s’octroie Prorité=6 2ParamP0ConsMes run: Creating Task3(CourbP0) 3CourbP0 delete 2ParamP0ConsMes 3CourbP0 s’octroie Prorité=6 3CourbP0 run: Creating Task4(ParamP0PID) 4ParamP0PID delete 3CourbP0 4ParamP0PID run: Make Resume task1(ReadCalcPID) 4ParamP0PID autodelete *****START****TASK 1***********
1ReadCalcPID : reafect priority 4 at: 1ReadCalcPID 1ReadCalcPID run: Creating Task2(ParamP0ConsMes) Loop function Loop function Loop function Loop function Loop function Loop function Loop function Loop function Loop function And blocked on Loop …. :-/ I do not understand too much about memory and stack management. the size of the stack here is configMINIMALSTACKSIZE, but must not agree? Thanks for all for my study Jeff

arduino MEGA2560. system Task loop 1 time and stop after the first return task. Thank you for your help

What is configMAX_PRIORITIES set to? I’m not sure I understand your question – are you saying that the first loop (from task to task then back to the first task again) works ok, but not the second loop through the four tasks? If so, it might be because the memory allocated by the scheduler for use as the task stack is not being freed. That will depend on which version of FreeRTOS you are using. From memory FreeRTOS V9 and V10 will free the memory as soon as the task is deleted, unless a task deletes itself, in which case the memory is not freed until the idle task runs. If you are using an older version (can’t remember which version the behaviour changed), then memory will only ever be freed when the idle task runs – in your case the idle task is never running as there is always a task that has a priority above 0 that is ready to run. Try putting a vTaskDelay( pdMSTOTICKS( 20 ) ) call to xTaskCreate() that creates the TaskNxtParamP0_ConsMes task. That will give the idle task some time too.

arduino MEGA2560. system Task loop 1 time and stop after the first return task. Thank you for your help

thanks for this first response 🙂 My arduino FreeRTOS ‘s V8.2.3 I will update in V9 then V10 Indeed the loop from the SETUP is carried out completely, then for the second loop it stops after the first task. I have indeed the error of stack overload and time of request of creation too important (after reading the wiki of the library …) I will try to give time for task creation. I did not do it before because the real program has a lot of calculations and data transmitted to the serial. So I told myself that the calculation time would be “time management”.

arduino MEGA2560. system Task loop 1 time and stop after the first return task. Thank you for your help

Here I use version 10.1 of FreeRTOS for arduino. (the system is indicated as better for AVR, I am on avr MEGA2560 but EDI arduino) But now it does not work at all, it stops at the first task, here are the details : https://www.dropbox.com/sh/d50831bb9laezfs/AACg71eqeer1xhrryrpIlKD_a?dl=0 Serial sended : *****Setup function*****
*****START****TASK 1***********
1ReadCalcPID : reafect priority 4 at: 1ReadCalcPID 1ReadCalcPID run: Creating Task2(ParamP0ConsMes)
BLOCKED BY OVERLOAD MEMORY BY TASK OR PLACE MEMORY NOT ENOUGHT
Thanks in advance

arduino MEGA2560. system Task loop 1 time and stop after the first return task. Thank you for your help

Oh, that doesn’t sound good. Do you have a debugger attached to see where the code stops? Does it get as far as starting the scheduler, and if so, how far does it get after that (i.e. does ‘stops at the first task’ mean the first task runs but the second doesn’t, and if so, at what point in the code does it stop?). Do you have the normal configASSERT() defined, stack overflow detection turned on, etc.?

arduino MEGA2560. system Task loop 1 time and stop after the first return task. Thank you for your help

Hello, I have now integrated this formula but it does not change anything. / * Set to trap errors during development. * /

define configASSERT ((x)) if ((x) == 1) vAssertCalled (FILE, LINE)

I think I will redo the entire sequence with Mutex to think about sharing the display resource that will be the purpose of the program. I understand the concept of each method very well, but in the application there are behaviors that seem inconsistent with the functional description. my knowledge also needs to learn again. But with V10 it’s not better than with V8, for avr MEGA2560 Thank you