Skip to main content
MauFanGilaMedical
Associate III
May 13, 2025
Solved

Free RTOS parameter CHECK_FOR_STACK_OVERFLOW seems not to work

  • May 13, 2025
  • 4 replies
  • 880 views

Hello.

 

I bought Riverdi board and start to develop my code.

I found in FREERTOS_M7 Config parameters RTOS CHECK_FOR_STACK_OVERFLOW.

 

Documentation says

 

CHECK_FOR_STACK_OVERFLOW
Parameter Description:
FreeRTOS provides two optional mechanisms that can be used to assist in stack overflow detection and debugging.
- when CHECK_FOR_STACK_OVERFLOW is set to 1 (option1), one mechanism is used
- when CHECK_FOR_STACK_OVERFLOW is set to 2 (option2), both mechanisms are used.
If CHECK_FOR_STACK_OVERFLOW is not set to 0 (Disabled), the application must provide a stack overflow hook (or callback) function: void vApplicationStackOverflowHook( xTaskHandle xTask, signed char *pcTaskName );
The kernel will call that stack overflow hook whenever a stack overflow is detected
Note: when set to 1 or 2, a function with an empty body is generated in the freertos.c file (to be completed by the user)

 

So I set CHECK_FOR_STACK_OVERFLOW = 1, trigger a stack overflow by an infinite recursive and set a bkpoint in 

MauFanGilaMedical_0-1747121130697.png

But when I run the code I just reach HardFault_Handler

 

What am I wrong ?

This topic has been closed for replies.
Best answer by TDK

Not in this case.

The check is done when tasks are switched which happens on the millisecond scale. If the overflow happens before then and a hard fault is produced, it will not be prevented. Calling a function recursively will overflow the stack very fast. It is not a magic solution that works all the time without limitation.

4 replies

TDK
May 13, 2025

See here for how this works. It only checks when tasks are switched.

FreeRTOS stack usage and stack overflow checking - FreeRTOS™

"If you feel a post has answered your question, please click ""Accept as Solution""."
MauFanGilaMedical
Associate III
May 13, 2025

Ok, but I expect that if I call recursively a function without any limit as soon as far that stack will going to saturation and I expect that the FreeRTOS signal me that condition if I select one of the option available.

I am right ?

TDK
TDKBest answer
May 13, 2025

Not in this case.

The check is done when tasks are switched which happens on the millisecond scale. If the overflow happens before then and a hard fault is produced, it will not be prevented. Calling a function recursively will overflow the stack very fast. It is not a magic solution that works all the time without limitation.

"If you feel a post has answered your question, please click ""Accept as Solution""."
MauFanGilaMedical
Associate III
May 14, 2025

MauFanGilaMedical_0-1747204263280.png

 

 

MauFanGilaMedical_1-1747204288898.png