EasyManuals Logo

Raspberry Pi Pico User Manual

Raspberry Pi Pico
77 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #23 background imageLoading...
Page #23 background image
Chapter 6. Debugging with SWD
As well as resetting the board, loading and running code, the SWD port on RP2040-based boards like Raspberry Pi Pico
can be used to interactively debug a program you have loaded. This includes things like:
Setting breakpoints in your code
Stepping through execution line by line
Inspecting the values of variables at different points in the program
Chapter 5 showed how to install OpenOCD to access the SWD port on your Raspberry Pi Pico. To debug code
interactively, we also need a debugger, such as the ubiquitous GNU Debugger, GDB.
Note that by default the SDK builds highly optimised program binaries, which can look very different in terms of control
flow and dataflow from the original program you wrote. This can be confusing when you try and step through the code
interactively, so it’s often helpful to create a debug build of your program which is less aggressively optimised, so that
the real on-device control flow is a closer match to your source code.
6.1. Build "Hello World" debug version
WARNING
When using SWD for debugging you need to use a UART based serial connection (see Chapter 4) as the USB stack
will be paused when the RP2040 cores are stopped during debugging, which will cause any attached USB devices to
disconnect. You cannot use a USB CDC serial connection during debugging.
You can build a debug version of the "Hello World"" 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 hello_world/serial
$ make -j4
6.2. Installing GDB
Install
gdb-multiarch,
$ sudo apt install gdb-multiarch
6.3. Use GDB and OpenOCD to debug Hello World
Ensuring your Raspberry Pi 4 and Raspberry Pi Pico are correctly wired together, we can attach OpenOCD to the chip, via
the
raspberrypi-swd interface.
Getting started with Raspberry Pi Pico
6.1. Build "Hello World" debug version 22

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Raspberry Pi Pico and is the answer not in the manual?

Raspberry Pi Pico Specifications

General IconGeneral
MicrocontrollerRP2040
Clock Speed133 MHz
SRAM264 KB
Flash Memory2 MB
GPIO Pins26
Operating Temperature-20°C to +85°C
ArchitectureARM Cortex-M0+ (dual-core)
InterfacesI2C, SPI, UART, PWM
Operating Voltage1.8–5.5 V
Dimensions51 mm × 21 mm

Related product manuals