How to add source directories and include directories for libraries?

When you do -I flags in the build_flags of the platformio.ini, they are relative to the root project directory – not to lib/FreeRTOS as you seem to be expecting. You would have to do -I lib/FreeRTOS/Source/ etc.

However, the proper way to add build configuration options (like include paths) to a library is via the documented library.json file, which can be added in the specific library folder itself.

I’d suggest starting with a simple description like

{
    "name": "FreeRTOS",
    "version": "10.2.1",
    "keywords": "rtos, timing, thread, task, mutex, semaphore",
    "description": "Real Time Operating System",
    "repository": {
        "type": "git",
        "url": "https://github.com/noidea/noidea.git"
    },
    "frameworks": "arduino",
    "platforms": "ststm32",
    "build": {
        "libArchive": false,
		"flags": [
			"-ISource/include",
			"-ISource/portable/GCC/ARM_CMF4/",
			"-ISource/portable/MemMang"
		]
    }
}

And taking it from there. Values like the framework and platform are a guess ofc.

Caveat note: libArchive: false is very important. FreeRTOS will hook interrupt functions like the SysTick or the system supervisor calls (SVC). Packing FreeRTOS as an .a archive file and linking it as such must not be done because in the final firmware link, would the interrupt functions would not correctly link to FreeRTOS but the default / empty ones in the Arduino core.

Another way is restructuring the source code and include file so that it’s all flat or doesn’t require specific include flags anymore. See e.g. Arduino_FreeRTOS_Library/src at master · feilipu/Arduino_FreeRTOS_Library · GitHub.

Others do it way more fancier and use the scripting capability of PlatformIO to take the vanilla FreeRTOS and build-configure it on the fly (GitHub - BOJIT/PlatformIO-FreeRTOS: PlatformIO Wrapper for FreeRTOS, designed for the FreeRTOS framework.).

1 Like