ard_newbie:
I have this code to test for the available SRAM of a DUE (Note: there are 96 K of contiguous SRAM plus 4K not contiguous):
#include <malloc.h>
const char errorMsg[] = {"Invalid code!"};
extern char _end;
extern "C" char *sbrk(int i);
char *ramstart=(char *)0x20070000;
char *ramend=(char *)0x20088000;
char* Text[] = {
/* [0] / "Start...",
/ [1] / "Sensor1 Count 0",
/ [2] / "Sensor1 Count 1",
/ [3] / "Sensor1 Count 2",
/ [4] / "Sensor1 Count 3",
/ [5] / "Sensor1 Count 4",
/ [6] / "Sensor1 Count 5",
/ [7] / "Sensor1 Count 6",
/ [8] / "Sensor1 Count 7",
/ [9] / "Sensor1 Count 8",
/ [10] / "Sensor1 Count 9",
/ [11] / "Sensor1 Count 10",
/ [12] / "Sensor1 Count 11",
/ [13] / "Sensor1 Count 12",
/ [14] / "Sensor1 Count 13",
/ [15] / "Sensor1 Count 14",
/ [16] / "Sensor1 Count 15",
/ [17] / "Sensor1 Count 16",
/ [18] / "Sensor1 Count 17",
/ [19] / "Sensor1 Count 18",
/ [20] / "Sensor1 Count 19",
/ [21] / "Sensor1 Count 20",
/ [22] / "Sensor2 Count 0",
/ [23] / "Sensor2 Count 1",
/ [24] / "Sensor2 Count 2",
/ [25] / "Sensor2 Count 3",
/ [26] / "Sensor2 Count 4",
/ [27] / "Sensor2 Count 5",
/ [28] / "Sensor2 Count 6",
/ [29] / "Sensor2 Count 7",
/ [30] / "Sensor2 Count 8",
/ [31] / "Sensor2 Count 9",
/ [32] / "Sensor2 Count 10",
/ [33] / "Sensor2 Count 11",
/ [34] / "Sensor2 Count 12",
/ [35] / "Sensor2 Count 13",
/ [36] / "Sensor2 Count 14",
/ [37] / "Sensor2 Count 15",
/ [38] / "Sensor2 Count 16",
/ [39] / "Sensor2 Count 17",
/ [40] / "Sensor2 Count 18",
/ [41] / "Sensor2 Count 19",
/ [42] / "Sensor2 Count 20",
/ [43] / "Direction --> to box",
/ [44] / "Direction <-- to trainer",
/ [45] / "Nose to Nose",
/ [46] / "Fault",
/ [47] / "Race Completed",
/ [48] / "Error 1",
/ [49] / "Error 2",
/ [50] */ "Error Unknown",
};
void setup()
{
Serial.begin(250000);
while(!Serial);
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",ramend - stack_ptr);
printf("Estimated Free RAM: %d\n\n",stack_ptr - heapend + mi.fordblks);
int* ptr_i;
int i = 0xaa;
ptr_i = &i;
printf("Size of int: %d, Size of uint: %d\n", sizeof(int), sizeof(unsigned int));
printf("Size of char: %d, Size of uchar: %d\n", sizeof(char), sizeof(unsigned char));
printf("Size of short: %d, Size of ushort: %d\n", sizeof(short), sizeof(unsigned short));
printf("Size of float: %d, Size of double: %d\n", sizeof(float), sizeof(double));
printf("Size of long: %d, Size of longlong: %d\n", sizeof(long), sizeof(long long));
printf("Size of pointer (ptr_i): %d\n", sizeof(ptr_i));
printf("Addr of pointer (ptr_i): 0x%x\n", ptr_i);
printf("Value of i: 0x%x\n", *ptr_i);
Serial.println(Text[44]);
Serial.println(Text[0]);
}
void loop() {
// put your main code here, to run repeatedly:
}
Thx : I have this
Dynamic ram used: 0
Program static ram used 28800
Stack ram used 104
Estimated Free RAM: 69400
Size of int: 4, Size of uint: 4
Size of char: 1, Size of uchar: 1
Size of short: 2, Size of ushort: 2
Size of float: 4, Size of double: 8
Size of long: 4, Size of longlong: 8
Size of pointer (ptr_i): 4
Addr of pointer (ptr_i): 0x20087fa4
Value of i: 0xaa
Direction <-- to trainer
Start...
and that
free=65423 FreeStack: 65432
And due crashes....