Skip to main content
alper ozel
Associate II
February 22, 2018
Question

STM32F373R8 Getting trapped in HardFault_Handler for no reason

  • February 22, 2018
  • 5 replies
  • 1369 views
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.
    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    February 22, 2018
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    alper ozel
    Associate II
    February 26, 2018
    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?

    Andrew Neil
    Super User
    February 22, 2018
    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

    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.
    Bogdan Golab
    Lead
    February 22, 2018
    Posted on February 22, 2018 at 14:41

    And my favorite:

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

     
    henry.dick
    Associate II
    February 22, 2018
    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.