Environment
The dev environment is Microchip (ex-Atmel) Studio. The target processor is a ATSAMC21G18A on a custom PCB. FreeRTOS version 8.0.1 is being used, being provided directly by ASF.
How Problem Begins
My code in main.c quickly proceeds to creating a first task, and then calling the scheduler.
// Create first task.
xTaskCreate( Test_Task, "TEST", TEST_TASK_STACK_SIZE, NULL, TEST_TASK_PRIORITY, NULL );
// Launch the OS.
FOREVER() {
vTaskStartScheduler();
}
Nature of the Issue
If:
- Optimization is set to None,
Then:
- Execution passes into
xTaskCreate, which is reallyxTaskGenericCreate, - Which eventually calls
prvAddTaskToReadyList( pxNewTCB );in tasks.c, - Which leads via a macro into
vListInsertEndin list.c, - And a CPU fault is triggered when trying to execute line 102,
pxIndex->pxPrevious->pxNext = pxNewListItem;
With the above changed to ANY optimization level except None, execution is normal and FreeRTOS operates normally. No CPU fault is experienced. I tested all of the available optimization settings.
The big difference that is apparent is that within tasks.c, a key variable is pxNewTCB. If optimization is OFF, then it is present, yet contributes to the CPU fault event. If any optimization is turned ON, then pxNewTCB is optimized out in the debug experience, yet everything operates normally.
I've developed many systems with this exact toolchain and processor family with this version of FreeRTOS, and this is the first time I've seen this issue. Pulling out another PCB with the same processor and a software project that is very similar (same startup code, same FreeRTOS version, identical FreeRTOS config header file, etc), the above behavior is not present - I can set the optimization to any level and FreeRTOS does not exhibit the issue described above.
I'm curious if anyone has seen this issue or knows of a solution to it. It would be nice to not have to hold the whole project at an optimization level due to this issue.