-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Description
- Type: Enhancement
- Related issue: n/a
- Priority: Major for some platforms w/ less RAM, minor for others with larger RAM
Enhancement
mbed OS allocates the heap and stack areas at runtime for ARM compiler and GCC_ARM compiler. This is done in the file RTX_CM_lib.h. The heap is allocated at the end of the last data section. It uses symbols defined in the scatter files such as Image$$RW_IRAM1$$ZI$$Limit for ARM and end for GCC.
Thus, the scatter files do not need to allocate their own heap and stack sections for ARM compiler and GCC compiler. Although the RW_IRAM1 and end symbols ignore the heap and stack areas (the size of heap and stack is subtracted to determine the start of IRAM1, etc, thus there is no real wasted space), defining the heap and stack in the scatter files limit the size of the available RAM.
For example, reserving 1/4 and 1/8 for heap and stack, reserves quite a lot of space that can't be used for data.
I recommend of of two options:
Option 1) Remove the defines for heap and stack completely. Add a comment that indicates the heap and stack are allocated by RTX at runtime. Pro: clean and tidy, data section can grow bigger. Con: data section could grow too big and not enough heap area reserved.
Option 2) Reduce the heap and stack down to the amount that mbed OS applications typically actually need at a minimum. This would serve as the floor. Pro: more space available for data section to grow bigger. Con: a minimum amount of stack and heap space is ensured to be kept available.
/* Heap minimum 0x1000 (4K) of ram and stack minimum 0x400 (1K)*/
#define stack_size 0x400
#define heap_size 0x1000