problem about HardFault_Handler

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem about HardFault_Handler

1,752 Views
_simple_
Contributor III

I use CAN0 recive data, but sometime it will run HardFault_Handler,why?

THANKS!

0 Kudos
6 Replies

1,470 Views
robertboys
Contributor IV

Hello

This might be helpful:   http://www.keil.com/appnotes/files/apnt209.pdf 

Bob

0 Kudos

1,470 Views
_simple_
Contributor III

Thank you!

0 Kudos

1,470 Views
danielmartynek
NXP TechSupport
NXP TechSupport

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

0 Kudos

1,470 Views
_simple_
Contributor III

I add these code into HardFault_Handler,but the translater report follow error:

Multiple markers at this line
- Symbol 'r0' could not be resolved
- 'r0' undeclared (first use in this function)

pastedImage_1.png

0 Kudos

1,470 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Symbols r0, r1 ... are variables and must be declared: uint32_t r0;

Also, the function getStackFrame should have a prototype.

Regards,

Daniel

0 Kudos

1,470 Views
_simple_
Contributor III

thank you!

0 Kudos