Creating new package/build for existing framework/platform. how to variate build at package level?


I would like to add a new package for ‘arduino’ framework and ‘ststm32’ platform. There is on-going work for with new HAL based Arduino framework.

I think it is not reasonable to create another framework because this new one is for Arduino and STStm32. Only difference is that there is new package folder and build system is a little different . Build can be variated in current ‘’ script. Only package directory is different and needed.

What kind of possibilities there are to distinguish the build process between current arduino-stm32 package and this new arduino package in platformio.ini? One idea came to my mind is that put special string in [env:…] string in platform.ini and check it in build script from PIOENV variable.

like if we have:

[env:disco_407vg_HAL] → check if PIOENV ends with HAL – > then use new arduino package and build system.

What possibilities there are to export variant name from platformio.ini into use for build system.


How about to add build_flags = -DFORCE_STHAL option and then handle it via if "FORCE_STHAL" in env.get("CPPDEFINES") ?

Thanks for the reply. Yes, your suggestion is better. I will do that.

But I still have a problem with linker script and it does not work properly. For some reason for linker flag (-T) platformio prepends ‘-Wl,’ so the result is that I have error :

r.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2.exe: error: ld returned 1 exit status

ldscripts are defined in variant folder “variants\DISCOVERY_F407VG” so I am using that for path.

Full linker command for platformio is:

-Wl,-T"ldscript.ld"        <--------------- 

If I change the offending line on the commandline manually from

Then it links okay. I tried to add -Tldscript.ld into LINKFLAGS but then there is two linker scripts defined and there is an error in linking.

If I compare to what Arduino IDE builds, there is only -T used for linker script file. It does not use -Wl,-T

"D:\Users\michael\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-gcc" -mcpu=cortex-m4
"-TD:\Users\michael\Documents\Arduino\hardware\STM32GENERIC\STM32\variants\DISCOVERY_F407VG/ldscript.ld"  <------------------------------


So how can I tell to linker that remove -Wl, from the from so that option becomes -Tldscript.ld and not -Wl,-Tldscript.ld

-Tldscript.ld → works
-Wl,-Tldscript.ld → does NOT work

P.S. Platformio is awesome tool !

EDIT: Looks like -Wl,-T is added in

#append specified LD_SCRIPT
if ("LDSCRIPT_PATH" in env and
        not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):

In my case this becomes a problem. Is there a way to remove LDSCRIPT_PATH from env ?


Replying to myself. The problem was not the linker flag. I rewrote the handler and now it seems to be working okay.

1 Like

I think you can pack your “Arduino for ST STM32” in a separete package. We will help you to integrate it with existing ststm32 development platform.

Please ping us here when you will be ready.

Ok, thanks!

I have forked ststm32 from latest development into GitHub - maichaell/platform-ststm32: ST STM32: development platform for PlatformIO and done development there. I have added new package in platform.json and added another ‘arduino’ framework. And of course changed to support this new package.

Whether to use new stm32generic is based on build_flag -DUSE_STM32GENERIC. If it is not defined then will use the original stm32duino builder.


platform = ststm32
board = genericSTM32F103CB
framework = arduino

platform = ststm32
board = genericSTM32F103CB
framework = arduino

For currently tested boards I have added ‘arduino’ for framework name so that it can be built.

package repository to use is here:

I have used method platformio platform install file://<folder> for my own development purposes. But can you add that package to your official repositoy so it is downloaded automatically when someone else tries to use it ? Repository is under development but is already quite working with many boards.

If anything else needed, please let me know.