Arduino ST STM32: Startup ".s" file filter

Hello everyone,

I’m trying to implement generic STM32F070CBTx board and my build is failing because it includes the startup file from another variant, namely MALYANMx00_F070CB. The build output looks like this:

Processing stm32f070cbtx (framework: arduino; platform: ststm32; board: genericSTM32F070CBTx)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Library Manager: Installing git+https://github.com/banoz/PSM.Library.git#feature/timer
git version 2.46.0.windows.1
Cloning into 'C:\Users\Vas\.platformio\.cache\tmp\pkg-installing-qt48g2sy'...
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 13 (delta 0), reused 8 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (13/13), 4.30 KiB | 880.00 KiB/s, done.
Library Manager: PSM@0.0.1+sha.8a920d6 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F070CBTx.html
PLATFORM: ST STM32 (17.5.0) > Generic STM32F070CBTx
HARDWARE: STM32F070CBT6 48MHz, 16KB RAM, 128KB Flash
DEBUG: Current (stlink) External (cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.20801.240815 (2.8.1)
 - framework-cmsis @ 2.50900.0 (5.9.0)
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 15 compatible libraries
Scanning dependencies...
Dependency Graph
|-- PSM @ 0.0.1+sha.8a920d6
Building in release mode
Compiling .pio\build\stm32f070cbtx\FrameworkArduinoVariant\PeripheralPins.c.o
Compiling .pio\build\stm32f070cbtx\FrameworkArduinoVariant\generic_clock.c.o
Compiling .pio\build\stm32f070cbtx\FrameworkArduinoVariant\startup_Mx00_f070xb.S.o
Compiling .pio\build\stm32f070cbtx\FrameworkArduinoVariant\startup_stm32f070xb.s.o
Compiling .pio\build\stm32f070cbtx\FrameworkArduinoVariant\variant_MALYANMx00_F070CB.cpp.o
Compiling .pio\build\stm32f070cbtx\FrameworkArduinoVariant\variant_generic.cpp.o
Compiling .pio\build\stm32f070cbtx\SrcWrapper\src\HAL\stm32yyxx_hal.c.o
Compiling .pio\build\stm32f070cbtx\SrcWrapper\src\HAL\stm32yyxx_hal_adc.c.o
Compiling .pio\build\stm32f070cbtx\SrcWrapper\src\HAL\stm32yyxx_hal_adc_ex.c.o

...

Compiling .pio\build\stm32f070cbtx\FrameworkArduino\wiring_shift.c.o
Compiling .pio\build\stm32f070cbtx\FrameworkArduino\wiring_time.c.o
Archiving .pio\build\stm32f070cbtx\libFrameworkArduino.a
Linking .pio\build\stm32f070cbtx\firmware.elf
c:/users/vas/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/stm32f070cbtx/FrameworkArduinoVariant/startup_stm32f070xb.s.o:(.isr_vector+0x0): multiple definition of `g_pfnVectors'; .pio/build/stm32f070cbtx/FrameworkArduinoVariant/startup_Mx00_f070xb.S.o:(.isr_vector+0x0): first defined here
c:/users/vas/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/stm32f070cbtx/FrameworkArduinoVariant/startup_stm32f070xb.s.o: in function `Default_Handler':
(.text.Default_Handler+0x0): multiple definition of `Default_Handler'; .pio/build/stm32f070cbtx/FrameworkArduinoVariant/startup_Mx00_f070xb.S.o:(.text.Default_Handler+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\stm32f070cbtx\firmware.elf] Error 1

As you can see it collects both .s files, as well as both variant_*.cpp files.

As soon as I remove the startup_Mx00_f070xb.S from the variant folder it compiles successfully.

I tried using build_src_filter but with no success, and this wouldn’t look pretty anyways.

Is it possible to filter out these files at all? What am I missing?

Interesting. You have hit exactly one of the only 2 folders out of the entire STM32duino core which have a variant specific startup file in their folder.

grafik

I’m not sure why, but when compiling for a e.g. board = blackpill_f103c8, then also startup_M200_f103xb.S is assembled and linked along with the regular startup_stm32yyxx.S which is used most of the time, but it does not generate a linker error… which it should though.

In any case, the PlatformIO builder script has no special provisions for excluding unwanted .S files, all files in the folder are compiled.

(env.BuildSources() has an optional src_filter parameter).

It solely relies on the fact that all files should be guarded by macros for their specific board type (example). You should file that as a bug report in https://github.com/platformio/platform-ststm32/issues.