The initial stack pointer is the stack address loaded by the processor when it starts an image. On Arm Cortex-M, the first vector table entry supplies the initial value of the Main Stack Pointer (MSP); the second entry gives the reset handler address. The first entry is an address, not a function pointer. section 4.1.3 section 4.2.1
A linker script can place the vector table in FLASH and compute the initial stack pointer as the end of RAM. The stack then grows downward. This does not reserve a separate stack section: enough RAM must remain unused, or the stack and other data can overwrite each other. section 4.1.3
SECTIONS
{
.vector_table :
{
LONG(ORIGIN(RAM) + LENGTH(RAM)); /* Initial stack pointer (
top of RAM) */
KEEP(*(.vector_table.reset_vector)) /* Reset vector (
entry point) */
KEEP(*(.vector_table.exceptions)) /* Other exceptions and
interrupts */
} > FLASH
The LONG expression writes the initial stack pointer as the first entry. KEEP preserves the reset vector and exception entries during linker garbage collection. section 4.1.3
At startup, the processor looks for the vector table at address 0x00000000. A device can alias that address to FLASH at a higher address, such as 0x08000000. After loading the MSP and jumping to the reset handler, low-level initialization begins. section 4.2.1
Check the initial MSP value, reset handler, NMI handler, and hard fault handler carefully. Missing, misaligned, or incorrect entries can prevent booting or cause unpredictable behavior. For common single-image firmware, runtime crates such as cortex-m-rt can provide the startup setup; a custom linker script can control memory regions and section placement. section 4.2.4 section 1.3.3
