cancel
Showing results for 
Search instead for 
Did you mean: 

Hard fault with no obvious reason why

shotaro
Associate II
Posted on August 03, 2011 at 18:50

I'm running into a hard fault situation and I'm not sure why this is happening.

From what I'm seeing in the fault status registers I'm getting...

Usage fault status: INVSTATE is set

Hard fault status : FORCED is set

Debug fault status: EXTERNAL and VCATCH are set

At the time of the fault, the only register that looks odd is my link register (0xFFFFFFF9).

This happens in my code when after I'm sending off some bytes over a USART, if that helps anything.

If it helps too, my memory consumption is 22.7KB/23.0KB FLASH and 2.5/10KB for SRAM. Target is STM32F103R6H6. If you're wondering about the FLASH size, I'm using a custom memory map.

EDIT:

This is a snippet of the disassembly that right after executing the last line, the MCU goes to a hard fault state:

    F1070708    add.w r7, r7, #8

    46BD        mov sp, r7

    BD80        pop {r7, pc}

r7 before the first line of code is executed is 0x20000754

2 REPLIES 2
Posted on August 03, 2011 at 19:22

The value in LR is a magic value to return from the fault handler. The real value of LR and other registers are on the stack.

With a decent Hard Fault Handler you could decode the faulting PC, and register states. Google ''Joseph Yiu Hard Fault Handler''

Now odd are that you are corrupting the stack frame, and then popping an illegal value for PC. If PC is an even address it will fault on a Cortex-M3 which can't run ARM instructions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shotaro
Associate II
Posted on August 04, 2011 at 00:18

I found out that I'm also triggering the bus fault IMPRECISEERR at some point, and that my FORCED fault is caused by an escalation, or something.

I did move back to previous code, but the only difference is I'm commenting out functions, which aren't part of the fault.

Also the PC addresses seems to be even (and the manual states that bit 0 has to be 0)