Hello everybody,
I am new to Arduino Due, I am trying to get familiar with this platform, and I started to do tests with the memory map/locations.
I bumped into this page:
http://rdiez.shoutwiki.com/wiki/Hacking_with_the_Arduino_Due
that shows a Memory map of the Arduino Due:
0x0008 0000 - 0x000B FFFF 256 KiB flash bank 0
0x000C 0000 - 0x000F FFFF 256 KiB flash bank 1
Both banks above provide 512 KiB of contiguous flash memory
0x2000 0000 - 0x2000 FFFF 64 KiB SRAM0
0x2007 0000 - 0x2007 FFFF 64 KiB mirrored SRAM0, so that it's consecutive with SRAM1
0x2008 0000 - 0x2008 7FFF 32 KiB SRAM1
0x2010 0000 - 0x2010 107F 4224 bytes of NAND flash controller buffer
Maybe it's a silly, but the first thing I am trying to understand is the dynamic allocation of memory with "malloc" that should be related to the Heap. I know that his can generate problems on microcontrollers, bt what it's not clear is why the malloc function returns a valid ( != NULL ) pointer when trying to allocate a 256Kb range of memory. Actually it shouldn't.
Serial.begin(9600);
char Txt[255];
// Try to malloc 256Kb
char *RAMPtr = (char *)malloc(256*1024*sizeof(char));
// Show the pointer value
sprintf(Txt, "RAM pointer 'RAMPtr': %p", RAMPtr);
Serial.println(Txt);
the pointer returned is at: 0x20071310. This location should be in the SRAM0 mirrored bank, correct? But actually the malloc function shouldn't be able to allocate this memory range.
The second problem is similar but this should be related to the Stack. If I declare an array which size is bigger than the memory available it works in any case:
Serial.begin(9600);
char Txt[255];
char Array1[1024*256];
// Show the pointer value
sprintf(Txt, "'Array1' pointer': %p", &Array1);
Serial.println(Txt);
And the 'Array1' pointer' is: 0x20047fe8, but where is this in the memory map?
Are those issues or I am doing something wrong?
Thanks.