AnsweredAssumed Answered

stm32f4 random hard faults (solved)

Question asked by aperles on Apr 10, 2012
Latest reply on Oct 2, 2013 by Clive One
Hi all,

With Keil MDK-ARM I had a random hard fault when I change the optimization level of the compiler.

The reason is a VPUSH.64 assembler instruction that tries to use the FPU. This instruction is added by the compiler before entering the main() function, so, at this point, the PFU is not enable.

I found a solution at

Edit startup_stm32f4xx.s file and add the following code in the Reset_handler

                ; CPACR is located at address 0xE000ED88
                LDR.W   R0, =0xE000ED88
                ; Read CPACR
                LDR     R1, [R0]
                ; Set bits 20-23 to enable CP10 and CP11 coprocessors
                ORR     R1, R1, #(0xF << 20)
                ; Write back the modified value to the CPACR
                STR     R1, [R0]; wait for store to complete
                ;reset pipeline now the FPU is enabled