William Chang

Find Out the Fault Casue (using SP)

Blog Post created by William Chang on May 13, 2018

How to find out which instruction cause the MCU run into crash?

> Can we find out? In the case, such as the SP are not broken by the fault. We can use the stack pointer to find out the fault instruction.


Let's do some experiment.

//do not enable usage fault


1. First make a fault in the program.

  • DIVBYZERO: divide by zero

when the program execute the 1/0, fault is trapped by exception.

we are in the while loop.

let's check the registers

As long as the SP is fine, we can get the data ( PC, LR ) we want before the exception happens.

So what is LR (0X800061F) and PC (0X80001BE)

LR is the next instruction address of the parent of the subroutine.

PC is the value stored in PC before entering the fault. yes, it was the instruction address that cause the fault.

Let's find them out.

Here is LR (The last bit should always be 1 that indicates using thumb instruction set)

(??but I don't know why value of PC is not 0x80001BF)


Here is PC, the answer we want!

We finally find the address of the cause of fault out.