This repository contains the scaffolding for programming and debugging a Raspberry Pi Pico or Pico W.
It currently has a simple demo program that reads the raw angle from an AS5048A magnetic rotary position sensor over SPI and emits some output via UART and an LED.
Install the following tools:
- GDB (e.g., with
brew install arm-none-eabi-gdb
) - Minicom (e.g., with
brew install minicom
) - OpenOCD (e.g., with
brew install openocd
) - Toast (e.g., with
brew install toast
)
Then initialize the submodules with:
git submodule update --init
(cd pico-sdk && git submodule update --init)
Note: It might be tempting to just run git submodule update --init --recursive
, but that would take a long time and download more submodules than necessary.
You can build the project by running toast
. This will produce two output files: out.elf
and out.uf2
.
There are two ways to flash the code onto the microcontroller. The first way is via USB:
-
Plug the Raspberry Pi Pico into a USB port while holding the
BOOTSEL
button. -
Run this command, adjusting the path to the device as necessary:
cp image.uf2 /Volumes/RPI-RP2/
The code is now running. To flash new code, unplug the Pico and start again.
The second way to program it is with a Raspberry Pi Debug Probe that is connected to the Pico's SWD debug port:
openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c 'adapter speed 5000; program out.elf verify reset exit'
If you want to restart the code without reprogramming the microcontroller, run:
openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c 'adapter speed 5000; init; reset; exit'
To debug the code, first build the code in debug mode:
BUILD_TYPE=Debug toast
Then flash the code onto the Raspberry Pi Pico with the instructions above.
Now run the following command to start GDB servers:
openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c 'adapter speed 5000'
Then start GDB:
arm-none-eabi-gdb
Attach to one of the two cores with core0
or core1
. At this point the program will pause. The following commands are helpful:
continue
(c
): Resume execution^C
: Pause executionnext
(n
): Execute one step, treating subroutines as a single stepstep
(s
): Execute one step, including individual steps in subroutinesprint x
(p x
): Print the value of the variable namedx
break
(b
): Set a breakpointdelete
(d
): Delete a breakpointdisable
: Disable a breakpointenable
: Enable a breakpointlist .
(l .
): Show the code at the current locationwhere
: Show the current stack tracefinish
: Run the current function to completionquit
(q
): Quit
You can use a serial console to connect to the Raspberry Pi Pico or a Raspberry Pi Debug Probe connected to the Pico's UART pins:
-
Run Minicom, adjusting the path to the device as necessary:
minicom --device /dev/tty.usbmodem*
-
Press Meta + Q to quit.