How to reduce the heap size, or remove completely the heap?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 4:51 AM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 5:25 AM
Heap and Stack are at the top end of the RAM (unless you're using an RTOS).
from generated sysmem.c:
* ############################################################################
* # .data # .bss # newlib heap # MSP stack #
* # # # # Reserved by _Min_Stack_Size #
* ############################################################################
* ^-- RAM start ^-- _end _estack, RAM end --^
So, the heap does not waste space except you're using it at runtime.
The .ld linker file reserves some space for the heap at link time using the symbol _Min_Heap_Size. Linking fails if less than _Min_Heap_Size + _Min_Stack_Size are free in RAM. You can adjust these linker values in the .ioc file's Project Manager tab. But, if linking succeeds you can gain nothing from changing these values.
Keep in mind that some C runtime functions may use the heap internally, so you might set a breakpoint or do some debug print in sysmem.c function _sbrk to find out whats happening in your system at runtime or study the sources.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 5:25 AM
Heap and Stack are at the top end of the RAM (unless you're using an RTOS).
from generated sysmem.c:
* ############################################################################
* # .data # .bss # newlib heap # MSP stack #
* # # # # Reserved by _Min_Stack_Size #
* ############################################################################
* ^-- RAM start ^-- _end _estack, RAM end --^
So, the heap does not waste space except you're using it at runtime.
The .ld linker file reserves some space for the heap at link time using the symbol _Min_Heap_Size. Linking fails if less than _Min_Heap_Size + _Min_Stack_Size are free in RAM. You can adjust these linker values in the .ioc file's Project Manager tab. But, if linking succeeds you can gain nothing from changing these values.
Keep in mind that some C runtime functions may use the heap internally, so you might set a breakpoint or do some debug print in sysmem.c function _sbrk to find out whats happening in your system at runtime or study the sources.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 5:41 AM
Thanks, just setting _Min_Heap_Size = 0, solved my problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 7:00 AM
You can e.g. reduce the heap size while creating the project in STM32CubeIDE and editing the IOC file:
Project Manager > Project > Linker Settings
This will modify the .ld file and set the entry _Min_Heap_Size accordingly.
Regards
/Peter
