Skip to main content
ZDjok.1
Associate
December 31, 2019
Question

Stack pointer value at boot time

  • December 31, 2019
  • 6 replies
  • 1741 views

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) ?

This topic has been closed for replies.

6 replies

waclawek.jan
Super User
December 31, 2019

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
ZDjok.1Author
Associate
December 31, 2019

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.

waclawek.jan
Super User
December 31, 2019

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
ZDjok.1Author
Associate
December 31, 2019

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

waclawek.jan
Super User
December 31, 2019

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
Super User
January 1, 2020

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.