|
158 | 158 | //! conjunction with crates generated using `svd2rust`. Those *device crates* will populate the
|
159 | 159 | //! missing part of the vector table when their `"rt"` feature is enabled.
|
160 | 160 | //!
|
| 161 | +//! ## `set-sp` |
| 162 | +//! |
| 163 | +//! If this feature is enabled, the stack pointer (SP) is initialised in the reset handler to the |
| 164 | +//! `_stack_start` value from the linker script. This is not usually required, but some debuggers |
| 165 | +//! do not initialise SP when performing a soft reset, which can lead to stack corruption. |
| 166 | +//! |
| 167 | +//! ## `set-vtor` |
| 168 | +//! |
| 169 | +//! If this feature is enabled, the vector table offset register (VTOR) is initialised in the reset |
| 170 | +//! handler to the start of the vector table defined in the linker script. This is not usually |
| 171 | +//! required, but some bootloaders do not set VTOR before jumping to application code, leading to |
| 172 | +//! your main function executing but interrupt handlers not being used. |
| 173 | +//! |
161 | 174 | //! # Inspection
|
162 | 175 | //!
|
163 | 176 | //! This section covers how to inspect a binary that builds on top of `cortex-m-rt`.
|
@@ -498,6 +511,23 @@ cfg_global_asm! {
|
498 | 511 | mvns r4, r4
|
499 | 512 | mov lr, r4",
|
500 | 513 |
|
| 514 | + // If enabled, initialise the SP. This is normally initialised by the CPU itself or by a |
| 515 | + // bootloader, but some debuggers fail to set it when resetting the target, leading to |
| 516 | + // stack corruptions. |
| 517 | + #[cfg(feature = "set-sp")] |
| 518 | + "ldr r0, =_stack_start |
| 519 | + msr msp, r0", |
| 520 | + |
| 521 | + // If enabled, initialise VTOR to the start of the vector table. This is normally initialised |
| 522 | + // by a bootloader when the non-reset value is required, but some bootloaders do not set it, |
| 523 | + // leading to frustrating issues where everything seems to work but interrupts are never |
| 524 | + // handled. The VTOR register is optional on ARMv6-M, but when not present is RAZ,WI and |
| 525 | + // therefore safe to write to. |
| 526 | + #[cfg(feature = "set-vtor")] |
| 527 | + "ldr r0, =0xe000ed08 |
| 528 | + ldr r1, =__vector_table |
| 529 | + str r1, [r0]", |
| 530 | + |
501 | 531 | // Run user pre-init code which must be executed immediately after startup, before the
|
502 | 532 | // potentially time-consuming memory initialisation takes place.
|
503 | 533 | // Example use cases include disabling default watchdogs or enabling RAM.
|
|
0 commit comments