Unable to build code with FPU flag enabled in .ini

Hello everyone. I have been coding stuff for my WeAct STM32f411ceu6 blackpill board. For the last day, I’ve been trying to build the code with the following settings:

[env:blackpill_f411ce]
platform = ststm32
board = blackpill_f411ce
framework = stm32cube

build_flags =
    -Ilib/USB_DEVICE/include
    -Ilib/STM32_USB_Device_Library/Core/Inc
    -Ilib/STM32_USB_Device_Library/Class/CDC/Inc

    -mcpu=cortex-m4
    -mfpu=fpv4-sp-d16
    -mfloat-abi=hard
    -O2
    -Wall

; Use J-Link for upload & debug
upload_protocol = jlink
debug_tool = jlink
debug_init_break = tbreak main

; keep ELF for Ozone
build_type = debug
monitor_speed = 115200

However, upon attempting to build the code I get (many of):

c:/users/martin/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: error: .pio/build/blackpill_f411ce/lib548/libCDC.a(usbd_cdc.o) uses VFP register arguments, .pio/build/blackpill_f411ce/firmware.elf does not
c:/users/martin/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file .pio/build/blackpill_f411ce/lib548/libCDC.a(usbd_cdc.o)
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\blackpill_f411ce\firmware.elf] Error 1

These errors occur for a myriad of other files. To my understanding this is because platformio pulls a version of the HAL framework which is not built with FPU enabled, but I’m not entirely sure as this is my first experience with large C projects, especially in platformio. I was wondering what I must set in my platformio.ini settings to build the code with the FPU enabled? The usage of the FPU is critical for my use case.

Thanks for the help!

You need to propogate the FPU flags to all build and environments and the linking stage as well through an extra_script. See already posted solution in

1 Like

This seems to have worked! Thank you!