PlatformIO and STM32CubeMX projects

Hi all

Recently I decided to switch from STM32CubeIDE to PlatformIO with VSCode and I’m having some troubles. So far I diagnosed the problems to PIO not being able to compile C sources from multiple directories.
Cube projects are divided into Inc, Src, Drivers and optionally Middlewares directories, and additional startup directory with assembly file.
While attaching more include directories is all nice and easy (eg. adding build flag -IDrivers/CMSIS/Device/ST/STM32F1xx/Include in platformio.ini ), I found no way of specifying more source files or directories other than that specified in src_dir, as well as not being able to compile the startup assembly file (using as.exe).
The parameters src_dir and lib_dir only accepts single entry, and I was unable to find any more configuration options to do that.

I am aware of possibility to use PlatformIO’s stm32cube framework, however I prefer using STM32CubeMX GUI to generate all the peripheral configuration, etc., and copying files after every change in Cube’s project would be kind of cumbersome.
An ideal solution to me would be to have PIO to work with Cube generated projects. My guess is - if it was possible to specify multiple src_dir entries, most of the problem would be solved (we could simply alter our platformio.ini).

The bottom line is - is there a way to specify more than one src_dir and any way to compile and link assembly files? Or simply some way to have similar workflow for STM MCUs as in STM32CubeIDE, ie. create project in Cube, work on the code, make some changes in Cube’s project, work on the code some more, etc. etc.?

Possible duplicate of Into the quest for a CubeMX framework. There exists a third-party conversion tool GitHub - ussserrr/stm32pio: Automate managing of STM32CubeMX + PlatformIO projects.

Thanks for reply.

I gave it a try today, and it’s giving me some troubles as well. I tried it on two different scenarios:

First i tried using it on my existing project, using bare metal stm32 chip, with already generated CubeMX project. I used stm32pio init and after stm32pio new -b MY_BOARD. This was the output:

INFO starting to generate a code from the CubeMX .ioc file…
ERROR 2020-04-17 13:01:54,220 [ERROR] IPConfigManager:1272 - ERROR: the RefConfig ADC_InternalChannelConfig is not available in your config.xml file
2020-04-17 13:01:54,224 [ERROR] IPConfigManager:1272 - ERROR: the RefConfig ADC_InternalChannelConfig is not available in your config.xml file
2020-04-17 13:01:54,227 [ERROR] IPConfigManager:1272 - ERROR: the RefConfig ADC_InternalChannelConfig is not available in your config.xml file
2020-04-17 13:01:54,228 [ERROR] IPConfigManager:1272 - ERROR: the RefConfig ADC_InternalChannelConfig is not available in your config.xml file
2020-04-17 13:01:54,230 [ERROR] IPConfigManager:1272 - ERROR: the RefConfig ADC_InternalChannelConfig is not available in your config.xml file
2020-04-17 13:01:55,204 [ERROR] IPConfigManager:1272 - ERROR: the RefConfig I2CEnableFastModePlus is not available in your config.xml file
ERROR Exception: code generation error

After that I tried to simulate similar conditions on fresh project generated for Nucleo board. The procedure was as following:

  • Created Cube project
  • Added project folder to VSCode
  • Used platformio init command to set up PIO project
  • Used stm32pio init and stm32pio new -b nucleo_f413zh
    And at this point there are errors again:

INFO starting to generate a code from the CubeMX .ioc file…
INFO successful code generation
INFO starting PlatformIO project initialization…
ERROR FileNotFoundError: [WinError 2] Nie można odnaleźć określonego pliku

Where above translates to “Could not find given file”…

Bug reports for the tool to Issues · ussserrr/stm32pio · GitHub please.

I will file a report tomorrow.
In all honesty, I hoped for Platformio to support projects from Cube, without including a number of third party software.

If the project structure is followed like in the official examples (platform-ststm32/examples/stm32cube-hal-blink at develop · platformio/platform-ststm32 · GitHub, platform-ststm32/examples/stm32cube-ll-blink at develop · platformio/platform-ststm32 · GitHub), there should be no problem. PlatformIO only compiles sources from the project’s lib/ and src/ folder (both of which can be remapped to different folders, but not multiple, see docs), and includes files from include/. Since CubeMX doesn’t follow that structure these files have to be moved.

1 Like