PlatformIO Community

STM32 X-Cube-NFC4 Package Support

Hello everyone! I am looking for a way to avoid using STM32CubeIDE (it is not bad, but you know… old habits die hard) which depends on the ST packages NFC04A1, ST25DV, and the middleware lib_ndef. Everything is available in the ST github repo and I am struggling to find a nice way to import them into a platformio project. I saw there is support for the stm32duino version, could be possible to have it also for the STM32Cube framework?
Maybe you have a good idea to import the github repo in the project? I tried with lib_deps but the repo does not have a folder structure recognized by platformio… a way out could be git clone the ST repo and configure accordingly the platformio.ini file, but it would be way better to have direct support or an easy include.

Thanks for the help.

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 src/, Core/inc 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 .c to .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 App and 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 src/ and 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_App and NFC_Target, then no such things would have been needed.