PlatformIO Community

Custom linker script STM32CUBE

I was investigating how to feed a custom linker file to compiler while building a project based on famework-stm32cube. (Project is generated via stm32CubeMx, and the linker file is in "project_root_dir/*_FLASH.ld)

I’ve got the following message:
Warning! Cannot find a linker script for the required board! Firmware will be linked with a default linker script!

According to https://github.com/platformio/platform-ststm32/blob/96da9d8d22b28dcdf59936df20b8fa76b2a1e421/builder/frameworks/stm32cube.py#L106

There is only chance to copy the linker file to .platformio root … framework … ldscripts directory.
Is there any other way to point to this file in my project directory?

Thanks ~

Hi @Sergio! Probably the best solution is to specify your linker script by using build_flags, e.g.:

[env:nucleo_f401re]
platform = ststm32
framework = stm32cube
board = nucleo_f401re
build_flags = -Wl,-Tpath_to_your_script/script.ld

Hi @valeros ! Thanks for the answer. I’ve tried this earlier:
-Wl,-T$PROJECT_DIR/STM32F401RE_FLASH.ld
This doesn’t work for me, still got
Warning! Cannot find a linker script for the required board! Firmware will be linked with a default linker script!
Any ideas?


Still have to copy the .ld file to .framework-stm32cube directory. This is not convenient way that does not allow doing it automatically after each code generation.

Looks like that warning might be a false positive. You can successfully compile your project with the custom linker script, right?

Yes, it compiles. I am worried that once I would need to customize ld file, I would have to copy it manually again and again

Don’t copy it to the framework folder, because with the next update it will be deleted. Just keep your ld script in the root folder of your project, add it to your project using build flags and you should be fine. You also can give your script a notable name so you can distinguish between your script and the default one.

1 Like

Hi @valeros! I’m aware of copying it to the framework directory. buiild_flags directive doesn’t work for me. My guess that there is a way to declare the path that still out of my knowledge in PlatformIO.

I suppose that warning might be a bit misleading, we will try to reimplement it or change the text in the next release. As for now, it’s fine to see that warning even when you specified your own linker script as long as you can successfully compile your project.

1 Like

Well, there is a bit of “usability” issues in PlatformOI, that’s true :slight_smile:. However nothing critical.
Thanks for the information


The conclusion is there is no efficient way to use custom LD script with framework-stm32cube (at least), except to copy it to framework directory.