|author||pigweed-integration-roller <email@example.com>||Fri Oct 16 23:29:47 2020 +0000|
|committer||CQ Bot Account <firstname.lastname@example.org>||Fri Oct 16 23:34:09 2020 +0000|
[roll third_party/pigweed] pw_build: add "-Wundef" to strict_warnings Adds "-Wundef" to "strict_warnings" to catch use of accidentally undefined macros which otherwise implicitly default to 0. Updates macros across Pigweed to make it compile. Drops support for PW_TEST_DONT_DEFINE_* in addition to GTEST_DONT_DEFINE_*, instead only GTEST_DONT_DEFINE_* is used. Original-Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/21463 Rolled-Commits: 7a436e0697b6a03..e4d7b690c861bf7 CQ-Do-Not-Cancel-Tryjobs: true Change-Id: I3406de3ebe680da1c8bbd52254d93729499e5d5c Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/sample_project/+/21687 Reviewed-by: Pigweed Integration Roller <email@example.com> Commit-Queue: Pigweed Integration Roller <firstname.lastname@example.org>
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!
The preferred method to add the Pigweed source is to use git submodules and place the Pigweed source repository in
third_party/pigweed. If you forked this repository, don't forget to run
git submodule init and
git submodule update.
bootstrap.bat for Windows, and
bootstrap.sh for Unix systems call the respective Pigweed bootstrap scripts. Feel free to modify them to set up your development environment for the first time.
After the initial setup, use the
activate.bat in Windows or
activate.sh in Unix to enter the environment in a shell.
Make the project yours with your own banner. Create your own banner and place it in
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.
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/presubmit_checks.py. To install them run
python tools/presubmit_checks.py --install. See the
pw_presubmit module documentation for more information.
The sample application in
source/main.cc uses the sample module
simple_counter. Look at
source/simple_counter/BUILD.gn to see how these are built respectively. The key part is in the root
BUILD.gn, which creates the host target using the host toolchain. A toolchain is required for each target.
Build the project and run the application.
simple_counter module has tests defined in
source/simple_counter_tests.cc. Look at
source/simple_counter/BUILD.gn for an example of how a test is defined. The root
BUILD.gn groups all the host tests together.
Build the project and run the tests.
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 \ out/host_clang_debug/obj/source/bin/hello_world
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
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
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 the Teensyduino core 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 https://gist.githubusercontent.com/AnthonyDiGirolamo/9368d2879d9aec6be4118e72c2b0cf46/raw/0afc6c182dcb3aac5af3f05d54c4d2c7d941b52d/teensy34_cpp17_patch.diff patch -p1 < teensy34_cpp17_patch.diff popd
To build for a Teensy 3.1 board run the following.
gn gen out --args=' dir_pw_third_party_arduino="//third_party/pigweed/third_party/arduino" arduino_board="teensy31"' ninja -C out
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
Tests can be manually flashed an run with the
arduino_unit_test_runner and the
arduino_unit_test_runner --verbose \ --config-file ./out/arduino_debug/gen/arduino_builder_config.json \ --upload-tool teensyloader \ out/arduino_debug_tests/obj/source/simple_counter/test/simple_counter_test.elf
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.
Start the test server in it's own terminal window.
gn gen out --args=' dir_pw_third_party_arduino="//third_party/pigweed/third_party/arduino" arduino_core_name="teensy" arduino_board="teensy40" pw_arduino_use_test_server=true' arduino_test_server --verbose \ --config-file ./out/arduino_debug/gen/arduino_builder_config.json
pw watch with the
arduino target in a separate terminal.
pw watch out arduino
For additional details check the Pigweed
arduino_builder documentation in:
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/BUILD.gn. 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/example_script.py \ --device /dev/ttyACM0 --baud 115200
At the time of writing, the
example_script.py 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.
source activate.sh python -m pw_hdlc_lite.rpc_console \ -o logfile.txt \ -d /dev/ttyACM0 \ ./third_party/pigweed/pw_rpc/pw_rpc_protos/echo.proto
Test Echo RPC:
Terminal 2: decode the logfile.
source activate.sh tail -f logfile.txt | python -m pw_tokenizer.detokenize \ base64 source/tokenizer_database.csv