2014-04-04 03:36 AM
Hello,
I'm working with a STM32F427VI (256kb of RAM), I use Coocox and FreeRTOS. Do you kown the easiest way to monitor in real time the RAM memory used and free in my uC ?Thanks !Jean2014-04-04 03:45 AM
Hi
Not easy to answer. Which malloc() implementation are you using?2014-04-04 04:12 AM
Hello,
I use a malloc from stdlib. What do you mean by malloc() implementation ?2014-04-04 04:30 AM
Presumably to understand the method/algorithm used for dynamic allocation. Review the initial size of the heap, and if you can track that, or the allocation chains in memory.
So what ''free memory'' are you looking for? The total of free memory, or the largest contiguous block available for allocation?2014-04-04 04:38 AM
Hi
If you look at the FreeRTOS documentation and implementation - you have to choose from 1 of 4 different malloc() implementations. 3 of them are more traditional embedded implementations where the developer has to define the memory (probably from the linker) that the malloc can use. The four implementation (no3 from memory) uses the gcc/gnu (or toolchain) version of malloc() - then it is upto the toolchain/developer to make sure the memory for the heap is defined and correctly used. Anyway to answer - 'how much RAM is left' - the answer is how much heap has not been used. (This should already take into account all the static allocations and the zero vars)2014-04-04 05:02 AM
Thanks a lot for your answers. Actualy i use the heap_2 in FreeRTOS. I don't remember exactly why. For example, how do you do in your projects to monitor if there is enough space left in the heap ? I'm going to check the FreeRTOS documentation in order to see the differences between the different heap_x files.
By the way what is the maximum size of a continuous block allocation in my case ?2014-04-04 05:18 AM
Moreover, there is no special FreeRTOS command which return the used/free ram space ? That would be the best !
2014-04-04 05:25 AM
heap_2.c only has 6 functions defined. One of them is:
size_t xPortGetFreeHeapSize( void )
{
return xFreeBytesRemaining;
}
Maybe is this the one you are looking for ?
2014-04-04 06:59 AM
The FreeRTOS call only shows the remaining space allocated to the heap. It doesn't include unused SRAM. I use a GCC linker script to assign global symbols to the last used RAM position in each bank (CCM, SRAM1, SRAM2).
In the GCC example the BSS region is the end of assigned memory for the SRAM1 bank. I can look at the address for .ebss and determine unused SRAM1 space by subtracting it from the known SRAM1 upper boundary. Declare .ebss an extern int in the C code to reference it. If you want to get a bit more sophisticated with the linker you canmap the FreeRTOS heapto the end of SRAM, mark the allocated end, and then on boot up extend the FreeRTOS malloc() boundary to use all unassigned RAM. As to how linker scripts work in other environments maybe someone else can aswer the question. This is for Eclipse and GCC toolchain./* the BSS section is for zeroed RAM */
.bss (NOLOAD) :
{
. = ALIGN(4); /* word align for fast clear */
_sbss = .;
*(.bss*) /* zeroed RAM, no initialization */
*(COMMON)
. = ALIGN(4); /* word align */
_ebss = .;
} > SRAM1
Jack Peacock
2014-04-04 07:22 AM
By the way what is the maximum size of a continuous block allocation in my case ?
Well it would depend, wouldn't it, on how fragmented the heap has become. In order to determine how large any available block could be you'd likely need to enumerate a linked list of allocations within the heap (implementation specific). Google, or use Wikipedia, to understand Dynamic Memory allocation issues, including fragmentation, and leakage.