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:

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 17 shows how to set up the heap pointers using assembly language.

Example 17.  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 18 shows how to set up the heap pointer using embedded assembler in C.

Example 18.  Embedded Assembler in C

__asm void dummy_function(void)
{
    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
}

Show/hideSee also

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0475H
Non-ConfidentialID070912