7. Flash your Pico#

Enough with the simulations. Let’s work with some real hardware! You’ll need a physical Raspberry Pi Pico for the rest of the tutorial. You can use any version of the Pico: Pico 1, Pico 1W, Pico 2, or Pico 2W. We support them all.

Set up your hardware#

Follow the instructions in one of the following tabs (Full setup, Pico and Enviro+, or Pico only) to set up your hardware. The full setup provides the most robust experience. Some later pages in the tutorial require the full setup.

In the full setup, you combine a Pico, Enviro+ Pack, Debug Probe, and Omnibus. The Debug Probe provides more robust flashing and debugging. The Omnibus provides the Debug Probe access to the Pico’s UART pins. These UART pins aren’t accessible when a Pico is connected directly to an Enviro+.

By the end of the instructions your full setup will look similar to this:

https://storage.googleapis.com/pigweed-media/sense/full_setup_zoom_v1.jpg

Update the Debug Probe firmware

  1. Connect the Debug Probe to your development host over USB.

  2. Update the Debug Probe firmware. You just need to download the latest release and drag-and-drop the UF2 file onto your Debug Probe. You want the debugprobe.uf2 file from the releases page. It only takes a minute or two.

Omnibus setup

  1. Connect the Enviro+ to Deck 1 on the Omnibus.

  2. Connect the Pico to the middle landing area on the Omnibus.

    Important

    Make sure that the Pico’s USB port lines up with the USB label on the Omnibus.

https://storage.googleapis.com/pigweed-media/sense/omnibus_v1.jpg

Serial Wire Debug port setup

  1. Find the Serial Wire Debug (SWD) port on your Pico. On the Pico 1 and Pico 2 the SWD port is at the edge of the board. On the Pico 1W and Pico 2W it’s near the middle of the board. The front of the Pico (the side with the raspberry logo) has a DEBUG label close to the port.

  2. Determine if your Serial Wire Debug (SWD) port has male or female connectors.

    If it’s male, follow the instructions in the Male tab in the next step. If female, use the Female tab instructions.

    https://storage.googleapis.com/pigweed-media/sense/swd_v1.jpg
  3. Connect the SWD port on your Debug Probe to the SWD port on your Pico.

    1. Connect the inner cable of the Debug Probe (SC) to the SWCLK pin on the Pico’s debug port. The back of the Pico (the side that does not have the raspberry logo) has a SWCLK label showing the location of that pin.

      Tip

      The image caption below provides an example of what we mean by “inner cable” (as well as “middle” and “outer”). The colors on these types of cables aren’t standardized, so we had to think up a different way to describe them.

    2. Connect the middle cable (ground) to the GND pin on the Pico’s debug port.

    3. Connect the outer cable (SD) to the SWDIO pin on the Pico’s debug port.

    https://storage.googleapis.com/pigweed-media/sense/debug_male_v1.jpg
    https://storage.googleapis.com/pigweed-media/sense/debug_male_zoom_v2.jpg

    In these images the “inner” cable is the white cable, the red cable is the “middle” cable, and the black cable is the “outer” cable.#

    1. Connect the DEBUG port on the Pico with the DBUG port on the Debug Probe using the JST-SH to JST-SH cable. JST-SH connectors only fit in one direction.

    https://storage.googleapis.com/pigweed-media/sense/debug_v3.jpg

UART setup

  1. Connect the inner cable (RX, input to Debug Probe) to pin 0 on Deck 2 of the Omnibus.

  2. Connect the outer cable (TX, output from Debug Probe) to pin 1 on Deck 2 of the Omnibus.

  3. Connect the middle cable (ground) to any of the pins labeled with a long dash () on Deck 2.

https://storage.googleapis.com/pigweed-media/sense/uart_v1.jpg
https://storage.googleapis.com/pigweed-media/sense/uart_zoom_v1.jpg

In the previous 2 images the “inner cable” is the yellow cable, the “middle” cable is the black cable, and the “outer” cable is the orange cable.#

Note

The Serial Wire Debug port connections from the last section are omitted from the previous two images to help you focus on the new UART cable connections. Don’t remove your SWD port connections.

USB setup

  1. Hold down the BOOTSEL button on the front of your Pico (the side with the raspberry logo) to prepare the Pico for flashing.

  2. While still holding down BOOTSEL, connect your Pico to a USB port on your development host or to a separate power supply.

    Tip

    Connecting to a separate power supply will slightly simplify the flashing process later.

  3. Connect your the USB Micro-B port on your Debug Probe to a USB port on your development host. If you updated the Debug Probe firmware earlier, your Probe may already be connected to your host.

You’re done! Your setup should look similar to this:

https://storage.googleapis.com/pigweed-media/sense/full_setup_v1.jpg
  1. Connect the Pico to the Enviro+ Pack.

  2. Hold down the BOOTSEL button on the front of your Pico (the side with the raspberry logo) to prepare the Pico for flashing.

  3. While still holding down BOOTSEL, connect your Pico to a USB port on your development host.

https://storage.googleapis.com/pigweed-media/sense/basic_enviro_front_v1.jpg
https://storage.googleapis.com/pigweed-media/sense/basic_enviro_back_v1.jpg
  1. Hold down the BOOTSEL button on the front of your Pico (the side with the raspberry logo) to prepare the Pico for flashing.

  2. While still holding down BOOTSEL, connect your Pico to a USB port on your development host.

https://storage.googleapis.com/pigweed-media/sense/basic_v1.jpg

Set up udev rules#

  1. Configure your host to properly detect Raspberry Pi hardware.

    1. Add the following rules to /etc/udev/rules.d/49-pico.rules or /usr/lib/udev/rules.d/49-pico.rules. Create the file if it doesn’t exist. You will probably need superuser privileges (sudo) to create or edit this file.

      # RaspberryPi Debug probe: https://github.com/raspberrypi/debugprobe
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000c", MODE:="0666"
      KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000c", MODE:="0666"
      # RaspberryPi Legacy Picoprobe (early Debug probe version)
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0004", MODE:="0666"
      KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0004", MODE:="0666"
      
      # RP2040 Bootloader mode
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE:="0666"
      KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0003", MODE:="0666"
      # RP2040 USB Serial
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000a", MODE:="0666"
      KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000a", MODE:="0666"
      
      # RP2350 Bootloader mode
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000f", MODE:="0666"
      KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000f", MODE:="0666"
      # RP2350 USB Serial
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0009", MODE:="0666"
      KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="0009", MODE:="0666"
      
    2. Reload the rules:

      sudo udevadm control --reload-rules && sudo udevadm trigger
      
    3. If your Pico is already connected to your host, unplug it and plug it back in again. Hold down the BOOTSEL button on the front of the Pico while plugging it back in to ensure that the Pico is ready for flashing.

    No extra setup needed.

Flash an application binary to your Pico#

  1. Flash the blinky bringup program to your Pico.

    1. In Bazel Targets expand //apps/blinky and find your board’s target:

      • If your board is a Pico 1 or Pico 1W then your board’s target is flash_rp2040.

      • If your board is a Pico 2 or Pico 2W then your board’s target is flash_rp2350.

        RP2040 is the name of the MCU that powers first-generation Picos. The RP2350 powers second-generation Picos.

    2. Right-click your board’s target then select Run target.

    3. If you’ve connected both the Debug Probe and Pico to your host over USB, you’ll see the following prompt. (If your Pico is connected to a separate power supply, you won’t see this prompt and can ignore this part.) Select Raspberry Pi - Debug Probe (CMSIS-DAP).

      Multiple devices detected. Please select one:
        1 - bus 3, port 1 (Raspberry Pi - Debug Probe (CMSIS-DAP))
        2 - bus 3, port 6 (Raspberry Pi - Pico)
      

      In this example you would want to select 1.

    A successful flash looks similar to this:

    https://storage.googleapis.com/pigweed-media/sense/20240802/flash.png
    1. Flash your Pico.

      bazelisk run //apps/blinky:flash_rp2040
      
      bazelisk run //apps/blinky:flash_rp2350
      
    2. If you’ve connected both the Debug Probe and Pico to your host over USB, you’ll see the following prompt. (If your Pico is connected to a separate power supply, you won’t see this prompt and can ignore this part.) Select Raspberry Pi - Debug Probe (CMSIS-DAP).

      Multiple devices detected. Please select one:
        1 - bus 3, port 1 (Raspberry Pi - Debug Probe (CMSIS-DAP))
        2 - bus 3, port 6 (Raspberry Pi - Pico)
      

    You should see output like this:

    20241220 19:46:38 INF Flashing bus 3 port 6
    

The LED on your Pico should start blinking on and off at a 1-second interval.

Troubleshooting

If you see A connected device has an inaccessible serial number: The device has no langid (permission issue, no string descriptors supported or device error) it probably means you need to update your udev rules. See Set up udev rules.

If you see Error: Connecting to the chip was unsuccessful or ERROR: This file cannot be loaded into the partition table on the device, make sure that you’re using the correct flashing target. These errors suggest that you tried to use the Pico 1 target on a Pico 2 board, or vice versa.

Summary#

In a Bazel-based project like Sense there is no separate flashing process. Flashing is a Bazel target, just like building and testing the source code are Bazel targets. Your team can manage all core development workflows through Bazel.

Next, head over to 8. Run on-device tests to try out on-device unit tests.