问题描述
我有一个使用 STM32F103 (ARM Cortex M3) 的嵌入式项目,它在发布模式下偶尔会出现硬故障.作为恢复的一部分,我想从硬故障之前检索 PC 值并将其存储在电池支持区域中以供以后调试.
I have an embedded project using a STM32F103 (ARM Cortex M3), it is getting a occasionally getting hard fault in release mode. As part of recovery, I would like to retrieve the PC value from before the hard fault and store it for later debugging in the battery backed region.
如何确定发生硬故障时程序计数器的值?显然,PC 现在已设置为其在硬故障中断内的位置.
How would I determine the value of the program counter at the point of the hard fault? Obviously, the PC is now set to its location within the hardfault interrupt.
我应该去哪里看?有正常模式寄存器组的地址吗?
Where should I look? It there an address for the normal mode register bank?
谢谢!
推荐答案
Cortex-M3 使用与经典"ARM 完全不同的异常处理模型,例如它没有在另一篇文章中提到的中止模式".我建议你阅读这个应用笔记.例如,对于硬故障:
Cortex-M3 uses a quite different model of exception handling from the "classic" ARM, e.g. it doesn't have "abort mode" mentioned in the other post. I suggest you to read this app note. For example, for the Hard Fault:
SCB->BFAR的值表示导致总线故障的内存地址如果 SCB->CFSR 寄存器中的 BFARVALID 位被置位,则有效.这SCB->MMFAR 的值表示导致内存的内存地址管理故障,如果 SCB->CFSR 中的 MMFARVALID 位有效寄存器已设置.
要确定发生异常时的 PC 值,您需要检查堆栈;处理器在执行处理程序之前推送 R0-R3、R12、PC 和 LR.使用的堆栈可以是 Main(如果 LR 的第 2 位为 0)或 Process(否则).有关详细信息,请参阅应用说明的第 13 页.
To determine the PC value at the time of exception you need to examine the stack; the processor pushes R0-R3, R12, PC and LR before executing the handler. The stack used can be either Main (if bit 2 of LR is 0) or Process (otherwise). See page 13 of the app note for details.
这篇关于ARM Cortex M3 如何在硬故障前确定程序计数器值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!