problem about HardFault_Handler

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

problem about HardFault_Handler

2,298 次查看
_simple_
Contributor III

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

THANKS!

0 项奖励
回复
6 回复数

2,016 次查看
robertboys
Contributor IV

Hello

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

Bob

0 项奖励
回复

2,016 次查看
_simple_
Contributor III

Thank you!

0 项奖励
回复

2,016 次查看
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 项奖励
回复

2,016 次查看
_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 项奖励
回复

2,016 次查看
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 项奖励
回复

2,016 次查看
_simple_
Contributor III

thank you!

0 项奖励
回复