Well it’s hard to convey multiple years of development experience in a single post; there’s a lot of background knowledge in play here, but let me try anyways by showing how I developed it…
I’m assuming you have completely read the linked documentation and know what a platform, framework, package, board definition etc. is and how e.g. a platform and package is described and configured by its JSON files.
The entities involved here are:
- PlatformIO core logic (
pio
tool etc) GitHub - platformio/platformio-core: Your Gateway to Embedded Software Development Excellence 👽- doesn’t need to be modified here since this doesn’t touch on the base code
- the new Arduino core must come as a package
- copy of original GitHub - GrumpyOldPizza/arduino-STM32L4 with
package.json
for packaging plus any other files we want in there- e.g. a PlatformIO build script, see below…
- I forked it at GitHub - maxgerhardt/arduino-STM32L4
- copy of original GitHub - GrumpyOldPizza/arduino-STM32L4 with
- the platform, here
ststm32
- holds all board definitions (
*.json
), theplatform.json
definition (used packages, …) and builders - for now knows two Arduino cores:
stm32
(STM32Duino) andmaple
- which core is built is either set in the
"core": "<core>"
section of the board JSON or in theplatformio.ini
withboard_build.core = ..
- which core is built is either set in the
- see
- holds all board definitions (
- _
- needs modification, since this code must call the correct underlying build script for the new STM32L4 core
- fork repo → add new code path for
core == stm32l4
(as I did here) - redirects execution for build into the
platformio-build.py
of the newly created Arduino core package
- Understand build logic
- first understand how the Arduino IDE uses the
platform.txt
andboards.txt
to built the firmware. (Redirecting and more).- these two criticial files dictate what flags (
-D .. -m .. -f ..
) the compiler gets, how all available boards / variants are defined (with their name, configuration options which feed into compiler options, variant-specific source code folder, …) and how the code is uploaded (here: either openocd or dfu)
- these two criticial files dictate what flags (
- can also run Arduino IDE in verbose mode to see all compiler invocations if unsure
- first understand how the Arduino IDE uses the
- Replicate board JSON definitions (mostly templated from existing board definition, plus
boards.txt
, plus what options you need in there accessible from the build script, here e.g. I puthwids
,usb_product
etc) - and build logic in PlatformIO / SCons build script
- I started from the STM32Duino build logic (
C:\Users\<user>\.platformio\packages\framework-arduinoststm32\tools
) plus previous experience - work at arduino-STM32L4/tools/platformio-build.py at master · maxgerhardt/arduino-STM32L4 · GitHub
- I started from the STM32Duino build logic (
- Setup example project that uses all this
- Redirect
platform
to the forked version ofststm32
by pointing it to the new git as shown per docs - Add new Arduino core package. I chose the simpler
platform_packages
way here to make PIO download and “know” the package. The proper way would be to modify theplatform.json
. Since PIO 5.0.0 has introduced a new package repository system, and I don’t yet know how to reference my own published packages in there… - my work at GitHub - maxgerhardt/pio-stm32l4core-example: Examples for the PIO integration for arduino-STM32L4
- Redirect
As you can see one needs a quite good understanding of PlatformIO internals, terminology and python scripting to integrate it here. Usually the core team adds integration for new cores, platforms etc.
The way I develop is to clone all my forked repos but modify my local files in e.g. C:\Users\.platformio\packages
and C:\Users\.platformio\platforms
, then copy them back and commit. Only at the last stage I redirect the packages / platforms of the project to the forked sources, remove my previous packages and platforms and see if it correctly uses the redirected packages.