Raspberry Pi Pico#
Pigweed AI summary: The Raspberry Pi Pico target is currently in an early state and under active development. Usability is not very polished, and many features and configuration options that work in the upstream Pi Pico CMake build have not yet been ported to the GN build. To use this target, Pigweed must be set up to build against the Raspberry Pi Pico SDK, which can be downloaded via "pw package". The build must then be manually configured to point to the location of the downloaded SDK. On
Warning
This target is in an early state and is under active development. Usability is not very polished, and many features/configuration options that work in upstream Pi Pico CMake build have not yet been ported to the GN build.
Setup#
Pigweed AI summary: This section provides instructions on how to set up Pigweed to build against the Raspberry Pi Pico SDK. The SDK can be downloaded using "pw package" and the build must be manually configured to point to the location of the downloaded SDK. For Linux users, there are additional instructions on updating udev rules.
To use this target, Pigweed must be set up to build against the Raspberry Pi
Pico SDK. This can be downloaded via pw package
, and then the build must be
manually configured to point to the location of the downloaded SDK.
pw package install pico_sdk
gn args out
# Add this line.
PICO_SRC_DIR = getenv("PW_PACKAGE_ROOT") + "/pico_sdk"
Linux#
Pigweed AI summary: This paragraph provides instructions for updating udev rules on Linux, specifically in the file /etc/udev/rules.d/49-pico.rules. The provided code should be added to the file to ensure proper functionality of certain USB devices.
On linux, you may need to update your udev rules at
/etc/udev/rules.d/49-pico.rules
to include the following:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0004", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0004", MODE:="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE:="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000a", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000a", MODE:="0666"
Usage#
Pigweed AI summary: The Pi Pico can output logs and test results over USB serial at a baud rate of 115200. Once the pico SDK is configured, the Pi Pico will build as part of the default GN build using the command "ninja -C out". Pigweed's build will produce ELF and UF2 files for each unit test built for the Pi Pico.
The Pi Pico is configured to output logs and test results over USB serial at a baud rate of 115200.
Once the pico SDK is configured, the Pi Pico will build as part of the default GN build:
ninja -C out
Pigweed’s build will produce ELF and UF2 files for each unit test built for the Pi Pico.
Flashing#
Pigweed AI summary: To flash the Pi Pico, simply hold the button on the device and connect it to your computer via the micro USB port. Then, copy the desired UF2 firmware image to the RPI-RP2 volume that appears when you connect the Pico.
Flashing the Pi Pico is two easy steps:
While holding the button on the Pi Pico, connect the Pico to your computer via the micro USB port.
Copy the desired UF2 firmware image to the RPI-RP2 volume that enumerated when you connected the Pico.
Testing#
Pigweed AI summary: The RP2040 does not automatically run tests on boot. To run a test, you need to flash it to the RP2040, connect to the serial port, and press the spacebar to start the test. The RP2040 waits for the space character as a signal to start running the tests because the serial port enumerated by the Pi Pico goes away on reboot. The RP2040 does not currently have an automated test runner with build system integration. However, there is an automated test
Unlike some other targets, the RP2040 does not automatically run tests on boot. To run a test, flash it to the RP2040 and connect to the serial port and then press the spacebar to start the test:
$ python -m serial.tools.miniterm --raw /dev/ttyACM0 115200
--- Miniterm on /dev/cu.usbmodem142401 115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---INF [==========] Running all tests.
INF [ RUN ] Status.Default
INF [ OK ] Status.Default
INF [ RUN ] Status.ConstructWithStatusCode
INF [ OK ] Status.ConstructWithStatusCode
INF [ RUN ] Status.AssignFromStatusCode
INF [ OK ] Status.AssignFromStatusCode
INF [ RUN ] Status.Ok_OkIsTrue
INF [ OK ] Status.Ok_OkIsTrue
INF [ RUN ] Status.NotOk_OkIsFalse
INF [ OK ] Status.NotOk_OkIsFalse
INF [ RUN ] Status.Code
INF [ OK ] Status.Code
INF [ RUN ] Status.EqualCodes
INF [ OK ] Status.EqualCodes
INF [ RUN ] Status.IsError
INF [ OK ] Status.IsError
INF [ RUN ] Status.IsNotError
INF [ OK ] Status.IsNotError
INF [ RUN ] Status.Strings
INF [ OK ] Status.Strings
INF [ RUN ] Status.UnknownString
INF [ OK ] Status.UnknownString
INF [ RUN ] Status.Update
INF [ OK ] Status.Update
INF [ RUN ] StatusCLinkage.CallCFunctionWithStatus
INF [ OK ] StatusCLinkage.CallCFunctionWithStatus
INF [ RUN ] StatusCLinkage.TestStatusFromC
INF [ OK ] StatusCLinkage.TestStatusFromC
INF [ RUN ] StatusCLinkage.TestStatusStringsFromC
INF [ OK ] StatusCLinkage.TestStatusStringsFromC
INF [==========] Done running all tests.
INF [ PASSED ] 15 test(s).
This is done because the serial port enumerated by the Pi Pico goes away on reboot, so it’s not safe to run tests until the port has fully enumerated and a terminal has connected. To avoid races, the Pico will just wait until it receives the space character (0x20) as a signal to start running the tests.
The RP2040 does not yet provide an automated test runner with build system integration.
Automated test runner#
Pigweed AI summary: The automated test runner is a target that allows on-device tests to be run as part of the GN build. It uses a custom script called "pw_unit_test_AUTOMATIC_RUNNER" to automate the process. The first step is to start a test server, which Ninja will send test requests to. By default, the script will detect a Pi Pico with USB serial enabled for testing, but this can be overridden with a custom server configuration file. If no devices are found, ensure that the Pi
This target supports automatically running on-device tests as part of the GN
build thanks to a custom pw_unit_test_AUTOMATIC_RUNNER
script.
Step 1: Start test server#
Pigweed AI summary: To run tests on a device using Ninja, a test server needs to be started. The server receives test requests from Ninja and runs them in the background. By default, the server will automatically detect a connected Pi Pico with USB serial enabled and use it for testing. However, a custom server configuration file can be provided to override this behavior. To start the test server, run the command "python -m rp2040_utils.unit_test_server". If no devices are found, make sure the Pi
To allow Ninja to properly serialize tests to run on device, Ninja will send
test requests to a server running in the background. The first step is to launch
this server. By default, the script will attempt to automatically detect an
attached Pi Pico running an application with USB serial enabled, then using
it for testing. To override this behavior, provide a custom server configuration
file with --server-config
.
$ python -m rp2040_utils.unit_test_server
Tip
If the server can’t find any attached devices, ensure your Pi Pico is already running an application that utilizes USB serial.
Warning
If you connect or disconnect any boards, you’ll need to restart the test server for hardware changes to take effect.
Step 2: Configure GN#
Pigweed AI summary: The paragraph explains that the hardware target has incremental testing disabled by default. However, by enabling the "pw_targets_ENABLE_RP2040_TEST_RUNNER" build argument, GN will send requests to a running "rp2040_utils.unit_test_server". The provided code snippet shows how to modify and save the arguments file to enable the "pw_target_runner".
By default, this hardware target has incremental testing disabled. Enabling the
pw_targets_ENABLE_RP2040_TEST_RUNNER
build arg tells GN to send requests to
a running rp2040_utils.unit_test_server
.
$ gn args out
# Modify and save the args file to use pw_target_runner.
pw_targets_ENABLE_RP2040_TEST_RUNNER = true
Step 3: Build changes#
Pigweed AI summary: In Step 3: Build changes, running the command "ninja -C out pi_pico" will rebuild and run all tests that have been affected by changes since the last build. Another option is to use "pw watch" to set up Pigweed to automatically trigger builds and tests whenever changes are made to source files.
Now, whenever you run ninja -C out pi_pico
, all tests affected by changes
since the last build will be rebuilt and then run on the attached device.
Alternatively, you may use pw watch
to set up Pigweed to trigger
builds/tests whenever changes to source files are detected.