The project software will be partially developed using multiple Raspberry PI Pico microcontroller boards. Subcomponents of the design will be breadboarded and tested before the initial prototype PCB is ordered. The Raspberry PI Debug Probe will be used to load and debug code.
The home page for the Raspberry PI RP2040 microcontroller is Raspberry PI RP2040 Microcontroller. Installation of the tools for use with the PI Pico are covered in “Getting started with Raspberry Pi Pico – C/C++ development with Raspberry Pi Pico and other RP2040-based microcontroller boards“. Chapter 2 of this guide describes tool installation for Linux. Chapter 9 covers tool installation on Apple macOS and on Microsoft Windows. I installed the tools on Ubuntu 22.04 running under “Windows Subsystem for Linux” (wsl2).
Windows Subsystem for Linux (WSL)
Install WSL (version 2) from the Microsoft store. By default, the latest version of the Ubuntu distribution is installed. You may choose a different Linux distribution. More details of the WSL installation can be found at WSL Install. You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 to install the latest version of WSL.
An advantage of WSL 2 is that allows Linux GUI applications. The procedure for installing and running Linux GUI applications is here. Run Linux GUI apps on the Windows Subsystem for Linux
Install the SDK and Toolchain
Install the SDK as described in section 2.1 of Chapter 2. Install the Toolchain following section 2.2. If installing on Ubuntu or Debian, pay attention to the NOTE at the end of this section. Update the SDK as described in section 2.3.
If you like follow on to Chapters 3 and 4 to verify the the example code builds and runs.
The C/C++ SDK is described in more detail in Raspberry Pi Pico C/C++ SDK – Libraries and tools for C/C++ development on RP2040 microcontrollers. Appendix D discusses board configuration. This information will be necessary to develop code to run on our custom board.
Raspberry PI Debug Probe
The Raspberry PI Debug Probe is a USB device that provides both a UART serial port and a standard Arm Serial Wire Debug (SWD) interface. It will be used both to flash code and to debug code via OpenOCD. This is the documentation for the Raspberry PI Debug Probe.
Install OpenOCD
To support debugging both cores, build OpenOCD from source code. Follow the instructions in the documentation starting after the first command in the Linux (and Raspberry Pi) section of the OpenOCD installation instructions.
When I ran the ./bootstrap command I got the following output on the terminal.
$ ./bootstrap
aclocal --warnings=all
configure.ac:32: error: Macro PKG_PROG_PKG_CONFIG is not available. It is usually defined in file pkg.m4 provided by package pkg-config.
configure.ac:32: the top level
autom4te: error: /usr/bin/m4 failed with exit status: 1
aclocal: error: autom4te failed with exit status: 1
I verified that pkg-config was not installed on my system using
$ dpkg -s pkg-config
Install pkg-config with the following commands.
$ sudo apt-get install -y pkg-config
$ sudo apt-get install -y pkg-config
After the successful installation of pkg-config, rerun the ./bootstrap command from the openocd directory. Continue with the installation as described in the documentation.
Install GDB
$ sudo apt install gdb-multiarch
Uploading Programs to the Pico
The Pico Debug Probes allows binary programs to be uploaded via the SWD port and OpenOCD. There is no need to push and hold the BOOTSEL button. Uploading new code becomes hands free. Change directory to the build directory of one of the pico examples; blink for example. Load the code with the debug probe as shown below. The connection fails. The problem is that the USB port is not connected to WSL2.
$ cd ~/pico/pico-examples/build/blink/
$ sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program blink.elf verify reset exit"
Open On-Chip Debugger 0.12.0-g4d87f6d (2023-08-18-11:16)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz
Error: unable to find a matching CMSIS-DAP device
** OpenOCD init failed **
shutdown command invoked
$
Open a windows PowerShell as Administrator, list the USB devices and attach the CMSIS-DAP interface device. Attaching the USB device failed.
The usbip client must be installed on the Ubuntu distribution. Install using the commands.
sudo apt install linux-tools-virtual hwdata
sudo update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20
Attaching the USB port from the Windows PowerShell should now succeed.
sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program blink.elf verify reset exit"
Open On-Chip Debugger 0.12.0-g4d87f6d (2023-08-18-11:16)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz
Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E6614103E73B5D2F
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x10000001
Info : [rp2040.core0] Cortex-M0+ r0p1 processor detected
Info : [rp2040.core0] target has 4 breakpoints, 2 watchpoints
Info : [rp2040.core1] Cortex-M0+ r0p1 processor detected
Info : [rp2040.core1] target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
[rp2040.core0] halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
[rp2040.core1] halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
** Programming Started **
Info : Found flash device 'win w25q16jv' (ID 0x001540ef)
Info : RP2040 B0 Flash Probe: 2097152 bytes @0x10000000, in 32 sectors
Warn : Adding extra erase range, 0x10002200 .. 0x1000ffff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
$
Debug a Program with SWD
In the GDB debugger.
$ sudo apt install gdb-multiarch
Rebuild pico-examples with CMAKE_BUILD_TYPE=Debug. If you have already set PICO_SDK_PATH in your ~/.bashrc file skip the “export” command. You can check the value of PICO_SDK_PATH with
$ echo $PICO_SDK_PATH
$ cd ~/pico/pico-examples
$ rm -rf build
$ mkdir build
$ cd build
$ export PICO_SDK_PATH=../../pico-sdk
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
$ cd blink
$ make
Attach OpenOCD via the SWD interface.
$ sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"
The output should look something like this.
Open On-Chip Debugger 0.12.0-g4d87f6d (2023-08-18-11:16)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E6614103E73B5D2F
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x10000001
Info : [rp2040.core0] Cortex-M0+ r0p1 processor detected
Info : [rp2040.core0] target has 4 breakpoints, 2 watchpoints
Info : [rp2040.core1] Cortex-M0+ r0p1 processor detected
Info : [rp2040.core1] target has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
Open a second terminal window. You can do this with a Shift-click on the WSL2 icon in the taskbar. In the newly opened terminal, change directory containing the built binary. Start GDB.
$ cd ~/pico/pico-examples/build/blink/
$ gdb-multiarch blink.elf
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
https://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"…
Reading symbols from blink.elf…
(gdb)
This starts the GDB command line debugger. You can get a text user interface to GDB using the -tui command line option.
$ gdb-multiarch -tui blin.exe
This gives you something like this.
A Graphical Interface to GDB
Microsoft Visual Studio Code (I couldn’t make this work.)
One potential graphical interface to GDB is Microsoft Visual Studio Code. can be used as a graphical user interface to GDB as well as a coding environment. Chapter 7 of “Getting Started with Raspberry PI Pico – C++ development with Raspberry PI Pico and other RP2040-based microcontroller boards“, provides instruction for installing VSCode A guide to installing and using Visual Studio Code on Raspberry Pi OS. I am using Ubuntu as my development OS. This link provides instructions for installing VSCode on Ubuntu 22.04. Note, I was not able to make this install work.
If you follow this procedure begin with the following command to become the root user. This will be required to write to root owned directories.
$ sudo -i
I followed this procedure. When I finished and typed the command to verify the install, I got the following output.
# code --version --user-data-dir
To use Visual Studio Code with the Windows Subsystem for Linux, please install Visual Studio Code in Windows and uninstall the Linux version in WSL. You can then use the code
command in a WSL terminal just as you would in a normal command prompt.
Do you want to continue anyway? [y/N] y
Following the se instructions, I uninstalled VSCode as follows.
# apt purge code
# apt autoremove
After installing VSCode in Windows from the Microsoft Store, I ran in from a Uduntu terminal as suggested. Here is the result.
$ code
/mnt/c/Users/glena/AppData/Local/Programs/Microsoft VS Code/bin/code: 61: /mnt/c/Users/glena/AppData/Local/Programs/Microsoft VS Code/Code.exe: Exec format error
One suggestion online to fix this issue was to edit the /etc/wsl.conf file in Ubuntu to disable systemd.
[boot]
systemd=false
This did not fix the problem for me. The error remained.
Install gdbgui
gdbgui is a browser based GUI for GDB. Therefore a browser, if not already present must be installed. I installed Google Chrome using the instructions from Microsoft’s WSL Gui-Apps Tutorial.
The recommended way to install gdbgui is to use pipx. I installed pipx as follows,
$ sudo apt update
$ sudo apt install pipx
and then used pipx to install gdbgui.
$ pipx install gdbgui
installed package gdbgui 0.15.1.0, installed using Python 3.10.12
These apps are now globally available
- gdbgui
⚠️ Note: '/home/glenafield/.local/bin' is not on your PATH environment variable. These apps will not be globally
accessible until your PATH is updated. Run pipx ensurepath
to automatically add it, or manually modify your PATH
in your shell's config file (i.e. ~/.bashrc).
done! ✨ 🌟 ✨
$ pipx ensurepath
Success! Added /home/glenafield/.local/bin to the PATH environment variable.
Consider adding shell completions for pipx. Run 'pipx completions' for instructions.
You will need to open a new terminal or re-login for the PATH changes to take effect.
Otherwise pipx is ready to go! ✨ 🌟 ✨
Using gdbgui
Using Windows Powershell as administrator make sure the the Pico Probe USB port is attached is attached to WSL.
Attach OpenOCD via the SWD interface.
$ sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"
Open a new Ubuntu terminal window. Shift-click on the WSL icon in the taskbar. Start Google Chrome in the background.
$ google-chrome&