cancel
Showing results for 
Search instead for 
Did you mean: 

Check free memory (STM32L0)

Jeroen deBuffel
Associate III

Hello,

During code execution I would like to monitor the available memory. Is there a default function available to check the available RAM memory?

Thanks

6 REPLIES 6

What do you mean by "available memory"?

Normally, memory is allocated during translation (linking) and you can check its consumption e.g. in mapfile.

Runtime, memory is consumed by stack and dynamic allocation (malloc() - heap). The latter is unlikely to be used in STM32L0. Stack pointer can be read out and checked runtime, but that has questionable value, given the check is not guaranteed to happen at the moment when the stack is at its deepest point.

So I'm not quite sure what exactly do you want to check and why.

JW

MM..1
Chief III

Simple this function exist only on high level OS.

Read somethink c - malloc behaviour on an embedded system - Stack Overflow

Jeroen deBuffel
Associate III

Thanks for your feedback and links.

The reason why I would like to check memory (RAM) is because I used a external library with a memory leak. I solved the leak but it triggered me to look for a way to measure memory usage.

These things typical use simple linked lists with a small chaining structure ahead of the pointer returned by the allocator.​

The free memory list typically available as a pointer.​

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

Any example or tip? I search on Google but could not find them. Thnx

Source to the GNU libraries should be open.

It's just use a linked-list, so perhaps 2 to 4 words in front of the allocated pointer.

uint32_t *p = malloc(1024);

uint32_t *q = p - 3;

printf("%p %p %p\n",q[0],q[1],q[2]);

You'd basically find the pointer to the free list, and then walk the list, should be able to determine the total free space, and the largest ones, and how fragmented the heap is.

https://community.st.com/s/question/0D50X00009XkgLxSAJ/stm32f4-extending-the-heap-to-seperate-ram-regions

Heap and List stuff presumably covered in first year CompSci college texts.

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