转载自:http://www.openedv.com/posts/list/25030.htm

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

先将fault中断函数的内容改为:
HardFault_Handler\
PROC
;EXPORT HardFault_Handler [WEAK]
;B .
IMPORT hard_fault_handler_c
TST LR, #
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[]);
stacked_r1 = ((unsigned long) hardfault_args[]);
stacked_r2 = ((unsigned long) hardfault_args[]);
stacked_r3 = ((unsigned long) hardfault_args[]); stacked_r12 = ((unsigned long) hardfault_args[]);
stacked_lr = ((unsigned long) hardfault_args[]);
stacked_pc = ((unsigned long) hardfault_args[]);
stacked_psr = ((unsigned long) hardfault_args[]); 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()
{
;;
}
}
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[]);
stacked_r1 = ((unsigned long) hardfault_args[]);
stacked_r2 = ((unsigned long) hardfault_args[]);
stacked_r3 = ((unsigned long) hardfault_args[]); stacked_r12 = ((unsigned long) hardfault_args[]);
stacked_lr = ((unsigned long) hardfault_args[]);
stacked_pc = ((unsigned long) hardfault_args[]);
stacked_psr = ((unsigned long) hardfault_args[]); 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()
{
;;
}

如果使用调试器,则可以在第一个printf处设置断点。

没有的话看串口打印结果通过查看stacked_lr的内容可以知道程序运行到哪个位置出现fault,然后查看编译后汇编代码,可以知道源程序是哪个函数哪一步出现问题,配合其它寄存器的内容来分析找出原因。

转载:定位ARM Hard Fault 的方法的更多相关文章

  1. Cortex-M3/4的Hard Fault调试方法

    1 Cortex-M3/4的Fault简介 Cortex-M3/4的Fault异常是由于非法的存储器访问(比如访问0地址.写只读存储位置等)和非法的程序行为(比如除以0等)等造成的.常见的4种异常及产 ...

  2. ADF控件ID变化引发JS无法定位控件的解决方法

    原文地址:ADF控件ID变化引发JS无法定位控件的解决方法作者:Nicholas JSFF定义的控件ID到了客户端时往往会改变.例如在JSFF中的一个的ID为"ot1",但是当这个 ...

  3. 【转载】 C#中使用Sum方法对List集合进行求和操作

    在C#的List操作中,有时候我们需要对List集合对象的某个属性进行求和操作,此时可以使用Lambda表达式中的Sum方法来快速实现此求和操作,使用Sum方法可使代码简洁易读,并且省去写for循环或 ...

  4. 【转载】 C#中使用Count方法获取List集合中符合条件的个数

    很多时候操作List集合的过程中,我们需要根据特定的查询条件,获取List集合中有多少个实体对象符合查询条件,例如一批产品的对象List集合,如果这批产品的不合格数量大于10则重点备注.在C#中可以自 ...

  5. ARM LDR伪指令使用方法具体解释

    LDR伪指令 10.45 LDR pseudo-instruction   功能:把一个32位马上数或一个32位的内存地址载入到一个寄存器中. 注意:这里描写叙述的是LDR伪指令,而不是LDR指令   ...

  6. GDB调试之core文件(如何定位到Segment fault)

    core dump又叫核心转储,当程序运行过程中发生异常,程序异常退出时,由操作系统把程序当前的内存状况存储在一个core文件中,叫core dump.(内部实现是:linux系统中内存越界会收到SI ...

  7. (转载)SQL删除重复数据方法

    本文转载自http://www.cnblogs.com/sunxiaonan/archive/2009/11/24/1609439.html 例如: id           name         ...

  8. 【转载】Pyqt 添加右键菜单方法

    转载地址: http://www.cnblogs.com/yogalau/p/3954042.html?utm_source=tuicool QListWidget 是继承 QWidget 的, 所以 ...

  9. UIAutomator定位Android控件的方法

    UIAutomator各种控件定位的方法. 1. 背景 使用SDK自带的NotePad应用,尝试去获得在NotesList那个Activity里的Menu Options上面的那个Add note菜单 ...

随机推荐

  1. angular开发中对请求数据层的封装

    代码地址如下:http://www.demodashi.com/demo/11481.html 一.本章节仅仅是对angular4项目开发中数据请求封装到model中 仅仅是在项目angular4项目 ...

  2. ThreadLocal源码

    /* * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETA ...

  3. easy ui datagrid 数据分页

    参照easyui官方网站提供的demo写了个datagrid数据分页的demo, 具体参数我就不一一罗列了,详细见官方网站, 这里只介绍一下具体的注意事项和常乃用到的几项, $('#test').da ...

  4. PayPal 对接

    时间:2019-1-29 15:39:39 文章相应链接: 官方SDK:https://developer.paypal.com/docs/api/rest-sdks/ 官方API:https://d ...

  5. “ResGen.exe”已退出,代码为2 问题处理

    这属于VS2010不能编译.Net3.5的问题 用VS2010创建了一个.Net 3.5的Winform项目,结果编译失败,这个问题也算是第二次碰到了,真纠结···这次不再偷懒了,把解决方法记录下来吧 ...

  6. docker容器互连

    三种方式 1.使用容器连接的示例如下: $ docker run --name some-app --link itbilu-mysql:mysql -d application-that-uses- ...

  7. Scroller应用:ListView滑动删除

    1.设计思路 在Scroller的应用--滑屏实现中使用Scroller实现滑屏效果,这里使用Scroller与ListView实现相似QQ滑动.然后点击删除功能.设计思路是Item使用Scrolle ...

  8. 总结文件操作函数(一)-C语言

    在进程一開始执行,就自己主动打开了三个相应设备的文件.它们是标准输入.输出.错误流.分别用全局文件指针stdin.stdout.stderr表示,相应的文件描写叙述符为0.1.2:stdin具有可读属 ...

  9. unity, 在surface shader中访问顶点色

    //ref: Custom data computed per-vertex: http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html ...

  10. 【LeetCode】Sort Colors 解题报告

    [题目] Given an array with n objects colored red, white or blue, sort them so that objects of the same ...