ARM: Dynamic Memory Allocation fails with generic Arm devices
Information in this knowledgebase article applies to:
When using the startup code (e.g. startup_ARMCM4.s) for a generic Arm device (e.g. Cortex M0, Cortex M3, Cortex M4...) from the ARM::CMSIS pack version 5.4.0 together with the Arm C library (not MicroLIB), dynamic memory allocation functions (malloc, calloc ...) will most likely fail.
Almost all startup codes from Arm Packs, define the Stack and the Heap in two independent memory areas. In order to select this two region model, the symbol __use_two_region_memory must be imported into the startup code. This was missing in these startup files. By default, the Arm C library uses the one region model.
Since the MicroLIB uses the two region model by default, the symbol __use_two_region_memory must only be imported for the Arm C library. This Arm C library is selected if MicroLIB not selected in a µVision project.
The three lines marked with "; please add" need to be added to the startup code in order to import the symbol __use_two_region_memory when the Arm C library is used:
; User setup Stack & Heap IF :LNOT::DEF:__MICROLIB ; please add IMPORT __use_two_region_memory ; please add ENDIF ; please add EXPORT __stack_limit EXPORT __initial_sp IF Heap_Size != 0 ; Heap is provided EXPORT __heap_base EXPORT __heap_limit ENDIF
This issue was introduced with ARM:CMSIS pack v 5.4.0 and will be fixed in ARM::CMSIS pack v 5.5.0. It was already fixed in the CMSIS version 5 GitHub repository with commit 605e4d6.
Last Reviewed: Friday, December 14, 2018
of your data.