cancel
Showing results for 
Search instead for 
Did you mean: 

How to know the remaining free RAM memory in my STM32?

jean_prieur
Associate III
Posted on April 04, 2014 at 12:36

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 !

Jean
10 REPLIES 10
chen
Associate II
Posted on April 04, 2014 at 12:45

Hi

Not easy to answer.

Which malloc() implementation are you using?

jean_prieur
Associate III
Posted on April 04, 2014 at 13:12

Hello,

I use a malloc from stdlib. What do you mean by malloc() implementation ?

Posted on April 04, 2014 at 13:30

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?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chen
Associate II
Posted on April 04, 2014 at 13:38

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)

jean_prieur
Associate III
Posted on April 04, 2014 at 14:02

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 ?

jean_prieur
Associate III
Posted on April 04, 2014 at 14:18

Moreover, there is no special FreeRTOS command which return the used/free ram space ? That would be the best !

stm322399
Senior
Posted on April 04, 2014 at 14:25

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 ?
jpeacock2399
Associate II
Posted on April 04, 2014 at 15:59

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
Posted on April 04, 2014 at 16:22

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..