ARM Cortex M3如何在硬故障之前确定程序计数器值? [英] ARM Cortex M3 How do I determine the program counter value before a hard fault?

查看:387
本文介绍了ARM Cortex M3如何在硬故障之前确定程序计数器值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用STM32F103(ARM Cortex M3)的嵌入式项目,在发布模式下偶尔会出现硬故障。作为恢复的一部分,我想从硬故障之前检索PC值,并将其存储在电池供电区域的以后调试中。



我如何确定程序计数器在硬故障点的值?显然,PC现在被设置在硬突破中断的位置。



我应该在哪里看?那里有正常模式寄存器银行的地址?



谢谢!

解决方案

Cortex-M3使用与经典ARM类似的异常处理模式,例如在其他帖子中没有提及中止模式。我建议您阅读此应用笔记。例如,对于硬故障:


SCB-> BFAR的值表示导致总线故障的内存地址
并且如果SCB-> CFSR寄存器中的位BFARVALID置1,则有效。 SCB-> MMFAR的
值表示导致内存
管理故障的内存地址,如果SCB-> CFSR
寄存器中的MMFARVALID位置1,则该值有效。


要确定异常时的PC值,需要检查堆栈;在执行处理程序之前,处理器推送R0-R3,R12,PC和LR。所使用的堆栈可以是主(如果LR的位2为0)或过程(否则)。有关详细信息,请参阅应用笔记的第13页。


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.

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?

Thanks!

解决方案

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:

The value of SCB->BFAR indicates the memory address that caused a Bus Fault and is valid if the bit BFARVALID in the SCB->CFSR register is set. The value of SCB->MMFAR indicates the memory address that caused a Memory Management Fault and is valid if the bit MMFARVALID in the SCB->CFSR register is set.

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如何在硬故障之前确定程序计数器值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆