Go Down

Topic: Arduino Due free memory (Read 5164 times) previous topic - next topic



I have a problem with my code, and I suspect it is caused by overloaded memory, so I want to check memory usage at real time. Is there a way to find available memory on arduino due at runtime? I found a code in Arduino Playground (http://playground.arduino.cc/Code/AvailableMemory), but it does not work for Arduino Due.

Thank you,


Try that, works for me, it is a starting point.

Code: [Select]
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>

extern char _end;
extern "C" char *sbrk(int i);
char *ramstart=(char *)0x20070000;
char *ramend=(char *)0x20088000;

void setup() {
        char *heapend=sbrk(0);
register char * stack_ptr asm ("sp");
struct mallinfo mi=mallinfo();
printf("\nDynamic ram used: %d\n",mi.uordblks);
printf("Program static ram used %d\n",&_end - ramstart);
printf("Stack ram used %d\n\n",ramend - stack_ptr);
printf("My guess at free mem: %d\n",stack_ptr - heapend + mi.fordblks);

void loop() {




What is the unit for the memory? k bytes?



Thanks for that - seems to work great.  Of course, only on the Due... so hard to use it to do comparisons between the board.  What a gaping hole in the Arduino libraries!  With 2K of SRAM, OF COURSE a simple to use memFree is needed.  Rant rant...

When I use this is a very simple sketch, I get
Dynamic ram used:0
Program static ram used 2616
Stack ram used 72
My guess at free mem: 95616

This looks like 2.6K used, for a sketch that just uses the serial port . that seems a lot!  What figures have you found?


Jan 12, 2017, 05:35 pm Last Edit: Jan 13, 2017, 03:13 am by mistergreen
Hey, does anyone have a fix for this for the new Arduino die 1.8.1?

It errors out at
#include <malloc.h>

struct mallinfo mi=mallinfo();
error -> mallinfo mi' has initializer but incomplete type

I needed download the Due board and set it to compile to the Due.

Go Up