It seems to me, that Stack address is starting wrong at 0x10001FFF ( = 0x10002000 - 1 )
I think the Stack should start at 0x100017FF ( = 0x10008000 - 1 )
The area ( 0x10001800 to 0x10001FFF) overwrites the area (0x10000000 to 0x100007FF) and this is causing a conflict of memory if we use more than 2Kb.
Because Global and Heap are starting at 0x10000000 and Stack starts writing at 0x100007FF (if it starts at 0x10001FFF).
I’ve had a lot of memory problems creating my game for contest, so I had to optimize the code to use less memory, and only now I noticed that.
The code below I tested on mBuino Retro:
#include "mbed.h"
int main() {
char RAM_stack[8];
DigitalOut led1(P0_9);
DigitalOut led2(P0_8);
led1 = 0; led2 = 0;
wait_ms( 1000 );
if( (int)RAM_stack > 0x10001800 ) led1 = 1; // RAM_stack is over 0x10001800
wait_ms( 1000 );
led1 = 0; // turn off led1
wait_ms( 1000 );
char *p = RAM_stack;
p -= 0x1800;
if( (int)p < 0x10000800 ) led1 = 1; // Confirm that p is below 0x10000800
wait_ms( 1000 );
*p = 0xA6; // Set value in p
RAM_stack[0] = 0x59; // Set value in Stack
if( *p == 0x59 ) led2 = 1; // Verify value in Stack - 0x1800
while( 1 );
}