stm32nucleotruestudio

Why does casting to a float hits a hard error on STM32F429ZI (App_Fault_ISR)


Why does casting to a float hits a hard error on STM32F429ZI (App_Fault_ISR)?

I'm not exactly sure what's going on here. I'm use a Nucleo Board, STM32F429ZI, on Atollic TrueSTUDIO

The Code

CPU_FP32 speed;
CPU_INT32U val = (CPU_INT32U)(0x20u >> 4u);
speed = (CPU_FP32)val;

The Assembly where it last crashes

080026f2:   bl      0x8001dc8 <BSP_Tick_Init>
51            CPU_INT32U val = (CPU_INT32U)(0x20u >> 4u);
080026f6:   movs    r3, #2
080026f8:   str     r3, [r7, #4]
52            speed = (CPU_FP32)val;
080026fa:   ldr     r3, [r7, #4]
080026fc:   vmov    s15, r3            <----  

Looks like a move issue

The Hard Fault Detected Window shos

Bus, memory management or usage fault (FORCED) Extra details Attempt to execute a coprocessor instruction (NOCP)

This lands on App_Fault_ISR which appears to be a hard fault

As far as configuration Assembler,Compiler and C Linker have in setting have FPU enabled (FPv4-SP-D16) Hardware Implementation selected


Solution

  • It looks like you've not enabled the FPU, this needs to be done before any floating point instructions are attempted. You have to set bits 20-23 in CPACR register.

    This link shows the steps required, I usually do it in my startup code.