I am writing an application for Mbed OS that will run on a K64F board. I have different threads running, using the RTOS capabilities of the system.
I need to handle a relatively big string for showing results in a JSON format. I have definned it as a char array. Initially it was defined to be 256 chars long and was working correclty, but when I have increased the size to 2048 to actually fit the needs of the app
char rData[2048];
I get this error on compilation:
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: ./BUILD/K64F/GCC_ARM/02_device.elf section `.heap' will not fit in region `m_data_2'
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: Region m_data_2 overflowed with stack and heap
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: region `m_data_2' overflowed by 22944 bytes
collect2.exe: error: ld returned 1 exit status
[ERROR] c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: ./BUILD/K64F/GCC_ARM/02_device.elf section `.heap' will not fit in region `m_data_2'
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: Region m_data_2 overflowed with stack and heap
c:/program files (x86)/gnu tools arm embedded/6.2 2016q4/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: region `m_data_2' overflowed by 22944 bytes
collect2.exe: error: ld returned 1 exit status
I have not found any reference on how to increase the space reserved for this need.
What am I missing?
Declare the variable on the heap, not on the stack:
char* rData = (char*)malloc(2048);
// potentially, don't always malloc 2048 bytes, but only the amount you need
Don't forget to call free(rData)
when you're done.