Skip to content

Commit

Permalink
platforms/syscalls: Implement Cortex-M exception handlers with morse
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Oct 26, 2024
1 parent 85b4110 commit 1e868ae
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/platforms/common/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,63 @@ __attribute__((weak)) void __aeabi_unwind_cpp_pr1()
__attribute__((weak)) void __aeabi_unwind_cpp_pr2()
{
}

#include "morse.h"
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/scb.h>
#include <libopencm3/cm3/systick.h>

static void systick_spinner(void)
{
uint32_t time_ms_reset = platform_time_ms() + 10000U;
while (time_ms_reset < platform_time_ms()) {
if (systick_get_countflag())
sys_tick_handler();
}
}

void hard_fault_handler(void)
{
morse("HF", true);
#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
volatile uint32_t hfsr = SCB_HFSR;
if (hfsr & SCB_HFSR_FORCED)
morse("HF FORCED", true);
#endif

systick_spinner();
scb_reset_system();
}

#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)

void mem_manage_handler(void)
{
morse("MPU", true);
volatile uint32_t mmfar = SCB_MMFAR;
(void)mmfar;

systick_spinner();
scb_reset_system();
}

void bus_fault_handler(void)
{
morse("BUS", true);
volatile uint32_t bfar = SCB_BFAR;
(void)bfar;

systick_spinner();
scb_reset_system();
}

void usage_fault_handler(void)
{
morse("USAGE", true);
volatile uint32_t cfsr = SCB_CFSR;
(void)cfsr;

systick_spinner();
scb_reset_system();
}
#endif

0 comments on commit 1e868ae

Please sign in to comment.