Hi,
I am using: ARM Compiler/Assembler/Linker on Cortex-M0.
Given the following template for startup.s: www.keil.com/.../startup_s_pg.html
Stack_Size EQU 0x00000400 AREA STACK, NOINIT, READWRITE, ALIGN=3 Stack_Mem SPACE Stack_Size __initial_sp
I want to define my memory regions(including stack) in scatter file. However, I want to use the start address of my Stack in my code.
My scatter file is as follows:
LOAD START_ADDRESS LR_SIZE { RAM RAM_START_ADDRESS { *(INTERRUPTS, +First) .ANY (+RO) .ANY (+RW,+ZI) } STACK_SPACE END_STACK_ADDR UNINIT STACK_SIZE { *(STACK) } }
I want __initial_sp to point to the END_STACK_ADDR + STACK_SIZE in the startup file and I want to export __initial_sp so that my application can use it.
I have attempted to use Image$$STACK_SPACE$$ZI$$Limit and Image$$STACK_SPACE$$ZI$$Base in my startup.s file but EQU and SPACE does not take these values (not constant).
Stack_Size EQU |Image$$STACK_SPACE$$ZI$$Limit|
How can I reserve SPACE in my startup file with a value of stack size defined in scatter file so that my __initial_sp points to the right location?
if that's not possible, how can I export a variable in my startup.s file that has a name __initial_sp and value of |Image$$STACK_SPACE$$ZI$$Limit| ?
Here are some examples of some pieces that might be useful for you.
LOAD START_ADDRESS LR_SIZE { RAM RAM_START_ADDRESS { *(INTERRUPTS, +First) .ANY (+RO) .ANY (+RW,+ZI) } STACK_SPACE +0 ALIGN 8 EMPTY 0x00000400 ; just an example here, using STACK_SIZE should work { } }
The Scatter File / Linker will create a section called STACK_SPACE in RAM, 8 byte aligned of 0x0400 bytes. The variable Image$$STACK_SPACE$$ZI$$Limit would be the value for __initial_sp.
To use this in the startup file
; Vector Table AREA RESET, DATA, READONLY EXPORT __initial_sp IMPORT |Image$$STACK_SPACE$$ZI$$Limit| __Vectors DCD |Image$$STACK_SPACE$$ZI$$Limit| DCD Reset_Handler DCD NMI_Handler ...... ; finish vector table __initial_sp DCD |Image$$STACK_SPACE$$ZI$$Limit|
In your C code
extern uint32_t Image$$STACK_SPACE$$ZI$$LIMIT; extern uint32_t __initial_sp;
How can I reserve SPACE in my startup file with a value of stack size defined in scatter file?
You do not actually define any space in the startup file in this case. The scatter file will allocate the space at link time and then fill in the proper values to be used by your program (Image$$STACK_SPACE$$ZI$$Limit). This may be referenced by C or assembly language.
I know this is probably not something you can use in this case, but IF you use the standard library, you can just define 2 sections ARM_LIB_STACK and ARM_LIB_HEAP in the scatter file and other than placing Image$$ARM_LIB_STACK$$ZI$Limit in Vector offset 0, there is nothing else you would need to do (you do need to IMPORT __use_tow_region_memory)
Thank you both for your response.