#include "mbed.h"
unsigned char a = 1;
Serial pc(USBTX, USBRX);
unsigned char globalbuff[0x80] =
{
0x72, 0x68, 0x69, 0x73, 0x5F, 0x69, 0x73, 0x5F, 0x67, 0x6C, 0x61, 0x62, 0x61, 0x6C, 0x6C, 0x79,
0x5F, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5F, 0x69, 0x6E, 0x72, 0x61, 0x6D,
0x74, 0x68, 0x69, 0x73, 0x5F, 0x69, 0x73, 0x5F, 0x67, 0x6C, 0x61, 0x62, 0x61, 0x6C, 0x6C, 0x79,
0x5F, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5F, 0x69, 0x6E, 0x72, 0x61, 0x6D,
0x74, 0x68, 0x69, 0x73, 0x5F, 0x69, 0x73, 0x5F, 0x67, 0x6C, 0x61, 0x62, 0x61, 0x6C, 0x6C, 0x79,
0x5F, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5F, 0x69, 0x6E, 0x72, 0x61, 0x6D,
0x74, 0x68, 0x69, 0x73, 0x5F, 0x69, 0x73, 0x5F, 0x67, 0x6C, 0x61, 0x62, 0x61, 0x6C, 0x6C, 0x79,
0x5F, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5F, 0x69, 0x6E, 0x72, 0x61, 0x6D,
} ;
int main() {
pc.baud (115200);
pc.printf("Start\r\n");
globalbuff[0]=0x74; //change a value otherwise compiler will place array in flash instead of ram
int i = 0x100;
pc.printf("i in stack at 0x%8X\r\n", &i);
pc.printf("blogal buff at 0x%8X\r\n", &globalbuff);
pc.printf("SP = 0x%8X\r\n", __current_sp());
while(1) {
void* test = malloc(i);
int i2 = 2;
if (test == NULL) break;
pc.printf("Mallocced 0x%X bytes at 0x%8X, diff = 0x%X\r\n", i, test, (uint32_t)(&i2) - (uint32_t)test);
memset(test,a,0x100);
a++;
}
pc.printf("End\r\n");
}
Dumped ram with ST-link utility and globals, ZI, stack, heap is all in place, no heap-stack overlapp (stack starts at 20017C00) and free() works too.
Hi all,
i updated mbed libs to latest and i saw my old application can't malloc more than 1KB.
The issue comes since mbed lib v87 and mbed-src v262
https://mbed.org/users/mbed_official/code/mbed-src/rev/85569914dbe0
TOOLCHAIN_ARM_MICRO/startup_stm32f401xe.s have been changed from Heap_Size EQU 0x00000000 to Heap_Size EQU 0x00000400
but now the heap can't grow outside that limit, while previously could grow untill overlapping the stack As workaround acutally i'm using latest mbed-src with that startup re-edited back to heapsize=0
Using an example given here to test the heap http://mbed.org/forum/bugs-suggestions/topic/4809/ the heap seems limited to 0x400