This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Cortex-M3: Tips/Tricks to debug a Hard Fault?

Any hints, tips or tricks to debug a Cortex-M3: Hard Fault Exception?

It's an STM32, and I'm using the standard Keil STM32F10x.s: Startup file - which contains Dummy Exception Handlers (infinite loops) to "catch" the exception.

So, ahving arrived in the Hard Fault Exception Handler, what should I do next...?

  • I don't seem to be able to find it right now, but there is a very good article - also having been referenced from this forum at an earlier time - that describes this situation, i.e. how to look at the processor registers to figure out the memory address the processor came from when it hit the exception.

    You may possibly manage to find the link - directly on Google or the reference on this forum - or I may possibly have it linked in a browser at work.

    Another alternative is to fight through the ARM manuals for the description of the register contents after an exception.

  • "how to look at the processor registers to figure out the memory address the processor came from when it hit the exception."

    Yes, that's the kind of thing I was after, although the uVision debugger does actually show the "call tree" - so I was wondering about further info that might help determine the precise cause...

    "a very good article - also having been referenced from this forum"

    I had searched on "Hard Fault" and not come up with anything...

    :-(

  • The Cortex-M pushes 8 registers on the stack on Hard Fault exception. Here is a code to read the memory address that caused it:

    MRS     R0,PSP                  ; Read PSP
    LDR     R1,[R0,#24]             ; Read Saved PC from Stack