cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4 random hard faults (solved)

aperles
Associate II
Posted on April 10, 2012 at 23:05

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 http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/471/t/155025.aspx?PageIndex=2

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

                DSB

                ;reset pipeline now the FPU is enabled

                ISB

Regrds,

�ngel

#semihosting
13 REPLIES 13
redmonds2
Associate II
Posted on October 02, 2013 at 13:16

My investigations indicate

- can't use MICROLIB if you want to use C++

- have to use MICROLIB if you want to use ITM (i.e. printf)

So result is

- can't use ITM (i.e. printf) if you want to use C++

Workarounds are all well and fine but there comes a point when you can't actually do what you need to do.

In most cases a proper fix is better.

Posted on October 02, 2013 at 14:26

ITM/SWV work at a hardware level, you are complaining about the libraries you are using, and how they are tailored to your platform. How you resolve your hosting issue is between you, the documentation, and Keil support.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
redmonds2
Associate II
Posted on October 02, 2013 at 17:31

forgive me, i'm just grumpy at having wasted so much of what should have been development time stepping through __scatterload, __decompress, __rt_entry, __user_setup_stackheap, __user_libspace, etc. trying to find out what was going on.

yes I think its a Keil issue. But this thread appeared to be relevant (I hit it when searching on the problem I saw) and I just wanted to post my findings here in the hope of saving other developers the time that I wasted stepping through system startup code trying to find which set of conditions were stopping me adding C++ files to my project