Pages: [1]   Go Down
Author Topic: Arduino Due free memory  (Read 903 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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,
Jason
Logged

ca
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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() {

}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

What is the unit for the memory? k bytes?

Jason
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: [1]   Go Up
Jump to: