在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 5401|回复: 0

[资料] 定位ARM Hard Fault 的方法

[复制链接]
发表于 2012-10-23 23:11:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
1,
Keil的话,可以做如下操作:

先将fault中断函数的内容改为:




HardFault_Handler\


PROC



;EXPORT
HardFault_Handler
[WEAK]



;B
.



IMPORT hard_fault_handler_c



TST LR, #4



ITE EQ



MRSEQ R0, MSP



MRSNE R0, PSP



B hard_fault_handler_c




ENDP








然后在源程序里添加下面的函数代码:

// hard fault handler in C,


// with stack frame location as input parameter


void hard_fault_handler_c(unsigned int * hardfault_args)


{


unsigned int stacked_r0;


unsigned int stacked_r1;


unsigned int stacked_r2;


unsigned int stacked_r3;


unsigned int stacked_r12;


unsigned int stacked_lr;


unsigned int stacked_pc;


unsigned int stacked_psr;





stacked_r0 = ((unsigned long) hardfault_args[0]);


stacked_r1 = ((unsigned long) hardfault_args[1]);


stacked_r2 = ((unsigned long) hardfault_args[2]);


stacked_r3 = ((unsigned long) hardfault_args[3]);





stacked_r12 = ((unsigned long) hardfault_args[4]);


stacked_lr = ((unsigned long) hardfault_args[5]);


stacked_pc = ((unsigned long) hardfault_args[6]);


stacked_psr = ((unsigned long) hardfault_args[7]);





printf ("[Hard fault handler]\n");


printf ("R0 = %x\n", stacked_r0);


printf ("R1 = %x\n", stacked_r1);


printf ("R2 = %x\n", stacked_r2);


printf ("R3 = %x\n", stacked_r3);


printf ("R12 = %x\n", stacked_r12);


printf ("LR = %x\n", stacked_lr);


printf ("PC = %x\n", stacked_pc);


printf ("PSR = %x\n", stacked_psr);


printf ("BFAR = %x\n", (*((volatile unsigned long *)(0xE000ED38))));


printf ("CFSR = %x\n", (*((volatile unsigned long *)(0xE000ED28))));


printf ("HFSR = %x\n", (*((volatile unsigned long *)(0xE000ED2C))));


printf ("DFSR = %x\n", (*((volatile unsigned long *)(0xE000ED30))));


printf ("AFSR = %x\n", (*((volatile unsigned long *)(0xE000ED3C))));








while(1)

{


;;


}




}





如果使用调试器,则可以在第一个printf处设置断点.没有的话看串口打印结果


通过查看stacked_lr的内容可以知道程序运行到哪个位置出现fault

然后查看编译后汇编代码,可以知道源程序是哪个函数哪一步出现问题,

配合其它寄存器的内容来分析找出原因







2
IAR的话,
startup_ewarm.c文件中的FaultISR()函数的内容改为:

volatile unsigned int stacked_r0;


volatile unsigned int stacked_r1;


volatile unsigned int stacked_r2;


volatile unsigned int stacked_r3;


volatile unsigned int stacked_r12;


volatile unsigned int stacked_lr;


volatile unsigned int stacked_pc;


volatile unsigned int stacked_psr;





//unsigned long cc;




stacked_r0 = ((unsigned long) hardfault_args[0]);


stacked_r1 = ((unsigned long) hardfault_args[1]);


stacked_r2 = ((unsigned long) hardfault_args[2]);


stacked_r3 = ((unsigned long) hardfault_args[3]);





stacked_r12 = ((unsigned long) hardfault_args[4]);


stacked_lr = ((unsigned long) hardfault_args[5]);


stacked_pc = ((unsigned long) hardfault_args[6]);


stacked_psr = ((unsigned long) hardfault_args[7]);











printf ("[Hard fault handler]\n");


printf ("R0 = %x\n", stacked_r0);


printf ("R1 = %x\n", stacked_r1);


printf ("R2 = %x\n", stacked_r2);


printf ("R3 = %x\n", stacked_r3);


printf ("R12 = %x\n", stacked_r12);


printf ("LR = %x\n", stacked_lr);


printf ("PC = %x\n", stacked_pc);


printf ("PSR = %x\n", stacked_psr);


printf ("BFAR = %x\n", (*((volatile unsigned long *)(0xE000ED38))));


printf ("CFSR = %x\n", (*((volatile unsigned long *)(0xE000ED28))));


printf ("HFSR = %x\n", (*((volatile unsigned long *)(0xE000ED2C))));


printf ("DFSR = %x\n", (*((volatile unsigned long *)(0xE000ED30))));


printf ("AFSR = %x\n", (*((volatile unsigned long *)(0xE000ED3C))));









while(1)



{



;;



}


如果使用调试器,则可以在第一个printf处设置断点.没有的话看串口打印结果


通过查看stacked_lr的内容可以知道程序运行到哪个位置出现fault

然后查看编译后汇编代码,可以知道源程序是哪个函数哪一步出现问题,

配合其它寄存器的内容来分析找出原因

搜索更多相关主题的帖子: 定位

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-16 05:40 , Processed in 0.021768 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表