You copied the Doc URL to your clipboard.

Creating the heap for use with microlib

To use the heap functions, for example, malloc(), calloc(), realloc() and free(), you must specify the location and size of the heap region.

To specify the start and end of the heap you can use either of the following methods:

  • Use a scatter file.

  • Define symbols __heap_base and __heap_limit.

The scatter file method uses ARM_LIB_HEAP and ARM_LIB_STACKHEAP.

Otherwise, specify the start and end of the heap by defining symbols __heap_base and __heap_limit respectively. On completion, you can use the heap functions in the normal way.

Note

The __heap_limit must point to the byte beyond the last byte in the heap region.

Example 16 shows how to set up the heap pointers using armasm assembly language.

    EXPORT __heap_base
__heap_base EQU 0x400000        ; equal to the start of the heap
    EXPORT __heap_limit
__heap_limit EQU 0x800000       ; equal to the end of the heap

Example 17 shows how to set up the heap pointer using inline assembler in C.

asm("  .global __heap_base\n"
    "  .equ __heap_base, 0x400000\n"  /* equal to the start of the heap */
    "  .global __heap_limit\n"
    "  .equ __heap_limit, 0x800000\n" /* equal to the end of the heap */
);

Was this page helpful? Yes No