Go Down

Topic: Arduino Due free memory (Read 1 time) 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?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131