Skip to content

Commit 75968ed

Browse files
committed
platforms/syscalls: Implement Cortex-M exception handlers with morse
1 parent 86704be commit 75968ed

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
@@ -137,3 +137,63 @@ __attribute__((weak)) void __aeabi_unwind_cpp_pr1()
137137
__attribute__((weak)) void __aeabi_unwind_cpp_pr2()
138138
{
139139
}
140+
141+
#include "morse.h"
142+
#include <libopencm3/cm3/nvic.h>
143+
#include <libopencm3/cm3/scb.h>
144+
#include <libopencm3/cm3/systick.h>
145+
146+
static void systick_spinner(void)
147+
{
148+
uint32_t time_ms_reset = platform_time_ms() + 10000U;
149+
while (platform_time_ms() < time_ms_reset) {
150+
if (systick_get_countflag())
151+
sys_tick_handler();
152+
}
153+
}
154+
155+
void hard_fault_handler(void)
156+
{
157+
morse("HF", true);
158+
#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
159+
volatile uint32_t hfsr = SCB_HFSR;
160+
if (hfsr & SCB_HFSR_FORCED)
161+
morse("HF FORCED", true);
162+
#endif
163+
164+
systick_spinner();
165+
scb_reset_system();
166+
}
167+
168+
#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
169+
170+
void mem_manage_handler(void)
171+
{
172+
morse("MPU", true);
173+
volatile uint32_t mmfar = SCB_MMFAR;
174+
(void)mmfar;
175+
176+
systick_spinner();
177+
scb_reset_system();
178+
}
179+
180+
void bus_fault_handler(void)
181+
{
182+
morse("BUS", true);
183+
volatile uint32_t bfar = SCB_BFAR;
184+
(void)bfar;
185+
186+
systick_spinner();
187+
scb_reset_system();
188+
}
189+
190+
void usage_fault_handler(void)
191+
{
192+
morse("USAGE", true);
193+
volatile uint32_t cfsr = SCB_CFSR;
194+
(void)cfsr;
195+
196+
systick_spinner();
197+
scb_reset_system();
198+
}
199+
#endif

0 commit comments

Comments
 (0)