#! armclang -E --target=arm-arm-none-eabi -mcpu=cortex-m0+ -xc
; command above MUST be in first line (no comment above!)

/*
;-------- <<< Use Configuration Wizard in Context Menu >>> -------------------
*/

/*--------------------- Flash Configuration ----------------------------------
; <h> Flash Configuration
;   <o0> Flash Base Address <0x0-0xFFFFFFFF:8>
;   <o1> Flash Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
 *----------------------------------------------------------------------------*/
#define __ROM_BASE      0x10000000
#define __ROM_SIZE      0x00200000

/*--------------------- Embedded RAM Configuration ---------------------------
; <h> RAM Configuration
;   <o0> RAM Base Address    <0x0-0xFFFFFFFF:8>
;   <o1> RAM Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
 *----------------------------------------------------------------------------*/
#define __RAM_BASE      0x20000000
#define __RAM_SIZE      0x00042000

/*--------------------- 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    0x00001000
#define __HEAP_SIZE     0x00001000

/*
;------------- <<< end of configuration section >>> ---------------------------
*/


/*----------------------------------------------------------------------------
  User Stack & Heap boundary definition
 *----------------------------------------------------------------------------*/
#define __HEAP_BASE         (AlignExpr(+0, 8))           /* starts after RW_RAM section, 8 byte aligned */

#define __STACK_ONE_SIZE    512

/*----------------------------------------------------------------------------
  Scatter File Definitions definition
 *----------------------------------------------------------------------------*/
#define __RO_BASE       __ROM_BASE
#define __RO_SIZE       __ROM_SIZE

#define __RW_SIZE      (__RAM_SIZE - __STACK_SIZE - __HEAP_SIZE)

/*
 * Stage two Boot
 */
LR_STAGE2_BOOT __RO_BASE 0x100 {
    ER_STAGE2_BOOT +0 0x100 {
        compile_time_choice.o (+RO)
    }
    ER_FILL ImageLimit(ER_STAGE2_BOOT) FILL 0xDEADBEEF 0x100 - ImageLength(ER_STAGE2_BOOT) {
    }
}

/*
 * next to stage two boot
 */
LR_ROM +0 __RO_SIZE - 0x100  {                      ; load region size_region
    ER_ROM +0 __RO_SIZE  {                          ; load address = execution address
        *.o (RESET, +First)
        *(InRoot$$Sections)
        * (+RO-DATA)
        * (.flashdata.*)

        * (:gdef:Reset_Handler)
        * (:gdef:SystemInit)
        .ANY (+RO-CODE)
        .ANY (+XO)
    }

    /*
     * This is required by pico-sdk
     */
    ER_RAM_VECTOR_TABLE __RAM_BASE {
        *  (.ram_vector_table)
    }

    /*
     * This is required by pico-sdk
     */
    ARM_LIB_STACK_ONE +0 ALIGN 8  EMPTY __STACK_ONE_SIZE {
    }

    ARM_LIB_STACK +0 ALIGN 8 EMPTY __STACK_SIZE {   ; Reserve empty region for stack
    }

    /*
     * This is required by pico-sdk
     */
    ER_MUTEX_ARRAY +0 {
        * (.mutex_array.*)
        * (.mutex_array)
    }

    RW_RAM +0  {                                    ; RW data
        .ANY (.time_critical.*)
        .ANY (+RW +ZI)
    }

    RW_IRAM_NOINIT +0 UNINIT {  ; RW data
        .ANY (.after_data.*)
        .ANY (.bss.noinit)
        .ANY (.uninitialized_data.*)
    }

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



    /* This empty, zero long execution region is here to mark the limit address
     * of the last execution region that is allocated in SRAM.
     */
    SRAM_WATERMARK +0 EMPTY 0x0 {
    }
    /* Make sure that the sections allocated in the SRAM does not exceed the
     * size of the SRAM available.
     */
    ScatterAssert(ImageLimit(SRAM_WATERMARK) <= __RAM_BASE + __RAM_SIZE)

}
