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

Hello,

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 ‘arduino.py’ 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.

Thanks,
Michael

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 :

d:/users/michael/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/ar
m-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu\libc_s.a(lib_a-sbrk
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:

arm-none-eabi-g++
-o
.pioenvs\disco_f407vg_halmx\firmware.elf
-Wl,-T"ldscript.ld"        <--------------- 
.pioenvs\disco_f407vg_halmx\src\blink.o
-LD:\Users\michael\.platformio\packages\framework-arduinoSTM32GENERIC\STM32\variants\DISCOVERY_F407VG
-L.pioenvs\disco_f407vg_halmx
-Wl,--start-group
.pioenvs\disco_f407vg_halmx\libFrameworkArduinoVariant.a
.pioenvs\disco_f407vg_halmx\libFrameworkArduino.a
-lc
-lgcc
-lm
-lc
.pioenvs\disco_f407vg_halmx\lib\libFreeRTOS.a
-Wl,--end-group

If I change the offending line on the commandline manually from
-Wl,-T"ldscript.ld"
to
-T"ldscript.ld"

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
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
-mthumb
-Os
-Wl,--cref
-Wl,--check-sections
-Wl,--gc-sections
-Wl,--entry=Reset_Handler
-Wl,--unresolved-symbols=report-all
-Wl,--warn-common
-Wl,--warn-section-align
"-TD:\Users\michael\Documents\Arduino\hardware\STM32GENERIC\STM32\variants\DISCOVERY_F407VG/ldscript.ld"  <------------------------------
"-Wl,-Map,D:\Users\michael\AppData\Local\Temp\arduino_build_498965/BlinkLeds.ino.map"

-o
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965/BlinkLeds.ino.elf"
"-LD:\Users\michael\AppData\Local\Temp\arduino_build_498965"
-Wl,--start-group
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\sketch\BlinkLeds.ino.cpp.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\Arduino_FreeRTOS.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\croutine.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\event_groups.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\heap_3.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\list.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\port_CM0.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\port_CM3.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\port_CM4F.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\port_CM7.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\queue.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\tasks.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\libraries\FreeRTOS\timers.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\core\systemclock_config.c.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965\core\variant.cpp.o"
"D:\Users\michael\AppData\Local\Temp\arduino_build_498965/core\core.a"
-lc
-Wl,--end-group
-lm
-lgcc
--specs=nano.specs

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 platformio.py

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

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

Thanks,
Michael

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 arduino.py to support this new package.

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

[common]
#src_path=.\

[env:BluePill_stm32generic]
platform = ststm32
board = genericSTM32F103CB
framework = arduino
build_flags = -DUSE_STM32GENERIC -DMENU_USB_SERIAL -DMENU_SERIAL=SerialUSB


[env:BluePill_stm32duino]
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:

https://github.com/danieleff/STM32GENERIC

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.

Thanks,
Michael