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 @u306060! 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 . 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.
Hi @u306060 and @valeros ,
While browsing the forum, I found the following way to specify a custom linkerscript. In the platformio.ini
file, you can define an environment like this:
[env:nucleo_l476rg]
platform = ststm32
board = nucleo_l476rg
board_build.ldscript = $PROJECT_DIR/my_linkerscript.ld
framework = stm32cube
The board_build.ldscript
option overwrites the ldscript
entry from the board’s json file, such that the linker uses your file 'my_linkerscript.ld'
in the project folder , instead of the default one.
Note:
If not specified, the default linkerscript would be:
~/.platformio/packages/tool-ldscripts-ststm32/stm32l4/STM32L476RGTX_FLASH.ld
PS: I found this thanks to @maxgerhardt , who helped me specify custom paths in projects (see PlatformIO integration into Embeetle IDE)
1 Like
Hi @kristof.mulier ! Thanks for sharing this with us. However as I remember I’ve tried something similar already.
May be I’ll get back to that issue to check if that is true.
1 Like