In the Keil, how to Set initial stack pointer (MSP) by changing linker script? Relevant example would help.
Linker script specifies how linker should position code and variables in the memory.So, if you specify a memory region for stack it will allocate the memory at specified position in RAM.
For Cortex-M cores CPU loads initial stack pointer with value at address 0, it is usually defined in startup files (vectors).
First address specifies initial stack pointer (loaded to MSP) and second address (at offset 4) specifies the reset vector, initial PC value.
In the Keil startup file there is option to set stack and heap sizes, but no option to set my own address for initial stack pointer in the Keil startup file.
You have to edit the linker script and position STACK section to your desired address.
In the Options for Target / Linker uncheck Use Memory Layout from Target Dialog and click on Scatter File Edit button, and edit the linker script as you see fit.