How to compile & link for hardware FPU (STM32L4 - Bosch BSEC library)

I am building a project with an STM32L4 on a custom board, and trying to use the Bosch BSEC library.

I’ve managed to build and upload and run bsec_get_version(), but only for the M4 version of the library, not the M4F.

I’ve read this post, which had similar issue.

From this post I’ve learned that an extra script is needed to add compiler and linker flags so the hardware FPU gets enabled. As my MCU is a cortex M4F (unlike the M7 of the topic mentioned), I’ve added the code below to an extra script fpuflags.py and added it to platformio.ini extra_scripts.

Import("env")
Import("projenv")

for e in [env, projenv, DefaultEnvironment()]:
    e.Append(
        CCFLAGS=[
            "-mfloat-abi=hard",
            "-mfpu=fpv4-sp-d16",
        ],
        LINKFLAGS=[
            "-mfloat-abi=hard",
            "-mfpu=fpv4-sp-d16",
        ]
    )
extra_scripts = 
	pre:.github/workflows/buildinfo.py
	pre:.github/workflows/fpuflags.py

This results in an error *** Import of non-existent variable ''projenv''
It seems projenv is not available in pre:scripts.
So I tried

extra_scripts = 
	pre:.github/workflows/buildinfo.py
	.github/workflows/fpuflags.py

but this brings me back to the error like
error: .pio\build\target\firmware.elf uses VFP register arguments, .pio\build\target\lib3b6\libuart1.a(uart1.o) does not

I’m stuck here, so any help is appreciated!
Project is open-source, you can look into it on Strooom/BME688-ML-v1-SW at develop

After reading another related topic Hardware floating point implementation problem on ST Nucleo L432KC, I’ve found the solution:

  • remove the ‘projenv’ stuff from the extra script.
  • run the script as pre:

contents of .github/workflows/fpuflags.py

Import("env")

for e in [env, DefaultEnvironment()]:
    e.Append(
    CCFLAGS=[
        "-mfloat-abi=hard",
        "-mfpu=fpv4-sp-d16",
    ],
    LINKFLAGS=[
        "-mfloat-abi=hard",
        "-mfpu=fpv4-sp-d16",
    ]
    )

section in platformio.ini to add libalgosec.a to linker

build_flags =
	-lalgobsec
	-L "lib\bsec3210\algo\bsec_IAQ\bin\gcc\Cortex_M4F"

section to run extra script to enable FPU

extra_scripts = 
	pre:.github/workflows/fpuflags.py

So now things are building properly locally, but the build on github actions workflow still fails at the linker…

cannot find -lalgobsec ??

Linking .pio/build/production/firmware.elf
/home/runner/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld: cannot find -lalgobsec
collect2: error: ld returned 1 exit status

I have checked uppercase/lowercase problems (as my pc is windows, and the github actions runner is linux), but seems ok.
It’s not a huge problem, as the builds work fine locally, so I can proceed with the development, but it would be nice to stick to the standard workflow that I use, and that builds the production binaries in the CI/CD workflow.