Keil Logo

ARM: Dynamic Memory Allocation fails with generic Arm devices


Information in this knowledgebase article applies to:

  • MDK v5.x
  • ARMCC v5.x compiler
  • ARMCLANG v6.x compiler
  • ARM::CMSIS pack version 5.4.0

SYMPTOM

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.

CAUSE

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.

RESOLUTION

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

STATUS

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.

MORE INFORMATION

SEE ALSO

Last Reviewed: Monday, January 11, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.