Hi,
You can check S32_SCB->CFSR register to see what type of exception it is.
Detailed description of this register can be found in Cortex-M4 Devices Generic User Guide (chapter 4.3.10).
Also, you can extend the HardFault_Handler function to get stack frame.
Program counter (pc) holds address of the instruction that has caused the exception.
void HardFault_Handler(void)
{
// LR provides information of the return stack PSP/MSP
asm("MOVS R0, #4");
asm("MOV R1, LR");
asm("TST R0, R1");
asm("BEQ _MSP");
asm("MRS R0, PSP");
asm("B getStackFrame");
asm("_MSP:");
asm("MRS R0, MSP");
asm("B getStackFrame");
}
void getStackFrame(uint32_t *stackFrame)
{
r0 = stackFrame[0];
r1 = stackFrame[1];
r2 = stackFrame[2];
r3 = stackFrame[3];
r12 = stackFrame[4];
lr = stackFrame[5];
pc = stackFrame[6];
psr = stackFrame[7];
asm("BKPT");
}
Regards,
Daniel
Hi,
Symbols r0, r1 ... are variables and must be declared: uint32_t r0;
Also, the function getStackFrame should have a prototype.
Regards,
Daniel