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

CMSIS cortex M startup file, scatter file STACK, HEAP size definitions

Hi,

I'm currently using CMSIS 5.7.0 with ARM compiler 5.

I noticed that there are 2 locations where HEAP, STACK size are defined.
files are located in CMSIS 5.7.0 directory: ARM.CMSIS.5.7.0/Device/_Template_Vendor/Vendor/Device/Source/ARM

  1. scatter file : Device_ac5.sct
  2. assembly startup file: startup_Device.s

In the scatter file, it defines STACK/HEAP size and it's placement defined as ARM_LIB_HEAP and ARM_LIB_STACK.

/*--------------------- Stack / Heap Configuration ---------------------------
; <h> Stack / Heap Configuration
;   <o0> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
;   <o1> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
 *----------------------------------------------------------------------------*/
#define __STACK_SIZE    0x00000200
#define __HEAP_SIZE     0x00000C00

.
.
.


LR_ROM __RO_BASE __RO_SIZE  {                       ; load region size_region
  ER_ROM __RO_BASE __RO_SIZE  {                     ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
   .ANY (+XO)
  }

  RW_RAM __RW_BASE __RW_SIZE  {                     ; RW data
   .ANY (+RW +ZI)
  }

#if __HEAP_SIZE > 0
  ARM_LIB_HEAP  __HEAP_BASE EMPTY  __HEAP_SIZE  {   ; Reserve empty region for heap
  }
#endif

  ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE {   ; Reserve empty region for stack
  }
}


In the assembly startup file, it also defines STACK/HEAP size as below.

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

Stack_Size      EQU      0x00000400

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


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

Heap_Size       EQU      0x00000C00

                IF       Heap_Size != 0                      ; Heap is provided
                AREA     HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE    Heap_Size
__heap_limit
                ENDIF


                PRESERVE8
                THUMB

I find this troublesome since if I have to modify both files at the same time.

Is there a reason for this?

I have also noticed the corresponding new startup_Device.c does not redefine stack/heap size like in the assembly startup file.

Thanks ahead for the help!