This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Allocate all remaining RAM to HEAP?

I am trying to find a way to allocate all remaining RAM in my application to the heap. Basically a variable heap size that will allow the use of all available memory. I have tried different things with the scatter file, but keep running into needing to specify a size.

I would like the RAM memory map to look like this:

RAM Base Address:

  • Vector table
  • Initialized variable data
  • Zero data
  • Stack (fixed size)
  • Heap (all remaining memory)

Processor: STM32L552

Tools: uVision 5

Existing Scatter File:

; Vector table
LR_VECTOR_TABLE 0x08000000 0x00000200
{
    ER_VECTOR_TABLE 0x20000000 0x00000200
    {
        *.o (RESET, +First) ; Vector table location in RAM.
    }
}


; load region size_region
LR_IROM1 (0x08000000 + 0x00000200) (0x00080000 - 0x00000200)
{
    ; load address = execution address
    ER_IROM1 (0x08000000 + 0x00000200) (0x00080000 - 0x00000200)
    {
        *(InRoot$$Sections)
        .ANY (+RO)
        .ANY (+XO)
    }

    ; RW data
    RW_IRAM1 (0x20000000 + 0x00000200) (0x00040000 - 0x00000200)
    {
        .ANY (+RW +ZI)
    }

}

Default Keil/STM Cube MX stack and heap setup in "startup_stm32l552xx.s":

; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>


Stack_Size EQU 0x00002000

AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp

; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size EQU 0x00001000

AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit