platformio / platform-ststm32

ST STM32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/ststm32
Apache License 2.0
395 stars 309 forks source link

Linking error with libc nano on STM32G4 with STSTM32 V15.0 to 15.2 #599

Closed cfoucher-laas closed 2 years ago

cfoucher-laas commented 2 years ago

Hello,

We have worked with Zephyr 2.6 on STM32 with PlatformIO for some time now. We tried to migrate our project to STSTM32 V15.0 to make use of Zephyr 2.7, and got a link error with libc nano at compile time. We work on STM32 G474RE µC. The error also happens with V15.2.

Error is as follows:

~/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.bfd: error: .pio/build/myenv/zephyr/firmware-pre.elf uses VFP register arguments, ~/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libc_nano.a(lib_a-nano-msizer.o) does not
~/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.bfd: failed to merge target specific data of file ~/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libc_nano.a(lib_a-nano-msizer.o)

(multiple such errors)

The error is linked to the FPU support of Zephyr. I tried disabling CONFIG_FPU in prj.conf and it solves the issue, except that we need FPU for our application.

After investigating, my understanding is that the linker tries to link the executable with [gcc toolchain]/v7e-m/nofp/libc_nano.a instead of [gcc toolchain]/v7e-m+fp/hard/libc_nano.a

The only change we made to the project was updating the version of STSTM32 platform (14.2 => 15.0).

I've built a minimal example that provokes the bug, it can be found here: https://gitlab.laas.fr/cfoucher/zephyr_2_7_linker_error

Steps to reproduce the behavior:

  1. You must have Visual Studio Code installed, with PlatformIO plugin enabled to test this.
  2. $ git clone https://gitlab.laas.fr/cfoucher/zephyr_2_7_linker_error.git test_v15
  3. $ cd test_v15
  4. $ code .
  5. Within the VS Code window that opened, hit the Build button from the pio toolbar. Everything should compile fine.
  6. Edit the platformio.ini file, commenting the line 9 and uncommenting the line 10.
  7. Save the file, clean the project, and build again.

I first reported this issue to Zephyr, and one of the clue they gave me was that the version of GNU Arm Embedded was fairly obsolete, and that the bug wasn't happening with the 2021.10 version.

I tried bumping the version of the toolchain to 1.9 using: platform_packages = toolchain-gccarmnoneeabi@1.90201.191206 but it didn't help.

I can't find a more recent version in the repository.

Do you have any idea where the bug can come from?

valeros commented 2 years ago

Hi @cfoucher-laas , thanks for reporting. Should be fixed in the latest Zephyr package. Could you please try to run the pio platform update ststm32 in the IDE terminal?

cfoucher-laas commented 2 years ago

Thank you for this quick answer @valeros, I confirm that the update did fix the issue.

Thank you very much!