How to add source directories and include directories for libraries?

Hi,

I am probably approaching it all wrong, and apologies if this is a duplicate question (found some related questions but I still don’t understand exactly how to approach this).

I am trying to use FreeRTOS in a small example project. I would really like to maintain the folder structure that is defined by FreeRTOS, so that I can easily update to newer versions in the future.

I would like to use it as a library, to clearly separate external code from my own code.

As the image clearly shows, files appear in red. The FreeRTOS .c files are unable to include the .h files which are present in FreeRTOS\Source\include.

I thought I would fix that problem by adding a bunch of directories to the include search path as follows:

image

But that doesn’t seem to solve the problem.

Is what I am trying to achieve possible? Or should I re-organize the folder structure of FreeRTOS so that it fits into the “PIO suggested way” of organizing libaries (lib/libname/src and lib/libname/include).

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

Hi thanks a million!!
Went for your first suggestion for now, created a library.json. I had to move one header file with the other headers. Didn’t look at the why yet.

Ran into some linker errors. Google pointed me out to add some compiler flags, so I did that too (without really knowing wth I am doing :))

"build": {
        "libArchive": false,
        "flags": [
            "-I Source/portable/GCC/ARM_CMF4",
            "-I Source/portable/MemMang",
            "-I Source/include",
            "-mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp"

It compiles! Now I have to understand what you (and many other pages on the internet I found by now) are talking about wrt system tick timer and it being claimed by free rtos.

Thanks again for the help!

PS: I felt stupid, I was surprised by lack of documentation of create library in platform io… If only I actually CLICKED on the library.json link, it would have had all the answers… /facepalm

It’s not the biggest deal in the world, but I prefer to understand it anyway.

As I said, I got it to compile, but I had to move one header. I don’t understand why.

It’s the portmacro.h header. It is located here:


When I move it over to lib/FreeRTOS/Source/include, it compiles fine.
When I move it back to its original position, I get this compile error :

Which should not be a problem since I added that directory to include path as well:

{
"name": "FreeRTOS",
"version": "10.2.1",
"keywords": "rtos, timing, thread, task, mutex, semaphore",
"description": "Real Time Operating System",
"frameworks": "stm32cube",
"platforms": "ststm32",
"build": {
    "libArchive": false,
	"flags": [
		"-I Source/include",
		"-I Source/portable/MemMang",
		"-I Source/portable/GCC/ARM_CMF4",
        "-mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp"
	]
}

}

Still compiler complains with the same error.

For the sake of trying, I also added the directory in platformio.ini

[env:nucleo_f446ze]
platform = ststm32
board = nucleo_f446ze
framework = stm32cube
lib_deps = FreeRTOS
build_flags =
    -I lib/FreeRTOS/Source/portable/GCC/ARM_CMF4

What am I doing wrong?

1 Like

Typo – should have been ARM_CM4F, not CMF4.

Oh how did I miss that…

Thx though…!