Pages: [1]   Go Down
Author Topic: How can we measure the amount of RAM consumed by a code in Arduino Due  (Read 562 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I need to measure the amount of RAM used up by my code on Due. Can anybody tell me how to do it.
Thanks in advance. smiley
Logged

Turku
Offline Offline
Full Member
***
Karma: 0
Posts: 217
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you got an answer yet.
There are ways to to do it with other Arduinos. Is it different than with DUE.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There are libraries/functions for the AVRs but I don't know if they have been ported to the SAM.

A quick and dirty way is to malloc() a single byte and get it's address, subtract that value from the max RAM address then subtract a fudge factor for the stack.

On LPCs you can get the SP as well and that's probably a option on the SAM, but you could also call a dummy function and get the address of a local variable to get an approx stack value. Or for that matter get the address of a local var in loop().

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This seems to provide a good number on a Mega

Code:
void setup() {
  byte stack;
   
   long heap = (long)malloc(1);
   
   Serial.println ((long)&stack );
   Serial.println (heap);
   Serial.println ((long)&stack - heap);

}

No reason to believe it would not work on the Due.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: