Skip to content

Commit 1e868ae

Browse files
committed
platforms/syscalls: Implement Cortex-M exception handlers with morse
1 parent 85b4110 commit 1e868ae

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/platforms/common/syscalls.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,63 @@ __attribute__((weak)) void __aeabi_unwind_cpp_pr1()
199199
__attribute__((weak)) void __aeabi_unwind_cpp_pr2()
200200
{
201201
}
202+
203+
#include "morse.h"
204+
#include <libopencm3/cm3/nvic.h>
205+
#include <libopencm3/cm3/scb.h>
206+
#include <libopencm3/cm3/systick.h>
207+
208+
static void systick_spinner(void)
209+
{
210+
uint32_t time_ms_reset = platform_time_ms() + 10000U;
211+
while (time_ms_reset < platform_time_ms()) {
212+
if (systick_get_countflag())
213+
sys_tick_handler();
214+
}
215+
}
216+
217+
void hard_fault_handler(void)
218+
{
219+
morse("HF", true);
220+
#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
221+
volatile uint32_t hfsr = SCB_HFSR;
222+
if (hfsr & SCB_HFSR_FORCED)
223+
morse("HF FORCED", true);
224+
#endif
225+
226+
systick_spinner();
227+
scb_reset_system();
228+
}
229+
230+
#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
231+
232+
void mem_manage_handler(void)
233+
{
234+
morse("MPU", true);
235+
volatile uint32_t mmfar = SCB_MMFAR;
236+
(void)mmfar;
237+
238+
systick_spinner();
239+
scb_reset_system();
240+
}
241+
242+
void bus_fault_handler(void)
243+
{
244+
morse("BUS", true);
245+
volatile uint32_t bfar = SCB_BFAR;
246+
(void)bfar;
247+
248+
systick_spinner();
249+
scb_reset_system();
250+
}
251+
252+
void usage_fault_handler(void)
253+
{
254+
morse("USAGE", true);
255+
volatile uint32_t cfsr = SCB_CFSR;
256+
(void)cfsr;
257+
258+
systick_spinner();
259+
scb_reset_system();
260+
}
261+
#endif

0 commit comments

Comments
 (0)