Indeed importing STM32Cube examples / components is a bit painful. For STM32Cube projects, there’s the tool GitHub - ussserrr/stm32pio: Automate managing of STM32CubeMX + PlatformIO projects, but I don’t think that works for the expansion pacakges.
I’ve created https://github.com/maxgerhardt/pio-nfc-ndef-uri as a replication of the Nucleo_L476RG/NDEF_URI example. Can you check that one out?
It shows how to do the basic ‘conversions’, aka, moving files and renaming a few folders. The project uses as a base
framework = stm32cube in the
platformio.ini, so it will use PlatformIO’s
framework-stm32cube-l4 package in this case and not the STM32L4 HAL supplied by the NFC expansion pack. Some users take a different approach and make it a baremetal project (no
framework = .. line) so that that too can be fully controlled, but I found the ‘regular’ way to be working.
I basically coped the example’s
Core/Src files to
include. Note that for PlatformIO libraries and projects, the include folder is called
include by default, while STM32Cube and its components call it
inc – thus renaming this folder is needed. I then took a look at the needed source files. This part is tricky, since the expansion pack / libraries contain source files that some projects don’t need and will not compile. In fact, attempting to compile them will result in error messages. So I took a look at the
.project file and thus found the exact general folders that I needed to put as a library in
lib/. I renamed uncompiled source files from
.txt so that they’re not compiled. The
.cproject file is also important in regards to e.g. global macros or
-l flags and other compiler settings, but I found no macros that are not by-default added in PlatformIO projects
framework = stm32cube project.
For library folders that have multiple sub-folders with header and source files, e.g. for the
NFC library, I took the approach of creating a new
src folder in which both of the sub folders
Target were put. But since the application code just does e.g.
#include <app_nfc.h> and by default PlatformIO only puts the libary’s
include/ folder in the include path, I had to add a small
build_flags = -I[...] addition into the
platformio.ini. I guess I could have also modelled it as two library folders,
NFC_Target, then no such things would have been needed.