I want to dimension the total heap size of freeRTOS with configTOTAL_HEAP_SIZE.
I use a STMF32F4 microcontroller, featuring:
192KB of SRAM
64KB of CCM RAM (core coupled memory) (I use this memory in my code to init my static variables)
For the moment, I configure configTOTAL_HEAP_SIZE to 102400 bytes
I want to increase the total heap size of freeRTOS because I want more memory space. Are my static variables included in the heap size? Can I set the TOTAL_HEAP_SIZE to 192000KB for example?
FreeRTOS itself uses very approximately 200 to 300 bytes. Task stacks
come from the heap.
You would have to ask your compiler where the rest of the RAM is going.
The easiest way of doing that it to look at the map file - it will
tell you how much RAM each section is taking (.bss, .data, etc.) and
what in those sections is using RAM. That is a C question though, not a
FreeRTOS question - the things that take up RAM in a non-RTOS
application (static variables, statically allocated DMA or network
buffers, etc.) will be the same things taking up RAM when you add
FreeRTOS into the build.
I have another question: which use the rest of memory space?
The rest of the memory should be 192000-(180*1024) = 7280 bytes.
Is it freeRTOS?
Yes partly. FreeRTOS has some static declarations.
The RAM is normally divided among these:
Static and global variables
Any code located in RAM
A heap to be accessed by the standard malloc()/free()
A stack which is used until the scheduler will start
In your project you will probably find a file describing the layout for the linker, e.g. âstm32F40.ldâ.
It describes all memories and it tells were to put the stack and heap (if any).
The linker file defines symbols like e.g. â_ebssâ which you can declare in your code:
extern char _ebss;
The address of â_ebssâ can be used within your code to dynamically determine how much free RAM is actually left. That would be useful if you use âheap_5.câ.
But the following is much simpler and it is also safe:
#define configTOTAL_HEAP_SIZE ( 180 * 1024 )
because the linker will fail when it doesnât fit any more.
Thanks a lot for your precious answers! I understand that I have a lot of static and global variables in my RAM, that reduces the heap space. I moved these variables to the CCM memory to expand the heap space: it works!
I have a trouble with my debugger: when I set the maximum heap size (180 * 1024), I canât watch my variables anymore in the debug mode. My variables are all equal to â0â. But when I reduce the heap size (120 * 1024) I can watch my variables again.
I guess that itâs because the debug mode use a lot of space in the RAM memory, although I have configured the linker to âdebug in flashâ.
Do you ever experienced this kind of trouble? For your information I use Coocox + GNU Tools ARM Embedded + ST Link + STM32F427.