当前位置:   article > 正文

HardFault_Handler故障原因排查_hardfault_handler 原因查找

hardfault_handler 原因查找

出现HardFault_Handler故障的原因有两个方面: 内存溢出或者堆栈溢出
在这里插入图片描述
首先需要找到出现故障的地方
1.在main.c下自定义hard_fault_handler_c函数

void hard_fault_handler_c(uint32_t* hardfault_args)
{
    static unsigned int stacked_lr;
    static unsigned int stacked_pc;
    stacked_lr = ((unsigned long) hardfault_args[5]);
    stacked_pc = ((unsigned long) hardfault_args[6]);
    __breakpoint(0);
    while(1);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2.把原先HardFault_Handler注释 重新定义
在这里插入图片描述

HardFault_Handler\
                PROC
                IMPORT hard_fault_handler_c
                TST LR, #4
                ITE EQ
                MRSEQ R0,   MSP
                MRSNE R0,   PSP
                B   hard_fault_handler_c
                ENDP
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  1. 修改后 下次故障就会出现在定义的函数中
  2. 在这里插入图片描述
    4.定位故障处
    在Debug状态下 在Disassembly窗口里右键选择Show Diassembly at Address
    在这里插入图片描述
    输入stacked_lr,stacked_pc存下的变量地址去定位到故障处
    在这里插入图片描述
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/50603
推荐阅读
相关标签
  

闽ICP备14008679号