Skip to main content
Associate II
November 11, 2024
Solved

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

  • November 11, 2024
  • 1 reply
  • 1397 views

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.

Best answer by STea

Hello @fzl ,

your request has been sent to our development team for investigation under ticket number 199458 (for internal reference only).
Regards

1 reply

ST Employee
November 11, 2024

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 

fzlAuthor
Associate II
November 12, 2024

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.

STeaBest answer
ST Employee
January 14, 2025

Hello @fzl ,

your request has been sent to our development team for investigation under ticket number 199458 (for internal reference only).
Regards