Go Down

Topic: Measuring free ram on Samd21 (Read 277 times) previous topic - next topic

starwarslegokid

Hello Everyone,

I discovered the other day a way to get the amount of free ram on a atmega series chip. Adafruit has a nice little writ up, and sure enough it works really well. Saved me alot of trouble diagnosing why my already tested code was breaking when I added some irrelevant code ;-).

https://learn.adafruit.com/memories-of-an-arduino/measuring-free-memory

I was wondering if anyone knew of an equivalent way of doing this for the samd21? I ported freertos to the samd21 for a laser tag project, and it is only a matter of time before I try and fill up all its ram hehehe.

I tried the same code on adafruit, and of course __heap_start and __brkval do not exist when compiling as a samd21 type board.

Anybody have any ideas on finding the samd21 equivalent variables (if they exist), or a different/better way to measure the ram currently in use?

Talk to you soon!
starwarslegokid

westfw

Quote
I ported freertos
Doesn't freertos have its own version of malloc()?
It probably even already has a function that returns the amount of free memory. (um...  xPortGetFreeHeapSize() ?)

sandeepmistry


starwarslegokid

#3
Sep 29, 2017, 09:36 pm Last Edit: Sep 29, 2017, 09:43 pm by starwarslegokid
The FreeMemory library works with the SAMD core: https://github.com/mpflaga/Arduino-MemoryFree
Hello sandeepmistry, thank you for posting this, thats just what I was looking for. I used the example program and added some print statements and it looks like it works great. Samd21 starting with just over 30,000 (im assuming bytes) and after afew constant string prints, the ram trickles down at about two bytes per non flashed char printed.


[/quote]
Doesn't freertos have its own version of malloc()?
It probably even already has a function that returns the amount of free memory. (um...  xPortGetFreeHeapSize() ?)
Hello westfw,

Ahh yes you are correct, freertos does have xPortGetFreeHeapSize(), I totally forgot that! When I ported it over, I ended up setting it up using heap_3 because it was the only one that I could get working at the time. It uses wrapped malloc calls, and throws a error that can be handled if a object creation fails. Problem is heap_3 does not support the xPortGetFreeHeapSize() function since it doesn't know how to predict free memory, just knows when malloc fails.

You bring up a good point, I should probably go back and revisit that code. Now that I know how many bytes are there at startup (~30,000), I can probably figure our how to setup heap_1 which allocates a giant heap array, and can easily check how much I actually used.


Thank you both for your answers! I will use both your advice B-)
starwarslegokid


Go Up