cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F373R8 Getting trapped in HardFault_Handler for no reason

alper ozel
Associate II
Posted on February 22, 2018 at 14:22

The original post was too long to process during our migration. Please click on the attachment to read the original post.
5 REPLIES 5
Posted on February 22, 2018 at 14:29

There's usually a reason, it is a gross fault. Look at the CODE that is faulting, not the handler. If you have console output consider implementing a Hard Fault Handler does more than a while() loop.

https://community.st.com/0D50X00009Xke40SAB

Consider if the stack is too small for your auto/local variables, or you run out of heap and don't check if malloc() returns NULL pointers. Look for wayward pointers accessing out of range memory.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 22, 2018 at 14:32

No, you don't get to the Hard Fault handler for no reason - there is always a reason.

And the system provides information to help you locate the reason.

google 'Hard Fault Cortex-M4': it is a standard part of the Cortex-M4 core - not specific to ST

You should also have a copy of this book; it covers the Core features - and includes a section on Hard Fault handling:

https://secure-ecsd.elsevier.com/covers/80/Tango2/large/97801240808jpg

The Definitive Guide to ARM® Cortex®-M3 and Cortex®-M4 Processors,3rd Edition

Author:Joseph Yiu

eBook ISBN:9780124079182

Paperback ISBN:9780124080829

https://www.elsevier.com/books/the-definitive-guide-to-arm-cortex-m3-and-cortex-m4-processors/yiu/978-0-12-408082-9

henry.dick
Senior II
Posted on February 22, 2018 at 14:45

There is always a reason - you just don't know it yet. Step through the code and see when it gets to the fault handler. Usually a peripheral isn't enabled.

Posted on February 22, 2018 at 14:41

And my favorite:

http://www.keil.com/appnotes/files/apnt209.pdf

 
Posted on February 26, 2018 at 14:42

Thanks for your answer Cleve. But, as you can see in the code, there are no variables defined, not even one! I don't think that is about stackoverflow. The code is so simple that I can't think of anything other than a bug causing this. Are there any possible reason for Hard Fault you know?