Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate stack overflow on FreeRTOS

I configured CubeMX STM32 to use FreeRTOS stack overflow monitoring. Now I want to test that it in fact works. I tried some simple stuff like executing below function in one of the threads

`// C program to demonstrate stack overflow 
// by creating a non-terminating recursive 
// function. 

void fun(int x) 
{ 
    if (x == 1) 
       return; 
    x = 6; 
    fun(x); 
} 

   int x = 5; 
   fun(x); 

but I get HardFault.

Do you know a way to simulate stack overflow on FreeRTOS?

like image 796
Lukasz Stanek Avatar asked Aug 09 '26 19:08

Lukasz Stanek


1 Answers

Looks like I found the solution. All you need is to change stack size of one thread to very low and program goes to vApplicationStackOverflowHook

like image 187
Lukasz Stanek Avatar answered Aug 11 '26 17:08

Lukasz Stanek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!