Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Set SP and VTOR in Reset vector #338

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ Reset:
ldr r4,=0xffffffff
mov lr,r4

# Some faulty debuggers fake a reset by jumping to the reset vector
# without triggering a system reset, leaving the stack pointer at
# its previous value. To ensure consistency, set MSP ourselves here.
ldr r0,=_stack_start
msr msp,r0

# Some buggy bootloaders do not set VTOR when jumping to application
# code, which leaves a very hard-to-debug issue where everything works
# except your interrupt handlers. We manually set VTOR here to avoid
# this issue. The VTOR register is optional on ARMv6-M, but when not
# present must be RAZ,WI and is therefore safe to write to.
ldr r0,=0xe000ed08
ldr r1,=__vector_table
str r1,[r0]

# Run user pre-init code, which must be executed immediately after startup,
# before the potentially time-consuming memory initialisation takes place.
# Example use cases include disabling default watchdogs or enabling RAM.
Expand Down
Binary file modified bin/thumbv6m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabihf.a
Binary file not shown.
Binary file modified bin/thumbv7m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.base-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabihf.a
Binary file not shown.
1 change: 1 addition & 0 deletions link.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ SECTIONS
{
/* Initial Stack Pointer (SP) value */
LONG(_stack_start);
__vector_table = .;

/* Reset vector */
KEEP(*(.vector_table.reset_vector)); /* this is the `__RESET_VECTOR` symbol */
Expand Down