Question
Why does stack overflow occurs when using CCES Compiler's Stack Overflow Detection Facility (-rtcheck-stack) in simple CCES project after adding freertos addin ?
Answer
By Default, Stack Limit for Checking Stack Overflow using CCES Compiler's Stack Overflow Detection Facility (-rtcheck-stack) just includes L1 Memory.
Through the above the relationship of Stack Limit and Memory Address can be found as below:
__adi_stack_bounds = &ldf_stack_space;
ldf_stack_space = stack_and_heap_in_L1_data_a; (project > System > Startup_ldf >app.ldf)
Therefore, the Stack Limit for Checking Stack Overflow just includes L1 Memory at default setting.
However, FreeRTOS project use both of L1 & L2 memory and Stack Overflow occurring when accessing L2 Memory:
For example:
xTaskCreateStatic() function occupies the L1 memory.
xTaskCreate() function occupies the L2 memory.
Hence once the L2 memory has been accessed, the STACK POINTER will exceed the STACK LIMIT witch just including the L1 Memory, and inducing the stack overflow.
Therefore the FreeRTOS official Check Stack Overflow function can be used instead of the CCES internal Stack Run-Time Check function.
It will be helpful to use the FreeRTOS official Check Stack Overflow function vApplicationStackOverflowHook() instead of CCES internal function “Generate code to catch a stack overflow”.
This ’s an official and usual way to check the stack validity for FreeRTOS program, more detail can be found at: https://www.freertos.org/Stacks-and-stack-overflow-checking.html