cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable warning if a function's maximum stack usage exceeds a value?

fzl
Associate II

I'm using STM32CubeIDE to develop a FreeRTOS application. Sometimes FreeRTOS reports stack overflow for a task at run time.

STM32CubeIDE's Static Stack Analyzer is very useful for analyzing the problem. Even so, I would prefer avoiding the problem at compile time. I need the compile tools to report a warning when a task function's maximum stack usage exceeds a value.

Is Static Stack Analyzer implemented in STM32CubeIDE, or is it implemented in a standalone tool like gcc/objdump/readelf? How to enable the warning if a function's maximum stack usage exceeds a value, either via graphic or command line option? Thanks very much.

2 REPLIES 2
STea
ST Employee

Hello @fzl ,

Static Stack Analyzer in STM32CubeIDE is a post-compilation tool and does not provide compile-time warnings. GCC's -fstack-usage flag can be used to generate stack usage information during compilation.

to activate it do the follwing steps.

In STM32CubeIDE, you can add this flag by:

  • Right-clicking on your project in the Project Explorer.
  • Selecting Properties.
  • Navigating to C/C++ Build > Settings.
  • Under Tool Settings, go to MCU GCC Compiler > Miscellaneous.
  • Add -fstack-usage to the Other flags field.

Regards 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
fzl
Associate II

Thanks for the reply. -fstack-usage is already checked by default in STM32CubeIDE. From my understanding, gcc -fstack-usage reports the stack usage of single functions, not including the stack used by subfunction calls. STM32CubeIDE may have a plugin that analyzes the .su files generated by gcc -fstack-usage, sums up the stack usage in function call chains, and calculates the maximum stack usage. I think it will be very nice to have an option to enable the warning if this tool finds out a maximum stack usage that exceeds a value.