From 89ebe6413ef88398b54d956448e5762506f6f44f Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 1 Sep 2020 20:13:38 -0400 Subject: [PATCH] recover from custom code faults --- source/main.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source/main.cpp b/source/main.cpp index 4bdd5a2..596991d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -160,3 +160,28 @@ void port_syscall(struct port_extctx *ctxp, uint32_t n) chSysHalt("svc"); } +void conversion_abort() +{ + elf_entry = nullptr; + dac::write_stop(); + adc::read_stop(); + signal_operate_done = true; +} + +extern "C" { + +__attribute__((naked)) +void HardFault_Handler() +{ + uint32_t *stack; + asm("mrs %0, msp" : "=r" (stack)); + stack[6] = stack[5]; + stack[7] |= (1 << 24); + + asm("push {lr}"); + conversion_abort(); + asm("pop {lr}; bx lr"); +} + +} // extern "C" +