[ion] Add the ability to perform a jump-reset

This commit is contained in:
Romain Goyet
2018-04-04 10:20:36 +02:00
parent 9cadc49264
commit 5c86a07481
5 changed files with 40 additions and 2 deletions

View File

@@ -34,7 +34,7 @@ const char * patchLevel();
const char * fccId();
/* CAUTION: This is a complete reset! */
void reset();
void reset(bool jump = false);
// CRC32 : non xor-ed, non reversed, direct, polynomial 4C11DB7
// Only accepts whole 32bit values

View File

@@ -23,6 +23,7 @@ objs += $(addprefix ion/src/device/, \
led.o\
power.o\
sd_card.o\
set_msp.o \
swd.o \
usb.o \
wakeup.o \

View File

@@ -14,6 +14,7 @@ extern "C" {
#include "swd.h"
#include "usb.h"
#include "bench/bench.h"
#include "set_msp.h"
#define USE_SD_CARD 0
@@ -65,10 +66,28 @@ uint32_t Ion::random() {
return result;
}
void Ion::reset() {
static void coreReset() {
// Perform a full core reset
CM4.AIRCR()->requestReset();
}
static void jumpReset() {
Ion::Device::shutdown();
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();
}
void Ion::reset(bool jump) {
if (jump) {
jumpReset();
} else {
coreReset();
}
}
static inline char hex(uint8_t d) {
if (d > 9) {
return 'A'+d-10;

8
ion/src/device/set_msp.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef ION_DEVICE_SETMSP_H
#define ION_DEVICE_SETMSP_H
#include <stdint.h>
extern "C" void set_msp(uint32_t address);
#endif

10
ion/src/device/set_msp.s Normal file
View File

@@ -0,0 +1,10 @@
.syntax unified
.section .text
.align 2
.thumb
.global set_msp
set_msp:
msr msp, r0
bx lr
.type set_msp, function