4

I'm using STM32 based microcontroller, IAR embedded workbench and STlink v2 debugger. I just want to know how to check the memory utilized/used by the program/system in various memory segments like:

  1. Data segment(initialized and uninitialized)
  2. heap segment
  3. stack segment

any suggestions regarding this would be appreciated.

Myanju
  • 213
  • 1
  • 3
  • 9
  • 2
    Check your linker commands line options, there should be one to produce a linker map, from which you can find the size of the BSS, DATA and CODE segmenst. The heap and stack are 'determined' at run-time (check the startup code), but the boundaries might be prepared by the linker. – Wouter van Ooijen Apr 06 '15 at 08:52
  • 1
    What Wouter said. Also "objdump" if you're using gcc etc. –  Apr 06 '15 at 10:56
  • @WoutervanOoijen Thanks. I generated map file and then saw the sizes of code, data and BSS segments. What else we can do from the map file? – Myanju Apr 06 '15 at 11:28
  • @BrianDrummond I'm using IAR embedded workbench in windows OS. Any ways thanks for the suggestion really i appreciate that. – Myanju Apr 06 '15 at 11:30
  • @Myanju now you'll have to check the startup code (or maybe the implementation of malloc) to see how the stack and heap are initialized. – Wouter van Ooijen Apr 06 '15 at 11:32
  • @WoutervanOoijen Right now i'm not using dynamic memory allocation. I saw startup file it contains some assembly code. Also i saw CSTACK/STACK contents in view option while running the code. But i couldn't see the total stack utilized. – Myanju Apr 06 '15 at 12:19
  • The total stack utilized during running (as opposed to allocated at build) isn't known at build time. (Same holds for the heap.) (There are some languages or dialects for which the compiler can determine the stack use, but full C is not among these.) – Wouter van Ooijen Apr 06 '15 at 12:30
  • A crude method for checking maximum stack and heap usage are to pre-fill those memory areas with a specific value. Then stop the program at various points and examine the memory spaces. Not very elegant, but gives you a rough idea. – Chris Ryding Sep 15 '17 at 16:19

0 Answers0