EasyManuals Logo

Raspberry Pi RP2040 User Manual

Raspberry Pi RP2040
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 RP2040 and is the answer not in the manual?

Raspberry Pi RP2040 Specifications

General IconGeneral
ProcessorDual-core Arm Cortex-M0+
Clock Speed133 MHz
SRAM264 KB
GPIO30
USBUSB 1.1 Host/Device
PWM16 channels
UART2
SPI2
I2C2
Temperature Range-20°C to +85°C
Operating Voltage1.8V to 3.3V
FlashExternal QSPI flash
I/O InterfacesSPI, I2C, UART, PWM
ADC4 × 12-bit ADC channels

Related product manuals