heap and absolute variables

Heap and absolute variables can overlap one another!!!

The mbed (linker) reserved for heap 1kB, but the heap practically can grow up to a stack area. If you define a variable absolute above the area reserved (1kB), will be overlap the heap.
eg volatile int aa attribute((at(0x20001000)));

Solutions:

  • choose the absolute address of the variable smaller than about the size of the area reserved heap size plus the interrupt vector table.
    Then the area reserved for heap starts above the variable.

  • change in the .s file size of the area reserved for heap (Heap_Size) at a sufficiently higher.
    eg startup_stm32f401xe.S

Heap_Size       EQU     0x00000400

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
                EXPORT  __heap_base
                EXPORT  __heap_limit
                
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit    EQU (__initial_sp - Stack_Size)


The value of the variable Heap_Size can greatly increase depending on the size of RAM.
Note that the heap manager are seen only symbols __heap_base __heap_limit and the linker seen only the size of the area Heap_Size.


To edit a file .S: export the file to a local computer, delete the file from the library, change the file extension from .S to.s, import the file from the local computer by the Import Wizard and move it where you need.


Please log in to post comments.