-1

I am using FreeRtos and have multiple tasks using the same code at the same priority level. To test my code I pass the same data into each task. When optimization is above -O0 and timeslicing is turned on, there is some sort of problem where the context is not being saved correctly.

My understanding is the each Task has its own stack, and on the context switch from one to another, the stack pointer will be updated accordingly, assuring that each Task stays independent. This isn't happening for me. When I run each task individually, I get one answer, but if I test by running all three tasks, I get one answer correctly and the others are slightly off. There is some sort of crossover of data between the tasks making them not truly independent.

Any idea where this issue could be coming from? I am not using any global variables and my code is reentrant as far as I can tell.


LRID
  • 53
  • 7
  • Are you using xTaskCreateStatic() or xTaskCreate() ? If it is the latter case check your heap size, it could be that task stack could overlap, see https://www.freertos.org/Stacks-and-stack-overflow-checking.html – ieio May 12 '20 at 15:21
  • im using xTaskCreate(). My heap seems to be large enough, I've doubled it a few times for testing and had the same problems. I have check_for_stack_overflow set to 2 which should be robust enough to see any overflow issues. – LRID May 12 '20 at 16:13

1 Answers1

0

In case anyone runs into this I discovered the problem.

I am running FreeRtos on an Arm Cortex-A9 chip. To prevent processor register corruption a task must not use any floating point registers unless it has a floating point context. In the case of my project, the tasks were not created by default with floating point context.

I added portTASK_USES_FLOATING_POINT() to the beginning of my task. That corrected the error and the multitasking works now.

Note that I also had to add this to my UnitTest task that was calling the original three "broken" tasks, as posting to a Queue is error prone as well.

You can see more here: https://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html and here: https://www.freertos.org/FreeRTOS_Support_Forum_Archive/April_2017/freertos_FreeRtos_native_Floats_and_Task_switching_03b24664j.html

LRID
  • 53
  • 7