From d1be7cf14215adfd245c792c1782d1e12a596d99 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 12:55:51 +0800 Subject: [PATCH] improve hardfault handler --- src/nrf52/hardfault.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/nrf52/hardfault.cpp b/src/nrf52/hardfault.cpp index 67180c833..c1a82d6ae 100644 --- a/src/nrf52/hardfault.cpp +++ b/src/nrf52/hardfault.cpp @@ -16,8 +16,14 @@ static void printUsageErrorMsg(uint32_t cfsr) cfsr >>= SCB_CFSR_USGFAULTSR_Pos; // right shift to lsb if ((cfsr & (1 << 9)) != 0) FAULT_MSG("Divide by zero\n"); - if ((cfsr & (1 << 8)) != 0) + else if ((cfsr & (1 << 8)) != 0) FAULT_MSG("Unaligned\n"); + else if ((cfsr & (1 << 1)) != 0) + FAULT_MSG("Invalid state\n"); + else if ((cfsr & (1 << 0)) != 0) + FAULT_MSG("Invalid instruction\n"); + else + FAULT_MSG("FIXME add to printUsageErrorMsg!\n"); } static void printBusErrorMsg(uint32_t cfsr) @@ -71,8 +77,9 @@ extern "C" void HardFault_Impl(uint32_t stack[]) FAULT_MSG("Done with fault report - Waiting to reboot\n"); asm volatile("bkpt #01"); // Enter the debugger if one is connected - while (1) - ; + + // Don't spin, so that the debugger will let the user step to next instruction + // while (1) ; } extern "C" void HardFault_Handler(void)