Skip to main content
Jim Seymour
Senior
April 15, 2026
Solved

Looking for a sample Hard Fault Handler that can determine the location of the fault

  • April 15, 2026
  • 2 replies
  • 144 views

I have a project that is using custom hardware with a STM32G0B1CBT6 processor.  The code is developed using STM32CubeIDE and STM32CubeMX.  However, there are times when I am unable to run a debug session and I'm seeing (very) occasional Hard Faults.

I have a diagnostic serial port and have successfully modified my Hard Fault Handler to dump additional information out that port.

So what I'm after is some code that can read registers and/or the stack to provide additional information that I can use (along with the map file, etc) to determine where my Hard Fault is happening.

Can anyone point me in the right direction?  All my searches have shown me code that references registers I can't seem to find in the docs.

Thanks.

 

 

2 replies

Andrew Neil
Super User
April 15, 2026

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/708193/highlight/true#M51

 


@Jim Seymour wrote:

All my searches have shown me code that references registers I can't seem to find in the docs.


What registers are those, and what docs are you looking in?

For core registers, you'll need the ARM documentation rather than ST's

Cortex-M0 lacks some of the debug registers of larger cores ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Jim Seymour
Senior
April 15, 2026

I found the article that mƎALLEm linked to below - and got lost when I couldn't find the SHCSR register that it references.  But if it's not in ST's docs, then that explains my confusion.

I'll take a closer look at that article.  It probably has what I need.

Thanks.

 

 

Pavel A.
Super User
April 15, 2026

SCB->SHCSR

The STM32 docs consist of 3 main parts, one of them is Programming Manual (PM) which describes the ARM core of the STM32. There you find these things.

mƎALLEm
mƎALLEmBest answer
Technical Moderator
April 15, 2026
"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."