Stack usage and stack usage control files

Technical Note 61385



9/11/2015 2:30 PM


The stack is described in "IAR C/C++ Development Guide", chapter "Storage of auto variables and parameters". This technical note describes how to get stack usage statistics from an application, and also shows the syntax of stack usage control files (.suc).


Download and open the example project from the link: Example project for IAR Embedded Workbench for ARM


The simple example project contains a 'main' and a 'test_func' function. To enable stack usage analysis, the following project option is enabled:

Project > Options > Linker > Advanced > Enable stack usage analysis

The linker map file now contains stack usage information in the section called "STACK USAGE". For example:

Maximum call chain                           20 bytes

"__iar_program_start" 0
"__cmain" 0
"main" 16
"test_func" 4

The example project also contains two interrupt handlers: 'SysTick_Handler' and 'UsageFault_Handler'. It also contains an OS task: 'test_task'. These functions are not (directly) called by anyone, so in the Stack Usage Control file (.suc), the following must be specified:

call graph root [task] : test_task;
call graph root [interrupt] : SysTick_Handler, UsageFault_Handler;

With the above, stack usage analysis now knows that these (not called) functions are "call graph roots". (Note that instead of using a control file, it is possible to use
#pragma call_graph_root directly in the code).

More information

See "IAR C/C++ Development Guide", chapter "Stack usage analysis".
For Stack Usage Control file syntax, see chapter "The stack usage control file".

See also the Article: Stack usage analysis for IAR Embedded Workbench for RX.

To get run-time stack usage information while debugging in C-SPY, enable: Tools > Options > Stack > 'Enable graphical stack display and stack usage tracking'. In C-SPY, open the View > Stack window.


All product names are trademarks or registered trademarks of their respective owners.

Related Tech Notes

© IAR Systems 1995-2019 - All rights reserved.

We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies