Skip to content

Instantly share code, notes, and snippets.

@syedtaqi95
Last active July 19, 2024 11:38
Show Gist options
  • Save syedtaqi95/fd974211eeeb2a92a1b7c22b25a9ff69 to your computer and use it in GitHub Desktop.
Save syedtaqi95/fd974211eeeb2a92a1b7c22b25a9ff69 to your computer and use it in GitHub Desktop.
Debug Wiznet W6100-EVB-Pico (or other RP2040 boards) using a Raspberry Pi Debug Probe

Debug Wiznet W6100-EVB-Pico using a Raspberry Pi Debug Probe

This tutorial explains how to debug a Wiznet W6100-EVB-Pico (or other RP2040 boards) using a Raspberry Pi Debug Probe and Linux (Ubuntu) host PC using the terminal.

Getting Started

Hardware

  • Connect a USB cable from the Wiznet board to the host PC.
  • Connect a USB cable from the Debug Probe to the host PC.
  • Connect a 3-pin JST-SH to male cable from the "D" port of the Debug Probe to the SWD pins on the Wiznet board.

Note: Ensure the SWD pins are correctly connected. On the Debug Probe, the pins are SWCLK, GND and SWDIO from left to right. The SWD pins on the Wiznet board are labelled on the rear side of the PCB.

Software

Install openocd

sudo apt install openocd

Install GDB

sudo apt install gdb-multiarch

Install the Pico SDK

Taken from Getting started with Raspberry Pi Pico (Chapter 2).

Create a new project folder
cd
mkdir pico
cd pico
Clone the pico-sdk and pico-examples git repos
git clone https://github.com/raspberrypi/pico-sdk.git --branch master
cd pico-sdk
git submodule update --init
cd ..
git clone https://github.com/raspberrypi/pico-examples.git --branch master
Install the build toolchain
sudo apt update
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential libstdc++-arm-none-eabi-newlib

Building

We will build the blink example here as explained the Getting Started guide (Chapter 3).

Create a build directory

cd pico-examples
mkdir build
cd build

Set the PICO_SDK_PATH environment variable

export PICO_SDK_PATH=../../pico-sdk

Run cmake and make

cmake ..
cd blink
make -j4

This should build the .elf and .uf2 binaries in the blink directory.

Loading a Program

Taken from the Debug Probe documentation - Uploading new programs to your Pico.

Ensure you are inside the ../pico-examples/build/blink directory and run the following command to load the binary to the Wiznet board using openocd.

sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program blink.elf verify reset exit"

Debugging

Taken from the Debug Probe documentation - Debugging with SWD.

Create a debug build

To allow debugging, you must build a debug version of the blink example with CMAKE_BUILD_TYPE=Debug as shown below.

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 -j4

Start the OpenOCD server

sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"

Start the GDB debugger

In another terminal window, run the following commands to start GDB and attach it to the OpenOCD server.

gdb-multiarch blink.elf
target extended-remote localhost:3333

GDB commands

Run these commands inside the GDB shell.

Reset the board

This will reset the board, but the program will not start until the continue command is sent.

monitor reset init

Continue program execution

Execution runs until a breakpoint is hit or the user presses Ctrl+C.

continue

Set a breakpoint

Replace with the actual line number.

b blink.c:<line-number>

You can also use a function name, e.g. b blink.c:main.

List breakpoints

info breakpoints

Delete breakpoints

Replace with the actual breakpoint ID.

delete <breakpoint-id>

Step into

step

Step over

next

Step out

finish

Print the value of a variable

print <variable-name>

Print all local variables

info locals

List the source code around the current line

list

List the source code around a specific line

list <line-number>

Quit GDB

q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment