what causes the STM32F429ZI to experience a hard error when attempting to cast a value into float?

Hi guys, what causes the STM32F429ZI to experience a hard error (App_Fault_ISR) when attempting to cast a value into float?

I have come across a problem while using Atollic TrueSTUDIO on an STM32F429ZI Nucleo board. Below is my code:

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


The crash occurs at this assembly instruction:

080026fa:   ldr     r3, [r7, #4]
080026fc:   vmov    s15, r3  // <---- Crash occurs here


The Hard Fault Detected window shows:

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


Enabling the FPv4-SP-D16 FPU in the Assembler, Compiler, and C Linker settings with Hardware Implementation selected results in triggering a hard fault that leads to App_Fault_ISR.

What might be the cause of this problem?
Solution
The hard fault occurs because the FPU is not enabled. Add SCB->CPACR |= (0xF << 20); in your initialization code to enable the FPU, and ensure your project settings in Atollic TrueSTUDIO are configured for FPU usage (-mfpu=fpv4-sp-d16, -mfloat-abi=hard).
Was this page helpful?