pw_board_led: Add module

* Adds the STM32F429I-DSIC1 upstream Pigweed target.
* Adds the pw_board_led facade and two backends.
* Fixes pw_trace-related warnings.

Adds the pw_board_led facade and backend implementations for Teensy3/4
and the STM32F429I-DISC1.

Change-Id: I42d8a4142d67e2653217805631fbba29ed596e34
Reviewed-by: Anthony DiGirolamo <>
Reviewed-by: Keir Mierle <>
Commit-Queue: Armando Montanez <>
15 files changed
tree: 3eb977d4b3e8563143602de91420c12b01787875
  1. build_overrides/
  2. source/
  3. targets/
  4. third_party/
  5. tools/
  6. workshop/
  7. .gitignore
  8. .gitmodules
  9. .gn
  10. activate.bat
  11. banner.txt
  12. bootstrap.bat

Pigweed Sample Project

This repository outlines the recommended way of using Pigweed in a new or existing project. Feel free to fork this repository, or read it as a reference.

For more information see the Pigweed Getting started guide

Check back for more complex examples and features coming soon!

Repository setup

Clone this repo with --recursive to get all required submodules.

git clone --recursive

This will pull the Pigweed source repository into third_party/pigweed. If you already cloned but forgot to --recursive run git submodule update --init to pull all submodules.

Environment Setup

After cloning the build tools will need to be installed with the bootstrap scripts. This is only required after the initial clone or updating Pigweed.



Linux & Mac


bootstrap.bat and call the respective Pigweed bootstrap scripts. Feel free to modify them to set up your development environment for the first time.

After the initial bootstrap, use the activate scripts to setup your shell for development.



Linux & Mac



Make the project yours with your own banner! Edit banner.txt as desired :-D.


Generate the build files with gn gen out once, unless the build configuration has changed. Then, use ninja to build everything with ninja -C out.

The sample project examples have dependencies, each with some required build arguments. See the Arduino, and RPC sections for more setup information. The build arguments can be set with gn args out.

Pigweed's File System Watcher

Speed up iteration running pw watch on a new terminal window. This utility builds targets and runs tests when their files are modified. See the pw_watch documentation for more information.


Sample presubmit checks are included in tools/ To install them run python tools/ --install. See the pw_presubmit module documentation for more information.

Sample Application

The sample application in source/ uses the sample module simple_counter. Look at source/ and source/simple_counter/ to see how these are built respectively. The key part is in the root, which creates the host target using the host toolchain. A toolchain is required for each target.

Build the project and run the application.


Sample Test

The simple_counter module has tests defined in source/ Look at source/simple_counter/ for an example of how a test is defined. The root groups all the host tests together.

Build the project and run the tests.


Arduino Example


To build for Arduino boards you must install a core. At this time only the Teensyduino core is supported.

Check the Pigweed pw_arduino_build module documentation for detailed installation instructions. Cores should be installed into third_party/piwgweed/third_party/arduino.

Run this to install the Teensy core:

arduino_builder install-core \
  --prefix ./third_party/pigweed/third_party/arduino/cores/ \
  --core-name teensy

NOTE: At this time Teensyduino 1.53 does not build with the c++17 standard which is required for Pigweed. There is an open pull request to fix this but in the meantime you will need to patch the core files. This will download a diff and patch the relevant files:

pushd ./third_party/pigweed/third_party/arduino/cores/teensy/hardware/teensy/avr/cores/
curl -O
patch -p1 < teensy34_cpp17_patch.diff

Arduino Files in the sample_project

  • source/arduino_example
    • An example application that uses the Arduino API included in Arduino.h.
  • source/arduino_example/
    • Demonstrates how to include the Arduino core dependencies.
  • source/
    • A sample application that can be compiled for a supported Arduino board.
    • Shows how to create a target using the Arduino toolchain.
  • source/target/arduino
    • Contains a sample toolchain that inherits from the an Arduino toolchain in upstream pigweed. It can override backends as needed.


To build for a Teensy 3.1 board run the following.

gn gen out --args='
ninja -C out

Where arduino_board= is one of:

  • "teensy41" - Teensy 4.1
  • "teensy40" - Teensy 4.0
  • "teensy36" - Teensy 3.6
  • "teensy35" - Teensy 3.5
  • "teensy31" - Teensy 3.2 / 3.1

Running Tests

Tests can be manually flashed an run with the arduino_unit_test_runner and the .elf file.

arduino_unit_test_runner --verbose \
    --config-file ./out/arduino_debug/gen/arduino_builder_config.json \
    --upload-tool teensyloader \

If you would like to use the unit test server to automatically run your tests you must set the pw_arduino_use_test_server=true build arg and startup the test server. Then in a second window start the pw watch command.

  1. Start the test server in it's own terminal window.

    gn gen out --args='
    arduino_test_server --verbose \
      --config-file ./out/arduino_debug/gen/arduino_builder_config.json
  2. Start pw watch with the arduino target in a separate terminal.

    pw watch out arduino

For additional details check the Pigweed arduino_builder documentation in:

Tokenized Logging

Log entries in the sample app are tokenized to save binary space. The included tokens database, source/tokenizer_database.csv, is updated on each build. See the Pigweed pw_tokenizer for more information.

Optionally, the database can be created manually using the binary or the .elf file.

python -m pw_tokenizer.database create \
    --database source/tokenizer_database.csv \

Running the app shows log entries similiar to $kgjLdg==. These can be saved to a file and then detokenized.

./out/host_clang_debug/obj/source/bin/hello_world > log.txt
python -m pw_tokenizer.detokenize base64 source/tokenizer_database.csv -i log.txt

Or can be detokenized in realtime.

./out/host_clang_debug/obj/source/bin/hello_world | python \
    -m pw_tokenizer.detokenize base64 source/tokenizer_database.csv

RPC Example

The sample project uses nanopb for its pw_rpc dependency. The nanopb repo is conveniently included as a git submodule. This installation can be overridden following the instructions in third_party/pigweed/third_party/nanopb/ Then set dir_pw_third_party_nanopb to the new installation location when building. For example:

gn gen out --args='dir_pw_third_party_nanopb="third_party/nanopb"'

The sample application registers the EchoService, which echoes any RPC message data sent to it. To test it out build for and flash the desired board, then run:

python third_party/pigweed/pw_hdlc_lite/rpc_example/ \
    --device /dev/ttyACM0 --baud 115200

At the time of writing, the does not parse log statements if they are not framed in the HDLC protocol used by RPC. There is ongoing work on an RPC log service that will handle sending logs in HDLC frames to an RPC channel. In addition, the sample application uses tokenized logging, which means that logs need to be detokenized after the RPC HDLC frames are decoded on the host side. To do that flash the hello_word application and use two terminals to parse RPCs and detokenize logs respectively.

Terminal 1: receive RPCs.

python -m pw_hdlc_lite.rpc_console \
       -o logfile.txt \
       -d /dev/ttyACM0 \

Test Echo RPC:"hola")

Terminal 2: decode the logfile.

tail -f logfile.txt | python -m pw_tokenizer.detokenize \
    base64 source/tokenizer_database.csv