mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 17:50:04 +01:00
[usb] Implement jumpReset in assembly.
This avoids unwanted stack modifications emited by the compiler. Change-Id: I2a2a13ee5395b95ed676f6634be86eeb148d55fd
This commit is contained in:
@@ -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<uint32_t *>(0x08000000);
|
||||
uint32_t * resetHandlerAddress = reinterpret_cast<uint32_t *>(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() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user