Spark Logic

Enable and verify the STM32F407 floating-point unit

Build and check single-precision floating-point code on the STM32F407 Cortex-M4F.

Use consistent compiler and linker options

STM32F407 has a single-precision FPU. Use float variables, literals such as 0.5f and functions such as sqrtf(). A double-precision calculation still uses software support.

With GCC, select Cortex-M4 and -mfpu=fpv4-sp-d16. For hard-float calling conventions, set -mfloat-abi=hard for the application and all linked objects and libraries. With softfp, the compiler can still generate floating-point instructions while following the base calling convention. Match the core or board package and its libraries rather than adding one flag to a single source file.

Check startup and the generated instructions

The STM32 CMSIS startup normally enables coprocessors CP10 and CP11 in SystemInit() for a build using the FPU. Check the startup code and SCB->CPACR if the first VFP instruction faults. In an RTOS build, use the Cortex-M4F port and its configured FP context support.

Disassemble a calculation with runtime inputs and look for single-precision instructions such as vmul.f32. Software double operations can show up as calls such as __aeabi_dmul. Make the result observable before timing it so optimization cannot delete the calculation.

References