2018-02-22 05:22 AM
2018-02-22 05:29 AM
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.
2018-02-22 05:32 AM
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 EditionAuthor:Joseph Yiu
eBook ISBN:9780124079182
Paperback ISBN:9780124080829
2018-02-22 05:45 AM
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.
2018-02-22 06:41 AM
And my favorite:
2018-02-26 06:42 AM
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?