FreeRTOS#
Pigweed AI summary: The FreeRTOS module contains various helpers to use FreeRTOS, including Pigweed backend modules which depend on FreeRTOS. This module provides support to compile FreeRTOS with GN, CMake, and Bazel. In order to use GN, you need to configure the variables in the freertos.gni file. For CMake, you need to set the variables in the CMakeLists.txt file. For Bazel, the FreeRTOS build is configured through constraint_settings and the platform you are building for must
The $dir_pw_third_party/freertos/
module contains various helpers to use
FreeRTOS, including Pigweed backend modules which depend on FreeRTOS.
Build Support#
Pigweed AI summary: This paragraph provides an overview of the "Build Support" module, which is used to compile FreeRTOS with GN, CMake, and Bazel. It explains the configuration variables that need to be set for each build system, such as the path of the FreeRTOS installation and the targets that provide the FreeRTOS config header and port specific includes and sources. It also mentions the settings that need to be specified in Bazel for the FreeRTOS build, such as the FreeRTOS port and malloc implementation.
This module provides support to compile FreeRTOS with GN, CMake, and Bazel. This is required when compiling backends modules for FreeRTOS.
GN#
Pigweed AI summary: This paragraph provides instructions for configuring variables in order to use FreeRTOS. The variables that need to be configured are listed, including the path to the FreeRTOS installation and the source sets that provide the config header and port specific includes and sources. Once these variables are set, a source set for the FreeRTOS library is created.
In order to use this you are expected to configure the following variables from
$dir_pw_third_party/freertos:freertos.gni
:
Set the GN
dir_pw_third_party_freertos
to the path of the FreeRTOS installation.Set
pw_third_party_freertos_CONFIG
to apw_source_set
which provides the FreeRTOS config header.Set
pw_third_party_freertos_PORT
to apw_source_set
which provides the FreeRTOS port specific includes and sources.
After this is done a pw_source_set
for the FreeRTOS library is created at
$dir_pw_third_party/freertos
.
CMake#
Pigweed AI summary: To use CMake, you need to set three variables from third_party/freertos/CMakeLists.txt: dir_pw_third_party_freertos, pw_third_party_freertos_CONFIG, and pw_third_party_freertos_PORT. The first variable should be set to the path of the FreeRTOS installation, while the other two should be set to library targets that provide the FreeRTOS config header and port specific includes and sources, respectively.
In order to use this you are expected to set the following variables from
third_party/freertos/CMakeLists.txt
:
Set
dir_pw_third_party_freertos
to the path of the FreeRTOS installation.Set
pw_third_party_freertos_CONFIG
to a library target which provides the FreeRTOS config header.Set
pw_third_party_freertos_PORT
to a library target which provides the FreeRTOS port specific includes and sources.
Bazel#
Pigweed AI summary: In Bazel, the FreeRTOS build is configured through constraint_settings. The platform you are building for must specify values for the following settings: //third_party/freertos:port, //third_party/freertos:malloc, and //third_party/freertos:disable_task_statics_setting. Additionally, you need to set the @pigweed_config//:freertos_config label flag to point to the library target providing the FreeRTOS config header. Refer to Pigweed's Bazel configuration for more information
In Bazel, the FreeRTOS build is configured through constraint_settings. The platform you are building for must specify values for the following settings:
//third_party/freertos:port
, to set which FreeRTOS port to use. You can select a value from those defined inthird_party/freertos/BUILD.bazel
.//third_party/freertos:malloc
, to set which FreeRTOS malloc implementation to use. You can select a value from those defined inthird_party/freertos/BUILD.bazel
.//third_party/freertos:disable_task_statics_setting
, to determine whether statics should be disabled during compilation of the tasks.c source file (see next section). This setting has only two possible values, also defined inthird_party/freertos/BUILD.bazel
.
In addition, you need to set the @pigweed_config//:freertos_config
label
flag to point to the library target providing the FreeRTOS config header. See
Pigweed’s Bazel configuration for a discussion of how to work
with @pigweed_config
.
Linking against FreeRTOS kernel’s static internals#
Pigweed AI summary: This section discusses how to link against FreeRTOS kernel's internal data structures using extern "C" and disabling statics for the tasks.c source file. Pigweed offers an opt-in option to disable statics, which can be enabled in GN, CMake, or Bazel. However, users must ensure that their FreeRTOSConfig.h and port do not rely on any statics inside tasks.c. A helper is defined when statics are disabled to manage conditional configuration. The section recommends using Pigweed
In order to link against internal kernel data structures through the use of
extern “C”, statics can be optionally disabled for the tasks.c source file
to enable use of things like pw_thread_freertos/util.h’s ForEachThread
.
To facilitate this, Pigweed offers an opt-in option which can be enabled,
in GN through
pw_third_party_freertos_DISABLE_TASKS_STATICS = true
,in CMake through
set(pw_third_party_freertos_DISABLE_TASKS_STATICS ON CACHE BOOL "" FORCE)
,in Bazel through
//third_party/freertos:disable_task_statics
.
This redefines static
to nothing for the Source/tasks.c
FreeRTOS source
file when building through $dir_pw_third_party/freertos
in GN and through
pw_third_party.freertos
in CMake.
Attention
If you use this, make sure that your FreeRTOSConfig.h and port
does not rely on any statics inside of tasks.c. For example, you cannot use
PW_CHECK
for configASSERT
when this is enabled.
As a helper PW_THIRD_PARTY_FREERTOS_NO_STATICS=1
is defined when statics are
disabled to help manage conditional configuration.
We highly recommend
our configASSERT wrapper when using
this configuration, which correctly sets configASSERT
to use PW_CHECK` and
``PW_ASSERT
for you.
OS Abstraction Layers Support#
Pigweed AI summary: This section discusses the support for Pigweed's OS abstraction layers in FreeRTOS through modules such as pw_chrono_freertos, pw_sync_freertos, and pw_thread_freertos.
Support for Pigweed’s OS Support are provided for FreeRTOS via the following modules:
configASSERT and pw_assert#
Pigweed AI summary: The article discusses the use of pw_assert with FreeRTOS and provides a helper header, pw_third_party/freertos/config_assert.h, which defines configASSERT using Pigweed's assert system for FreeRTOSConfig.h. The header can be included instead of defining configASSERT.
To make it easier to use pw_assert with FreeRTOS a helper header
is provided under pw_third_party/freertos/config_assert.h
which defines
configASSERT
for you using Pigweed’s assert system for your
FreeRTOSConfig.h
if you chose to use it.
// Instead of defining configASSERT, simply include this header in its place.
#include "pw_third_party/freertos/config_assert.h"