2.6 Configuring the stack and heap for use with microlib

To use microlib, you must specify an initial pointer for the stack. You can specify the initial pointer in a scatter file or using the __initial_sp symbol.

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

To configure the stack and heap for use with microlib, use either of the following methods:

  • Define the symbol __initial_sp to point to the top of the stack. If using the heap, also define symbols __heap_base and __heap_limit.

    __initial_sp must be aligned to a multiple of eight bytes.

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

  • In a scatter file, either:

    • Define ARM_LIB_STACK and ARM_LIB_HEAP regions.

      If you do not intend to use the heap, only define an ARM_LIB_STACK region.

    • Define an ARM_LIB_STACKHEAP region.

      If you define an ARM_LIB_STACKHEAP region, the stack starts at the top of that region. The heap starts at the bottom.

Examples

To set up the initial stack and heap pointers using armasm assembly language:

    EXPORT __initial_sp
__initial_sp EQU 0x100000        ; top of the stack
    EXPORT __heap_base
__heap_base  EQU 0x400000        ; start of the heap
    EXPORT __heap_limit
__heap_limit EQU 0x800000        ; end of the heap

To set up the initial stack and heap pointers using embedded assembler in C:

__asm void dummy_function(void)
{
    EXPORT __initial_sp
__initial_sp EQU 0x100000        ; top of the stack
    EXPORT __heap_base
__heap_base  EQU 0x400000        ; start of the heap
    EXPORT __heap_limit
__heap_limit EQU 0x800000        ; end of the heap
}
Non-ConfidentialPDF file icon PDF versionARM DUI0475M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.