Search code examples
cstm32iarmap-files

IAR Stack Usage for STM32 in the map File


I don't understand very well the meaning of some details about the stack usage in the map file of my firmware. I have this in the map file:

*******************************************************************************
*** STACK USAGE
***

  Call Graph Root Category  Max Use  Total Use
  ------------------------  -------  ---------
  interrupt                      48        112
  Program entry                 704        704
  Uncalled function             424     25 424

Can someone help me to understand what's means "Max Use" and "Total Use"? What is the real size of the stack? Is 48+704+424 or 112+704+25424 ? Does the stack include the data for uncalled functions? I search in the IAR Help but is not clear.

Thanks in advance


Solution

  • The "Max Use" column refers to the maximum usage of any one function in the row's category. In the first row, interrupts, it is saying that the maximum stack depth of any one function flagged as an interrupt is 48 bytes. Among your uncalled functions, which may be referenced by function pointers, or may be used as task entry functions, the single deepest stack is 424 bytes deep. Lastly, your program entry (so, usage of the main stack starting from reset) has a maximum depth of 704 bytes.

    The "Total Use" column, is summing the stack usage of all items in each category. So, for interrupts, this is the total of all interrupt stack usage, and is useful on a Cortex-M3 because interrupts can nest. This value is giving you the maximum depth from function calls you would expect to see on the interrupt stack if every interrupt fires and nests, less the registers that the core stacks for you. For uncalled functions, this number is a little less useful, because it isn't expected that the uncalled functions will nest and all stack up at the same time. Lastly, your program entry, being that there's only one of them, has a total usage among all (one) program entry points of 704 bytes.

    This summary isn't all that useful if you're trying to determine what stack sizes you should use. Because of the large use of uncalled functions, you either have significant indirect calls (via function pointers or jump tables) that IAR can't resolve, or lots of RTOS tasks. For indirect calls, there is an IAR pragma to indicate what functions it can possibly call, and that will allow the stack analysis to be more accurate. For RTOS tasks, you will need to look further down in the map file to see for individual task entry functions what stack size is needed.

    If you are just looking to see how large the stack has been allocated, you can look in the other part of the map file for the CSTACK definition, and it will have the size listed with it.