cancel
Showing results for 
Search instead for 
Did you mean: 

Stack pointer value at boot time

ZDjok.1
Associate II

I was not involved in ST MCUs (STM32F769 specifically) until now. I understood that CPU gets stack pointer at start, from address 0, but what there exists is RAM - which is undefined after power up. Then, how can I force some "reasonable" SP value in custom bootloader (eg. from ITCM RAM) ?

6 REPLIES 6

The initial value for SP in vector table goes hand-in-hand with the first address which is executed, so by ensuring there's sane code to be executed from start, you also ensure that there's a sane value for SP.

> I understood that CPU gets stack pointer at start, from address 0,

This is not the case with the 'F76x, read Boot configuration chapter in RM0410.

> but what there exists is RAM - which is undefined after power up

The default setting of BOOT_ADDx point to either FLASH or the system memory (ROM with the factory bootloader). While you can change to point it to RAM, it's anticipated you'll do it only if *you* make sure the RAM's content is always well-defined, eg. in an always-powered (by battery) system.

JW

ZDjok.1
Associate II

I've already red chapter you've mentioned, few times, but noticed nothing of stack pointer start value (in RM0410). Unless it's implied that is expected to be at the beginning of boot region. Or am I missed something.

Well, it's not explicitly said there, that's true, but I'd expect the boot address to point at the vector table, which contains the stack pointer start value.

JW

ZDjok.1
Associate II

Seems so, although for newbies in ST world (like myself) it would be beneficial to emphasize such conclusion/statement.

The documentation leaves a lot to be desired.

You are supposed to click in CubeMX instead of asking questions on technical details.

Welcome to 21th century 😉

JW

KnarfB
Principal III

The stack is usuallly defined in the linker description (.ld) file. The STM generated startup code overwrites the hardware fetched SP at the very beginning of the ResetHandler.