diff --git a/ion/src/device/device.cpp b/ion/src/device/device.cpp index 4c5d515cd..03804a86b 100644 --- a/ion/src/device/device.cpp +++ b/ion/src/device/device.cpp @@ -14,7 +14,6 @@ extern "C" { #include "swd.h" #include "usb.h" #include "bench/bench.h" -#include "set_msp.h" #define USE_SD_CARD 0 @@ -105,9 +104,18 @@ void coreReset() { void jumpReset() { uint32_t * stackPointerAddress = reinterpret_cast(0x08000000); uint32_t * resetHandlerAddress = reinterpret_cast(0x08000004); - set_msp(*stackPointerAddress); - void (*ResetHandler)(void) = (void (*)())(*resetHandlerAddress); - ResetHandler(); + + /* Jump to the reset service routine after having reset the stack pointer. + * Both addresses are fetched from the base of the Flash memory, just like a + * real reset would. These operations should be made at once, otherwise the C + * compiler might emit some instructions that modify the stack inbetween. */ + + asm volatile ( + "msr MSP, %[stackPointer] ; bx %[resetHandler]" + : : + [stackPointer] "r" (*stackPointerAddress), + [resetHandler] "r" (*resetHandlerAddress) + ); } void init() { diff --git a/ion/src/device/usb/Makefile b/ion/src/device/usb/Makefile index 72e714f72..a26bc2931 100644 --- a/ion/src/device/usb/Makefile +++ b/ion/src/device/usb/Makefile @@ -45,7 +45,6 @@ dfu_objs += ion/src/device/usb/boot.o dfu_objs += ion/src/device/keyboard.o dfu_objs += ion/src/device/device.o dfu_objs += ion/src/device/usb.o -dfu_objs += ion/src/device/set_msp.o ion/src/device/usb/dfu.elf: LDFLAGS = --gc-sections -T ion/src/device/usb/dfu.ld ion/src/device/usb/dfu.elf: $(usb_objs) $(dfu_objs)