|
ELEC-C7222
Libraries for ELEC C7222 Course Work
|
This document explains how the CMake build is structured in this repository, which options are available, and how examples/projects are converted into final firmware targets.
The project uses a single top-level CMakeLists.txt to:
The default board is configured as:
PICO_BOARD = pico2_wToolchain defaults are aligned with Pico VS Code extension paths via:
cmake/pico-compiler-settings.cmakeSeveral parts of the library (BLE, GAP, GATT, Security Manager, and some device code) select platform-specific source files based on whether PICO_SDK_PATH is available:
PICO_SDK_PATH is defined and non-empty, platform sources are taken from platform/rpi_pico/.platform/grader/.This pattern is used in:
libs/elec_c7222/ble/ble.cmake and its submodules (gap.cmake, gatt.cmake, security_manager.cmake)libs/elec_c7222/devices/devices.cmakelibs/elec_c7222/utils/utils.cmakeMain options defined in the root CMake:
C7222_ENABLE_BLE (default ON)ELEC_C7222.C7222_BLE_DEBUG (default OFF)C7222_BLE_DEBUG=1 compile definition to generated app targets.C7222_EXAMPLES_BUILD (default ON)libs/elec_c7222/examples.C7222_GETTING_STARTED_BUILD (default ON)getting-started/getting-started.cmake.C7222_EXPORT_PICO_UF2 (default ON)${CMAKE_BINARY_DIR}/images/<target>.uf2 for drag-and-drop flashing via Pico MSC (BOOTSEL mode), without debugger tooling.Additional cache variables:
PROJECT_NAME (default ELEC-C7222-CPP-LIB)PICO_BOARD (default pico2_w)FREERTOS_KERNEL_PATH (optional override path)FREERTOS_CPP11_PATH (optional override path)Imported via:
cmake/FREERTOS_KERNEL_import.cmakeBehavior:
FREERTOS_KERNEL_PATH if defined.libs/FreeRTOS-Kernel.FreeRTOS-Kernel and initializes required submodules.Imported/configured via:
cmake/FreeRTOS_CPP11_import.cmakecmake/FreeRTOS_Cpp11_lib.cmakeBehavior:
FREERTOS_CPP11_PATH if defined.libs/FreeRTOS_cpp11 or clones it.FREERTOS_CPP11_SOURCESFREERTOS_CPP11_INCLUDE_DIRSThese sources are added to every generated executable to provide C++ threading integration on top of FreeRTOS.
The build uses a two-layer model:
Each selectable app/example is represented by an INTERFACE target that carries:
TARGET_NAME (final executable name)TARGET_PATH (source directory, for diagnostics)GATT_FILES (for BLE profile header generation)This pattern is used by:
libs/elec_c7222/examples/.../*.cmakegetting-started/getting-started.cmakeThe root CMake builds a unified APP_LIBS list:
C7222_EXAMPLES_BUILD=ON: append C7222_EXAMPLESC7222_GETTING_STARTED_BUILD=ON: append C7222_GETTING_STARTEDThen it iterates over APP_LIBS and creates one executable per interface library.
The helper library is defined in:
libs/elec_c7222/elec_c7222.cmakeIt creates the interface target:
ELEC_C7222and links the main subcomponents:
ELEC_C7222_DEVICES (from libs/elec_c7222/devices/devices.cmake)ELEC_C7222_UTILS (from libs/elec_c7222/utils/utils.cmake)ELEC_C7222_BLE (from libs/elec_c7222/ble/ble.cmake) when C7222_ENABLE_BLE=ONMost apps/examples only need to link against ELEC_C7222 to inherit the full library stack.
For each entry in APP_LIBS, root CMake:
TARGET_NAME, TARGET_PATH, optional GATT_FILES)add_executable(<TARGET_NAME> ${FREERTOS_CPP11_SOURCES})pico_stdlib, hardware libs)ELEC_C7222_GLIBCXX_HAS_GTHREADS=1_GLIBCXX_USE_C99_STDINT_TR1=1.elf, .uf2, etc.) via pico_add_extra_outputsGATT_FILES are present, runs pico_btstack_make_gatt_headerWhen C7222_EXPORT_PICO_UF2=ON (default), each built executable adds a post-build copy step:
${CMAKE_CURRENT_BINARY_DIR}/<TARGET_NAME>.uf2${CMAKE_BINARY_DIR}/images/<TARGET_NAME>.uf2This exported file is intended for direct copy to the Pico mass-storage drive that appears when the board is connected in BOOTSEL mode.
When an app/example interface library defines the GATT_FILES property, the root CMake iterates over those .gatt files and invokes the Pico SDK helper:
pico_btstack_make_gatt_header(<TARGET_NAME> PRIVATE "<file.gatt>")This generates a C header representation of the GATT database and wires it into the build of the executable target.
Overall, each app/example inherits a consistent platform/runtime baseline while contributing only its own sources through the interface library.
Default UART stdio behavior:
PICO_DEFAULT_UART_BAUD_RATE=921600, so default UART stdio output is configured for 921600 baud.When C7222_EXAMPLES_BUILD=ON, examples are loaded from:
libs/elec_c7222/examples/examples.cmakeCurrent set includes:
example-freertos-boardexample-freertos-device-cppexample-ble-gapexample-ble-gatt-serverBLE examples may append .gatt files to GATT_FILES for header generation.
Examples are registered as INTERFACE libraries and then collected into the global C7222_EXAMPLES list.
A typical example .cmake file does the following:
1) Create an interface library:
add_library(<EXAMPLE_LIB> INTERFACE)2) Set required metadata properties (used by the root executable-generation loop):
TARGET_NAME: the final executable nameTARGET_PATH: directory path for diagnostics/logging3) Add sources/includes:
target_sources(<EXAMPLE_LIB> INTERFACE ...)target_include_directories(<EXAMPLE_LIB> INTERFACE ...)4) (Optional) Register .gatt files:
GATT_FILES5) Add the example to the global list:
list(APPEND C7222_EXAMPLES <EXAMPLE_LIB>)See existing examples for the exact pattern:
libs/elec_c7222/examples/ble/gatt-server/ble-gatt-server-example.cmakelibs/elec_c7222/examples/ble/gap/ble-gap-example.cmakeWhen C7222_GETTING_STARTED_BUILD=ON, targets are loaded from:
getting-started/getting-started.cmakeTargets:
getting-started-freertos-cgetting-started-freertos-cppThese are configured along with the rest of enabled targets and are typically the first targets to debug.
Using CMake presets:
Or explicit configure/build:
Examples of option overrides:
Build a specific target:
This CMake design is intentionally centered on interface-library descriptors and one executable-generation loop to keep:
Serial console viewing options:
ms-vscode.vscode-serial-monitor (Serial Monitor)Serial Port Monitor (JetBrains)RTOS task/object visualization options:
xRTOS extension support in VS CodeThe project FreeRTOS configuration is set up to support these debugger views, including runtime-stats and trace-related options in libs/elec_c7222/config/FreeRTOSConfig.h together with runtime hooks in libs/elec_c7222/utils/platform/*/freertos_hooks.c.
To generate local API/docs output from this repository, install:
doxygendot tooldot is needed because the Doxygen configuration enables call/include/collaboration graphs (HAVE_DOT=YES).
macOS (Homebrew):
Ubuntu/Debian:
Windows (winget):
From repository root:
Output is generated under:
doc/elec-c7222/html/