公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

XMC实验分享之四十八: Cortex M0的Hard Fault发生原因

XMC实验分享之四十八: Cortex M0的Hard Fault发生原因

User12775
Level 5
Level 5
First solution authored First like received

凡是在Cortex M系列内核上写过程序的程序员, 没有不知道Hard Fault的. 大多数程序出现问题的表现就是进入Hard Fault.

但是进入Hard Fault的原因是甚么, 为了查明这个问题, 不少程序员为之废寝忘食...


Hard Fault的设计初衷就是为了程序出错之后提供一个预警机制, 但是进入Hard Fault的原因有很多. 所以把这个问题研究透对调试排错意义很大.


相比于其他型号, Cortex M0只有一种Fault就是Hard Fault. 本帖以几个实验稍稍探究一下子发生Fault的原因.


首先看手册, Cortex M0发生Hard Fault的原因有如下几种:

Faults are a subset of exceptions, see Exception model on page 2-19. All faults result in
the HardFault exception being taken or cause lockup if they occur in the NMI or
HardFault handler. The faults are:
? execution of an SVC instruction at a priority equal or higher than SVCall
? execution of a BKPT instruction without a debugger attached
? a system-generated bus error on a load or store
? execution of an instruction from an XN memory address
? execution of an instruction from a location for which the system generates a bus fault
? a system-generated bus error on a vector fetch
? execution of an Undefined instruction
? execution of an instruction when not in Thumb-State as a result of the T-bit being previously cleared to 0
? an attempted load or store to an unaligned address.


0 点赞
3352 次查看
13 评论