improve hardfault handler

This commit is contained in:
Kevin Hester 2021-01-16 12:55:51 +08:00
parent d1f0be215b
commit d1be7cf142

View File

@ -16,8 +16,14 @@ static void printUsageErrorMsg(uint32_t cfsr)
cfsr >>= SCB_CFSR_USGFAULTSR_Pos; // right shift to lsb cfsr >>= SCB_CFSR_USGFAULTSR_Pos; // right shift to lsb
if ((cfsr & (1 << 9)) != 0) if ((cfsr & (1 << 9)) != 0)
FAULT_MSG("Divide by zero\n"); FAULT_MSG("Divide by zero\n");
if ((cfsr & (1 << 8)) != 0) else if ((cfsr & (1 << 8)) != 0)
FAULT_MSG("Unaligned\n"); 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) 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"); FAULT_MSG("Done with fault report - Waiting to reboot\n");
asm volatile("bkpt #01"); // Enter the debugger if one is connected 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) extern "C" void HardFault_Handler(void)