Using STM32CubeMX and PlatformIO

Another way is to use config library.json. Then you don’t need any prescript. You only set all “Inc” subfolders in library.json.

platformio.ini:

[platformio]
src_dir = Src
lib_dir = Middlewares/ST

[env:disco_f407vg]
platform = ststm32
board = disco_f407vg
framework = stm32cube

Create library.json in Middlewares/ST/STM32_USB_Host_Library and set this content

{
    "name": "STM32_USB_Host_Library",
    "version": "0.0.0",
    "build": {
        "flags": [
            "-I $PROJECT_DIR/Inc",
            "-I Core/Inc",
            "-I Class/CDC/Inc"
        ]
    }
}

I checked that if I regenerate code in STM32CubeMX, library.json isn’t lost.

1 Like