Skip to main content
Visitor II
November 14, 2024
Question

STM32F030 - Heap start and end address and usage

  • November 14, 2024
  • 4 replies
  • 1426 views

Hi,

My uC (STM32F30K6T6) is full in RAM memory.

To optimize the RAM size, I have planned to reduce the Heap Size Memory (initial Heap size is 0x400).

I do not use any manual memory allocation so, I think I will set it to a quarter of it (0x100), just in case.

It leads me two interrogrations about heap and stack :

  • how to check and know the exact start and end addresses of the heap and stack memory ? This, to check, in debug mode, the live usage (using IAR RAM memory live watch) of each.
    The .map file just give that piece of information:
    JGreg2_3-1731584498842.png
    Following the described order, should I expect to have first rw, then CSTACK and at the end of RAM memory the heap ?
    At next question, we see that I have hint about the CSTACK start and end RAM addresses (0x2000 0C00 to 0x2000 1000) but what about the Heap adresses?

  • From now on, I don't see any correlation between what I see in the CSTACK usage tool and the RAM Memory
    • Live watch (where I suppose to have the stack)
      JGreg2_0-1731584326331.png
    • I see only 20bytes (CSTACK usage tool) while I see at the end of RAM 
      JGreg2_1-1731584430850.png
      JGreg2_2-1731584442328.png
      For information, here is what I have in the .map file using the stack tracking usage of IAR tool
      JGreg2_0-1731584829351.png

       

 

    This topic has been closed for replies.

    4 replies

    Super User
    November 14, 2024

    You're using the IAR version of runtime library, so better ask IAR support (maybe they have a KB article on this).

     

    JGreg.2Author
    Visitor II
    November 15, 2024

    Pavel A., Thank for your reply but maybe you could try a litle bit to help me since I am using STM32 and I have seen other posts in which users got some replies even if they used IAR.

    To help those who will be interested in, the linker compiler file (.icf) places the heap and stack in an arbitrary order. This can be fixed using 

    define block FIXED_ORDER_RAM with fixed order { block CSTACK, block HEAP};
    place in RAM_region { readwrite, last block FIXED_ORDER_RAM };

    instead of the initial

    place in RAM_region { readwrite, block CSTACK, block HEAP };

    Nevertheless, I still do not see any 1K range of Heap memory at the end of my RAM memory ranged (I can see it from the debugger and the stack usage tool which place a pattern before running).

    And this obversation is coherent with the fact that when I reduce the heap size, my issue is not fixed (my RAM is still considered as full)

    Is there any way that, despite the size is specified, that the compiler/linker (for some reason) do not implement heap at all ?

    Thank you in advance,

    Super User
    November 15, 2024

    @JGreg.2 Unfortunately my IAR license timed out after end of project, so I cannot any longer ask IAR support. Stack Overflow is another place where IAR questions can be answered.

     

    JGreg.2Author
    Visitor II
    November 15, 2024

    Yes, I also did that few hours ago.

    I have read "Actually, most toolchains set a default value of zero for the heap size. Many embedded projects do not use dynamic memory allocation at all." see ST post at this link

    Do you think it means that, even if the size is defined, the toolchain could not add the heat memory at all ?

    JGreg.2Author
    Visitor II
    November 15, 2024

    Allright, answer is yes (if no function related to dynamic allocation has been detected into the code). See post here