关于调试探头

debug probe

Raspberry Pi调试探头是一款USB设备,提供UART串行端口和标准Arm串行线调试(SWD)接口。该探头设计为易于使用、无需焊接、即插即用的调试方式。它具有以下功能:

  • USB转Arm串行线调试(SWD)端口

  • USB 转 UART 桥

  • 兼容CMSIS-DAP标准

  • 配合OpenOCD以及其他支持CMSIS-DAP的工具

  • 开源、易于升级的固件

有关Raspberry Pi三针调试连接器的更多信息,请参阅规范.

这使得在Windows、macOS和Linux等缺少GPIO接口的平台上轻松使用Raspberry Pi Pico成为可能,可直接连接到Pico的串行UART或SWD端口。

调试探头

探头工作电压为3.3V标称I/O电压。

the probe

调试探头附赠USB电源线和三根调试线:

  • 三针JST-SH连接器转三针JST-SH连接器线缆

  • 三针JST-SH连接器转0.1英寸插针(母头)线缆

  • 三针JST-SH连接器转0.1英寸插针(公头)线缆

两根0.1英寸插针线缆——用于面包板(公头)或直接连接带插针的电路板(母头)——颜色如下:

橙色

TX/SC(探头输出)

黑色

GND

黄色

RX/SD(探头输入或I/O)

三针JST-SH连接器线缆旨在与标准三针连接器这是较新的 Raspberry Pi 主板用于 SWD 调试端口和 UART 连接器的接口。

当目标板由独立电源或计算机供电时,请在连接信号线之前确保有公共参考点。先从目标板断开电源,或先连接目标板与 Raspberry Pi Debug Probe 之间的 GND;连接 GND 后,您可以连接 RX、TX、SC 和 SD。两个系统之间的潜在电压差可能会损坏调试探针。

Debug Probe 有五个 LED,一个红色 LED 用于指示电源,另外四个是活动指示灯

debug leds
OpenOCD 在连接目标时打开两个 DAP LED,并在调用时将其关闭DAP_DISCONNECT.

入门指南

labelled wiring

根据您的设置,有几种方法可以将 Debug Probe连接到Pico 系列设备。下面,我们将 Debug Probe 连接到 Raspberry Pi Pico H,该主板具有用于 SWD 的新型三针 JST-SH 连接器。

连接以下内容:

  • Debug Probe 的"D"端口到 Pico H SWD JST-SH 连接器

  • Debug Probe 的"U"端口,使用三针 JST-SH 连接器转 0.1 英寸排针(公头):

    • Debug ProbeRX connected to Pico H TX pin

    • Debug ProbeTX connected to Pico H RX pin

    • Debug ProbeGND connected to Pico H GND pin

如果您使用的是非 H 版 Pico 或 Pico W(没有 JST-SH 连接器),仍然可以连接到 Debug Probe。请在SWCLK, GND, and SWDIO header pins on the board. Using the alternate 3-pin JST-SH connector to 0.1-inch header (female) cable included with the Debug Probe, connect to the Debug Probe "D" port. Connect SWCLK, GND, and SWDIO on the Pico or Pico W to the SC (orange wire), GND (black wire), and SD (yellow wire) pins on the Debug Probe, respectively.

wiring

安装工具

要使用 Debug Probe,需要 OpenOCD 和 GNU Project Debugger (GDB)。集成开发环境 (IDE) 也可能会有所帮助。

在 Raspberry Pi OS、大多数 Linux 发行版、macOS 和 Microsoft Windows 上,我们建议安装我们的 VS Code 扩展。此扩展捆绑了 OpenOCD、Arm 工具链、GDB 以及 Pico 系列微控制器的寄存器定义。

有关更多信息,请参阅我们的Raspberry Pi Pico 入门指南指南中找到完整的操作说明。

或者,可以按照该指南的附录 C 手动安装工具。

不建议在 Windows 上手动安装这些工具。

开始调试会话

Debug Probe 允许您通过 SWD 端口和 OpenOCD 加载二进制文件:您不需要每次将新二进制文件推送到 Pico 时都拔出并按住 BOOTSEL 按钮。使用 Debug Probe 上传新二进制文件是完全自动化的过程。

然后使用 GDB 调试在 Pico 上运行的二进制文件。

我们建议使用 Raspberry Pi Pico VSCode 扩展,它集成了 OpenOCD 和 GDB 的使用,用于上传和调试程序。请参阅开始使用 Raspberry Pi Pico获取更多信息。

独立程序上传

构建二进制文件后:

$ sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program blink.elf verify reset exit"
使用 Debug Probe 上传二进制文件时,使用的是文件的 ELF 版本,而不是拖放时使用的 UF2 文件。

独立调试会话

这将使用openocd in server mode, and connect GDB, which gives you breakpoints and single-step over a console interface.

为了允许调试,您必须将二进制文件构建为Debug rather than Release build type, for example,

$ 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

在调试构建中,当您在调试器下运行它时将获得更多信息,因为编译器在构建程序时包含了告诉 GDB 程序正在做什么的信息。

对于计算机来说先拔下连接器的一端需要GDB的ARM处理器调试变体来调试Raspberry Pi设备。根据您的操作系统和设备,请使用以下替代方案之一: * 在Linux设备上,使用gdb-multiarch. * On macOS and Windows devices, use arm-none-eabi-gdb from the toolchain on Arm的Gitlab仓库

要启动OpenOCD服务器,请运行以下命令:

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

然后打开第二个终端窗口,切换到包含已编译二进制文件的目录,并启动调试器以连接到OpenOCD服务器:

$ gdb blink.elf
> target remote localhost:3333
> monitor reset init
> continue

串行连接

确保调试探针已连接到Raspberry Pi Pico的UART引脚。

wiring

Raspberry Pi Pico UART0的默认引脚如下:

默认UART0 物理引脚 GPIO引脚

GND

3

不适用

UART0_TX

1

GP0

UART0_RX

2

GP1

连接后,Raspberry Pi Pico的UART通信将通过调试探针中继到计算机,并显示为CDC UART。在Raspberry Pi上,这将显示为/dev/ttyACM0; on other platforms this serial port will show up differently (for example, on macOS it will appear as /dev/cu.usbmodemXXXX).

如果尚未安装,请安装minicom:

$ sudo apt install minicom

并打开串行端口:

$ minicom -b 115200 -o -D /dev/ttyACM0
要退出minicom, use CTRL-A followed by X.

要测试串行通信,您可以构建并上传"Hello World"示例应用程序。

更改目录到hello_world directory inside the pico-examples tree, and run make. Afterwards, you can upload it to your Raspberry Pi Pico using openocd. For a full walkthrough of building the hello_serial example program, see Chapter 4 of 开始使用 Raspberry Pi Pico.

$ cd pico-examples
$ mkdir build
$ cd build
$ export PICO_SDK_PATH=../../pico-sdk
$ cmake ..
$ cd hello_world/serial
$ make -j4
$ sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program hello_serial.elf verify reset exit"
$ minicom -b 115200 -o -D /dev/ttyACM0

打开minicom, you see "Hello, world!" printed to the console.

对于支持它的终端程序,USB串行UART的描述会在USB设备描述中广告。

description

此描述中的唯一序列号意味着在Windows上您的COM端口编号是每个设备的"粘性"编号,并将允许您编写udev rules to associate a named device node with a particular Debug Probe.

RTT连接

您还可以配置应用程序以直接通过SWD接口发送其输出,而无需UART连接。这使用一种称为Segger实时传输(RTT)的机制。

为此,您必须在应用程序中启用 RTT 标准输入输出驱动,并通过调试探针连接到 RTT。

您必须使用调试版本的应用程序才能通过 SWD 发送输出。

启用 RTT 标准输入输出驱动

C/C++ SDK 为 RTT 提供了一个标准输入输出驱动,与用于 UART 和 USB 的驱动类似。更多信息请参见pico_stdio_rtt.

要在构建中启用该驱动,请在您的CMakeLists.txt文件中加入以下一行(或链接pico_stdio_rtt,其效果相同):

pico_enable_stdio_rtt(<your_project_name> 1)

在调用stdio_init_all(), any output that your application sends with printf() is sent to RTT. If you want to copy your output to the UART as well, you can enable that too.

从 VSCode 连接到 RTT

RTT 得到 OpenOCD 和 VSCodeCortex-Debug扩展的支持;这两者都已在安装工具.

的过程中完成设置。要为调试会话启用 RTT,请在其启动配置中添加一个部分。打开您的项目.vscode folder and add the following lines to the launch.json file, putting them in the appropriate configuration section, such as "Pico Debug (Cortex-Debug)":

"rttConfig": {
    "enabled": true,
    "address": "auto",
    "decoders": [
        {
            "label": "",
            "port": 0,
            "type": "console"
        }
    ]
}

了解更多信息,请参阅cortex-debug 启动属性.

如果你现在在启用了 RTT 的应用程序上启动调试会话,并打开终端选项卡,你会在右侧看到一个列表,其中包含RTT Ch:0 console. Select this to see the output that your application sends to the pico_stdio_rtt driver.

在独立调试会话中连接到 RTT

如果你按照开始调试会话中所述使用独立调试会话,可以通过以下步骤连接到 RTT:

  1. 构建并上传你的启用了 RTT 的应用程序。

  2. 连接调试探针并启动openocd and gdb in separate terminals. For more information, see 独立调试会话.

  3. 在gdb prompt enter the following commands:

    (gdb) target remote localhost:3333
    (gdb) monitor reset init
    (gdb) monitor rtt setup 0x20000000 2048 "SEGGER RTT"
    (gdb) monitor rtt start
    (gdb) monitor rtt server start 60000 0
    (gdb) continue
    [8] MiRo-Egdb commands prefixed with monitor are passed through to openocd. For more information about the commands used here, see OpenOCD 手册的第 15.6 节。OpenOCD 会在目标设备上搜索 RTT 控制块,然后在端口 60000 上创建一个本地 TCP 套接字。

    打开第三个窗口,并使用类似工具连接到该本地套接字。

  4. 更新调试探针的固件nc (netcat) or equivalent to see the RTT output from your application:

    $ nc localhost 60000

调试探针的固件以 UF2 文件的形式由树莓派提供。

调试探针固件的最新版本是 2.3.1。如果你当前运行的是旧版本,或者不小心覆盖了调试探针上的固件,可以在

debugprobe 的 GitHub 仓库中找到最新发布的固件。.

要检查调试探针的固件版本,请运行:

$ lsusb -v -d 2e8a:000c | grep bcdDevice

这将报告bcdDevice 2.31 for Debug Probe firmware version 2.3.1.

[8] MiRo-EInfo : CMSIS-DAP: FW Version = 2.0.0 line reported by openocd only refers to the CMSIS-DAP protocol level (which is different to the Debug Probe firmware version).

要更新调试探针的固件版本,请执行以下操作:

  1. 下载debugprobe.uf2 from the latest release.

  2. 按压并取下调试探针外壳的顶部。

  3. 插入调试探针时按住 BOOTSEL 按钮,此时会挂载一个名为 RPI-RP2(Pico)或 RP2350(Pico 2)的存储卷。

  4. 复制debugprobe.uf2 onto the mounted volume. The volume will dismount automatically after the file finishes copying onto the device.

  5. 调试探针将重新启动,现在运行的是更新后的调试探针固件,已准备好用于调试。

原理图

调试探针的原理图和机械图纸现已提供:

原理图中所示的测试点(TP)位置如下面的示意图所示。

debug probe tps