Programming a PICO 2 on Debian

Programming a PICO 2 on Debian Trixie

Getting Started

Getting to a stage where you can compile code for a PICO is straightforward. Install VSCode, install the official PICO extension, load a demo and compile.
However, there are some difficulties when it comes to getting the program onto the PICO.

Programming the PICO

Straight out of the box

You can manually copy the uf2 onto the mounted drive. The PICO will automatically load and reset. Then each time you have a new build, unplug the PICO, hold down the BOOTSEL button, replug the usb cable, and move the uf2 again.
Tedious.

Automated

Alternatively, you can use 2 methods shown in the PICO extension:

  1. Run Project (USB) - still requires the unplug, bootsel, replug steps
  2. Flash Project (SWD) - requires a Raspberry Pi Debug Probe PICO Debug Probe (there are other methods I didn't explore)
However, both methods have the same root issue on Debian Trixie; incorrect permissions to access the device(s).
The 2nd method has another issue.

Fixing the Issues

            
*  Executing task: /home/jon/.pico-sdk/picotool/2.2.0-a4/picotool/picotool load /home/jon/blink/build/blink.elf -fx 
  No accessible RP-series devices in BOOTSEL mode were found.
*  The terminal process "/home/jon/.pico-sdk/picotool/2.2.0-a4/picotool/picotool 'load', '/home/jon/blink/build/blink.elf', '-fx'" failed to launch (exit code: 249). 
            
          
or
            
*  Executing task: /home/jon/.pico-sdk/openocd/0.12.0+dev/openoc.exe -s /home/jon/.pico-sdk/openocd/0.12.0+dev/scripts -f interface/cmsis-dap.cfg -f target/rp2350.cfg -c adapter speed 5000; program "/home/jon/blink/build/blink.elf" verify reset exit 
    /home/jon/.pico-sdk/openocd/0.12.0+dev/openocd.exe: error while loading shared libraries: libhidapi-hidraw.so.0: cannot open shared object file: No such file or directory
*  The terminal process "/home/jon/.pico-sdk/openocd/0.12.0+dev/openocd.exe '-s', '/home/jon/.pico-sdk/openocd/0.12.0+dev/scripts', '-f', 'interface/cmsis-dap.cfg', '-f', 'target/rp2350.cfg', '-c', 'adapter speed 5000; program "/home/jon/blink/build/blink.elf" verify reset exit'" failed to launch (exit code: 127). 
*  Terminal will be reused by tasks, press any key to close it. 
            
          
For the missing library issue, install the package libhidapi-hidraw0. The permissions issue can be solved by adding udev rules. One for the PICO 2, the other for the Debug Probe.
            
jon@DEBIANPC:~$ cat /etc/udev/rules.d/90-openocd.rules 
# RPI Pico2
ATTR{idVendor}=="2e8a", ATTRS{idProduct}=="000f", MODE="0666"
# Debug Probe
ATTR{idVendor}=="2e8a", ATTRS{idProduct}=="000c", MODE="0666"
            
          
Then reload the udev rules with:
            
sudo udevadm control --reload-rules && sudo udevadm trigger
            
          

Arduino

You can skip all of this and use the Arduino IDE to program the PICO2 with the arduino-pico repo.
Straightforward, but it's not to everyone tastes to use that IDE.