How to Enable Hardware Floating Point Math for Cortex M4 with FPU in GCC
04/106/2014 | 10:50 PM
Question
How do I enable hardware support for floating point math in GCC for EFM32WG (Wonder Gecko)?
Answer
How to Enable Hardware Floating Point
Add the following compiler symbol: ARM_MATH_CM4=1
Add the following flags to the GCC assembler, compiler, and linker: -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
Add the following include to source files using floating point math: #include "arm_math.h"
Make sure SystemInit() turns on the FPU hardware:
void SystemInit(void) { /* Set floating point coprosessor access mode. */ SCB->CPACR |= ((3UL << 10*2) | /* set CP10 Full Access */ (3UL << 11*2) ); /* set CP11 Full Access */ }
(Optional) Add CMSIS\Lib\GCC\libarm_cortexM4lf_math.a to your project for hardware accelerated floating point math functions.
How to Verify that Hardware Floating Point is Enabled
Launch a debug session in Simplicity Studio and insert a breakpoint on a line containing a floating point operation.
Run to the breakpoint and open the Disassembly view.
Verify that the FPU instructions, such as vldr, vmul, and vstr, are being used. If hardware floating point is not being used, floating point operations will jump to library functions and execute in software.
How to Enable Hardware Floating Point Math for Cortex M4 with FPU in GCC