Skip to main content
tkjmail2
Associate III
Mar 13, 2010 9:53 PM UTC
Question

Hard Fault error

Posted on March 13, 2010 at 22:53

Hard Fault error

    This topic has been closed for replies.

    15 replies

    tkjmail2
    tkjmail2Author
    Associate III
    May 17, 2011 11:43 AM UTC
    Posted on May 17, 2011 at 13:43

    If I remove the LCD_WriteRAM function call, then the code runs without any hard failured.

    So it has something to do with the LCD_WriteRAM function - but I'm using ST's LCD library??

    Thomas

    sgomes
    Associate II
    May 17, 2011 11:43 AM UTC
    Posted on May 17, 2011 at 13:43

    Add a debug trap as the first thing in your LCD_WriteRAM routine.  Check the passed argument against the bounds.  Output a message over your serial port when it is out of bounds.  If it isn't the argument that is the problem then dig deeper and debug each string or array in the same way.  100% of the hard faults I've had are caused by variables accessing out of bounds.  Looking past the end of a string is easy to do.

    tkjmail2
    tkjmail2Author
    Associate III
    May 17, 2011 11:43 AM UTC
    Posted on May 17, 2011 at 13:43

    No ideas?

    Tesla DeLorean
    Guru
    May 17, 2011 11:43 AM UTC
    Posted on May 17, 2011 at 13:43

    Hi Thomas,

    You'll have to step it along, could be a bug in the library, but much like the old 68K when you touch the wrong memory it faults.

    The Cortex-M3 pushes fault context on to the stack (some 8 dwords as I recall), I think Joseph Yiu has some example of instrumenting this. This could should permit you to determine the faulting PC. With this and the register info, and a map file you should be able to zero in on what is going on.

                    MRS     R0, PSP         ; Read PSP

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

    http://forums.arm.com/lofiversion/index.php?t13632.html

    Boy this forum sucks chunks for finding and citing things. ST *please* get rid of this Microsoft junk?!

    https://my.st.com/public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FARM%20CortexM3%20STM32%2FHardFault%20Exception%20Why%20oh%20why%21

    http://www.google.com/search?hl=en&q=Joseph+Yiu+hard+fault+exception+handler

    -Clive

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    tkjmail2
    tkjmail2Author
    Associate III
    May 17, 2011 11:43 AM UTC
    Posted on May 17, 2011 at 13:43

    Hmm, I've already tried this, not with the serial port though, but with a debugging tool. Then I can just read the counting integer fx.

    But I can't find the thing which makes the hard fault!

    Also, the thing that keeps irretating me is, that the code works on the STM32F103RET6 without any problems, but on the STM32F103ZET6 the hard fault appears!

    Thomas