Excluding framework files from build

I want to exclude stm32cube framework files which are always automatically included in cpp_properties.
Is it possible to do it without modifying the builder script of the framework? I want to use my own driver files instead of these automatically added ones( like .platformio/packages/framework-stm32cubef0/Drivers/CMSIS/DSP/Include)

STM32Cube with the DSP library is a specially support case. If you have the latest platform-ststm32 version (CLI → pio platform update ststm32), just follow the documentation.

board_build.stm32cube.custom_dsp_library = yes

It didn’t have any effect. I still get multiple definition errors coming from .platformio/packages/ sources. Here is my platformio.ini configuration. I can to bypass source files with an extra_script.py but can’t discard header files.

platform = ststm32
board = stm32f030c8
framework = stm32cube
board_build.stm32cube.custom_dsp_library = yes
src_filter = +<*> +<../CubeMx/Drivers/STM32F0xx_HAL_Driver/Src> +<../CubeMx/Core/Src>
board_build.ldscript = $PROJECT_DIR/CubeMx/STM32F030C8TX_FLASH.ld
build_unflags = -std=c++11 -std=gnu++11
build_flags = -std=c++17

What about ^-- this?

The fix commit definitely disables the entire inclusion (header files and precompiled library included) from the build.

Have you tried just

build.stm32cube.custom_dsp_library = yes

? I might have been wrong the first time.

build.stm32cube.custom_dsp_library = yes

Gives unknown configuration warning.

I used the latest development version directly from github still doesn’t have any effect whatsoever.

If you’ve used that before it may have not done a fresh git-pull. Can you manually remove C:\Users\<user>\.platformio\platforms\ststm32** to make sure it pulls the newest version?

Try both after doing per above. And always execute the “Clean” project task before rebuilding.

No luck unfortunately. I created a minimal project if you want to check out.


Oh okay yeah I see why that might not work. You’ve copied the entire F0 HAL in it on top of specifying framework = stm32cube, which will include PlatformIO’s STM32Cube F0 HAL version.

Is there a problem with PIO’s HAL version?

If you delete the

framework = stm32cube

line in the platformio.ini it turns it into a baremetal project from the PlatformIO perspective and it compiles normally with only the sources in the project – zero PlatformIO STM32Cube support used then and no more double-definitions from your project’s HAL version and PlatformIO’s HAL version.

RAM:   [==        ]  20.0% (used 1640 bytes from 8192 bytes)
Flash: [=         ]  14.4% (used 9412 bytes from 65536 bytes)
Building .pio\build\stm32f030c8\firmware.bin

That’s what you want for the project?

I thought getting the configuration from CubeMx could more reliable since my board is a custom PCB if that makes sense. I don’t really know how PIO creates configuration for such custom boards. I also prefer my project files to be self contained.

Strangely it doens’t compile when framework is deleted because it doesn’t know what to do with startup file. Other than that it’s exactly what i was trying to accomplish.

Oh I see, it works on me on Windows because of case-insensitivity. Rename src/startup_stm32f030x8.s to src/startup_stm32f030x8.S. Then the assembly file will be handled by the right program.

Well but I don’t think the CubeMX generator changed the basic STM32F0 HAL that PlatformIO would be providing too. Take a look at the standard examples at platform-ststm32/examples/stm32cube-hal-blink at develop · platformio/platform-ststm32 · GitHub – the advantage of PlatformIO is exactly that a user doesn’t need to copy the entirety of the STM32HAL into the project since PlatformIO maintains it. Still, custom-configuring the options of it possible with the linked documentation, but the focus is on convenience.

But having a bare-metal project with all sources contained in the project can have advantages too – no dependency or variation can be introduced by relying on PlatformIO’s HAL version and full control over all files and compile settings. Chose whichever suits your application best.

1 Like

Thats awesome. It works now. Thank you!