Target Generic MCU MKL26Z64, STM32G031K8, etc


Background: I’ve just started getting into ARM32 based MCUs, and I’d like to try out different vendors like NXP, Microchip, and ST, so I’ve ordered some cheap boards for each. For an NXP board I’m using a Teensy LC. I realise the intention with the Teensy is to use it for Arduino, however I see no reason why it can’t be programmed using CMSIS. I’m hoping to use PlatformIO to target any of these.

Finally, to get to my question: The Teensy LC only has an Arduino framework - how do I target the MKL26Z64 MCU itself so I can use CMSIS? Further, I see the Nucleo development boards available, but not their standalone MCUs. I’m planning on using one of these chips for an actual product and I’m concerned that I can’t target the generic processor for when I make my custom board and program over SWD. Is the intention of this platform to support things like that, or is it meant to be like Arduino where it only really supports pre-made boards?


PlatformIO always works in the context of boards, not pure MCUs. Here’s the documentation for board definitions, though it helps even more to look at existing board definitions that are close to the boards you want, e.g., teensylc.json and nucleo_g031k8.

In short, a PlatformIO board definition does not only contain the name of the MCU you’re working with, but more information, regarding e.g. the nominal clock speed the board runs at (f_cpu), macros that are always present (extra_flags), the name of the Arduino variant to be used with (variant), the supported debug methods and meta-info for that (debug), supported frameworks (frameworks) and supported upload methods and parameters (upload).

Note that you can always have your own board definitions in the boards/ folder of the project and use those if the standard board definition are not applicable for your usecase.

PlatformIO does not have built-in support for framework = cmsis on platform-teensy at the moment, and nobody has yet requested it in here, but it is very easy to add it yourself for the moment being. The general gist is to create a baremetal project (aka, no external stuff is compiled) and then add the CMSIS code and necessary build settings. I’ve taken the liberty to fork a TeensyLC CMSIS project and make it PlatformIO-compilable at GitHub - maxgerhardt/teensylc-baremetal: GCC Bare Metal Toolchain with CMSIS for the Teensy-LC Board (KL26Z64 Cortex-M0+).

In the case of using a STM32G031K8 MCU within a CMSIS project, you can just use the Nucleo G031K8 board definition because there would be no difference in the build, upload or debug settings compared to if you created your own board definition for a generic STM32G031K8 board.

platform = ststm32
board = nucleo_g031k8
framework = cmsis
; for cmsis-blink/src/main.c to identify series
build_flags = -DSTM32G0

as a platformio.ini and the cmsis-blink project can be used as a starting point there.

Note that the default boards do contain a lot of genericSTM32xxxx.json definitions otherwise, which use the generic Arduino board variants.

Thankyou very much for the reply.

I’ll place a request in the mentioned Github for official support, and give your ported version a go to start learning! Hopefully all goes well.

It’s good to hear that I can make my own board files. I felt a bit locked in to AVR when using 8 bit micros using their IDE, and am trying to avoid being locked into any 1 vendor for 32 bit ARM, hence PlatformIO and CMSIS.