How to determine maximum stack usage in embedded system?

前端 未结 2 1181
悲&欢浪女
悲&欢浪女 2021-01-02 05:08

When I give the Keil compiler the \"--callgraph\" option, it statically calculates the exact \"Maximum Stack Usage\" for me.

Alas, today it is giving me a \"Maximum

相关标签:
2条回答
  • 2021-01-02 05:22

    Use the --info=stack in the linker option. The map file will then include a stack usage for all functions with external linkage.

    In a single tasking environment, the stack usage for main() will give you the total requirement. If you are using an RTOS such as RTX where each task has its own stack, then you need to look at the stack usage for all task entry points, and then add some more (64 bytes in the case of RTX) for the task context storage.

    This and other techniques applicable to Keil and more generally are described here

    0 讨论(0)
  • 2021-01-02 05:39

    John Regehr of the University of Utah has a good discussion of measuring stack usage in embedded systems at http://www.embedded.com/design/prototyping-and-development/4025013/Say-no-to-stack-overflow, though note that the link to ftp.embedded.com is stale, and one occurrence of “without interrupts disabled” should have either the first or last word negated. In the commercial world, Coverity has a configurable stack overflow checker, and some versions of CodeWarrior have a semi-documented warn_stack_usage pragma. (It’s not mentioned in my version of the compiler documentation, but is in MetroWerks’ “Targeting Palm OS” document.)

    0 讨论(0)
提交回复
热议问题