How do I use STM32Duino with Platformio?

Development environment specific, Arduino, Eclipse, VS2013, Em::Blocks etc
Post Reply
User avatar
Alextrical
Posts: 39
Joined: Tue Aug 02, 2022 12:59 pm
Location: Cornwall, UK

How do I use STM32Duino with Platformio?

Post by Alextrical »

Hi all

I'm wondering if anyone can point me in the direction of any instructions on how to setup Platformio in Visual Studio Code to use the STM32Duino core.
I'm hoping to make use of the STM32G0B1RBTx board definition that is available in Arduino 1.8.19

Kind regards
Alextrical
by ag123 » Tue Aug 02, 2022 3:41 pm
I'm unable to comment about platformIO as I don't use it myself.
But if you are prefer VSCode, you may want to try the arduiono extension
https://github.com/stm32duino/wiki/wiki ... -extension

and to try the core here
https://github.com/stm32duino/Arduino_Core_STM32
this is the repository for 'official' STM core.

platformIO likely pull this occasionally and adapt it for PlatformIO

if you find that you are building a new variant for your board, you may like to start with this core instead and placing your new variant files in the appropriate file structure/directories. it'd likely be necessary to update boards.txt for your entry as well (normally, by examining similar entries as examples and making a new one).

if your board is after all distributed in public, and your codes are part of this core, you may want to work with @fpiSTM to contribute your variant to the repository subsequently
Go to full post
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: How do I use STM32Duino with Platformio?

Post by ag123 »

welcome,
I'm not sure about Platform IO, but do take a look at the wiki
https://github.com/stm32duino/wiki/wiki/PlatformIO
for a while I tried VSCode with Arduino extension
https://github.com/stm32duino/wiki/wiki ... -extension
that works, but I've not used it in a while.
User avatar
Alextrical
Posts: 39
Joined: Tue Aug 02, 2022 12:59 pm
Location: Cornwall, UK

Re: How do I use STM32Duino with Platformio?

Post by Alextrical »

ag123 wrote: Tue Aug 02, 2022 2:30 pm I'm not sure about Platform IO, but do take a look at the wiki
https://github.com/stm32duino/wiki/wiki/PlatformIO
Hi ag123, thank you for your message, just to confirm as the way that link is phrased confuses me slightly
it mentions
Behind the scenes this will create a dependency on the ST STM32: development platform for PlatformIO.... This repository should not be confused with the ST STM32: development platform which is located at https://github.com/platformio/platform-ststm32.
when is says "This repository" it reads as if its referencing the previous block, that is also referencing "platform-ststm32"

I think I've managed to get the Blink sketch to compile for a STM32F401CC (BlackPill) using the information from what you sent, and finally this link https://docs.platformio.org/en/latest/p ... ion-system

Thank you for the heads up on the Arduino for VSCode extension, I will look into that :)
User avatar
Alextrical
Posts: 39
Joined: Tue Aug 02, 2022 12:59 pm
Location: Cornwall, UK

Re: How do I use STM32Duino with Platformio?

Post by Alextrical »

The next question I have is, Is there a list of compatible board names I can use?

This definition works for the Black pill, but I'm not sure how to setup for a STM32G0B1RBTx based chip.

Code: Select all

[env:genericSTM32F401CC]
platform = ststm32
board = genericSTM32F401CC
framework = arduino
build_flags =
  -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
  -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: How do I use STM32Duino with Platformio?

Post by ag123 »

i think the maintainers of PlatformIO has made a fork of
https://github.com/stm32duino/Arduino_Core_STM32
and made it one of their cores.
however, this repository is the "original" STM core, i.e. any developments done here is only in this repository.

to use STM32G0B1RBTx a new variant is needed
https://github.com/stm32duino/wiki/wiki ... 28board%29

However, what I'd normally do is to look at existing definitions and try to copy that structure and make a new set for my board.
you can take a look at the codes in the variants directory.
https://github.com/stm32duino/Arduino_C ... /STM32G0xx

a variant is normally needed for a new board as for instance there is a crystal on board (HSE)
https://github.com/stm32duino/Arduino_C ... -E)(I-T)xN
https://github.com/stm32duino/Arduino_C ... ic_clock.c
you would at least need a

Code: Select all

 void SystemClock_Config(void)
if you want to use the external crystal to setup your system clock i.e. HSE
an easier way is to look for codes that is done for existing boards replace and adapt the codes for your variant/board
Last edited by ag123 on Tue Aug 02, 2022 3:36 pm, edited 2 times in total.
User avatar
Alextrical
Posts: 39
Joined: Tue Aug 02, 2022 12:59 pm
Location: Cornwall, UK

Re: How do I use STM32Duino with Platformio?

Post by Alextrical »

Ah, is it that https://registry.platformio.org/platfor ... io/ststm32 manages the board definitions, and then passes over to stm32duino for the Arduino Core?
If I define my own board layout for the STM32G0B1RBT6 in the format similar to https://github.com/platformio/platform- ... 401cc.json would stm32duino be able to handle that?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: How do I use STM32Duino with Platformio?

Post by ag123 »

I'm unable to comment about platformIO as I don't use it myself.
But if you are prefer VSCode, you may want to try the arduiono extension
https://github.com/stm32duino/wiki/wiki ... -extension

and to try the core here
https://github.com/stm32duino/Arduino_Core_STM32
this is the repository for 'official' STM core.

platformIO likely pull this occasionally and adapt it for PlatformIO

if you find that you are building a new variant for your board, you may like to start with this core instead and placing your new variant files in the appropriate file structure/directories. it'd likely be necessary to update boards.txt for your entry as well (normally, by examining similar entries as examples and making a new one).

if your board is after all distributed in public, and your codes are part of this core, you may want to work with @fpiSTM to contribute your variant to the repository subsequently
User avatar
Alextrical
Posts: 39
Joined: Tue Aug 02, 2022 12:59 pm
Location: Cornwall, UK

Re: How do I use STM32Duino with Platformio?

Post by Alextrical »

I'm not all that up to speed with PlatformIO, but I'm hoping that VisualStudio will let me build for multiple board types with the Arduino extension like PlatformIO's ini allowed.

The exact chip I'm trying to use is actually the one used by BigTreeTech on the EBB42 v1.1 is a STM32G0B1CBT6 however the already made definition for STM32G0B1RBTx is a close enough match to work. The required board definitions for the CBT are already compiled in the stm32duino code, just not exposed as the required ldscript.ld wasn't generated

I would also be interested in getting support added for the other STM32 chips used on the BTT EBB boards in this repo

I'm more than happy to try and add support for the chips in question, as I have the hardware to confirm functionality. I take it that best practice would be to fork the git repo, and then create a pull request once the changes are made?
Post Reply

Return to “IDE's”