problem about HardFault_Handler

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

problem about HardFault_Handler

2,305件の閲覧回数
_simple_
Contributor III

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

THANKS!

0 件の賞賛
返信
6 返答(返信)

2,023件の閲覧回数
robertboys
Contributor IV

Hello

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

Bob

0 件の賞賛
返信

2,023件の閲覧回数
_simple_
Contributor III

Thank you!

0 件の賞賛
返信

2,023件の閲覧回数
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,023件の閲覧回数
_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,023件の閲覧回数
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,023件の閲覧回数
_simple_
Contributor III

thank you!

0 件の賞賛
返信