Nanopb

Nanopb is a C implementation of Google’s Protocol Buffers.

Requirements

Nanopb uses the protocol buffer compiler to generate source and header files, make sure the protoc executable is installed and available.

Use apt to install dependency:

sudo apt install protobuf-compiler

Additionally, Nanopb is an optional module and needs to be added explicitly to the workspace:

west config manifest.project-filter -- +nanopb
west update

Configuration

Make sure to include nanopb within your CMakeLists.txt file as follows:

list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
include(nanopb)

Adding proto files can be done with the zephyr_nanopb_sources() CMake function which ensures the generated header and source files are created before building the specified target.

Nanopb has generator options that can be used to configure messages or fields. This allows to set fixed sizes or skip fields entirely.

The internal CMake generator has an extension to configure *.options.in files automatically with CMake variables.

See samples/modules/nanopb/src/simple.options.in and samples/modules/nanopb/CMakeLists.txt for usage example.