跳过正文

使用 USB-JTAG/probe-rs 调试应用

·945 字
Rust Esp32 Rust Esp32
rust-esp32 - 这篇文章属于一个选集。
§ 12: 本文

ESP32-S3 开发版一般有两个 USB 接口,一般标记为 UART 和 USB,后者是支持 USB-Serial-JTAG 调试的接口,该接口包含两个 USB 设备:

  1. USB-CDC-ACM:PC 识别为 USB 串口设备,可以用于下载固件和打印芯片输出的日志;
  2. JTAG 设备:可以被用来进行 JTAG 调试;

查看 MaxcOS USE-Serial-JTAG 设备信息:

zj@a:~/docs$ system_profiler SPUSBDataType | grep -A 11 "USB JTAG"
        USB JTAG/serial debug unit:

          Product ID: 0x1001
          Vendor ID: 0x303a
          Version: 1.01
          Serial Number: 3C:84:27:04:FE:18
          Speed: Up to 12 Mb/s
          Manufacturer: Espressif
          Location ID: 0x02100000 / 2
          Current Available (mA): 500
          Current Required (mA): 500
          Extra Operating Current (mA): 0

对应的设备名称为 /dev/tty.usbmodem* 或 /dev/cu.usbmodem*:

zj@a:~/docs$ ls -l /dev/*.usbmodem*
crw-rw-rw- 1 root 9, 11  5 10 21:38 /dev/cu.usbmodem2101
crw-rw-rw- 1 root 9, 10  5 10 20:16 /dev/tty.usbmodem2101
zj@a:~/docs$ espflash board-info
[2024-05-10T13:38:06Z INFO ] Detected 2 serial ports
[2024-05-10T13:38:06Z INFO ] Ports which match a known common dev board are highlighted
[2024-05-10T13:38:06Z INFO ] Please select a port
[2024-05-10T13:38:19Z INFO ] Serial port: '/dev/cu.usbmodem2101'
[2024-05-10T13:38:19Z INFO ] Connecting...
[2024-05-10T13:38:21Z INFO ] Using flash stub
Chip type:         esp32s3 (revision v0.2)
Crystal frequency: 40 MHz
Flash size:        16MB
Features:          WiFi, BLE
MAC address:       3c:84:27:04:fe:18

# 使用 probe-rs 工具
zj@a:~/docs$ probe-rs info
Probing target via JTAG

 WARN probe_rs::probe::espusbjtag: More than one TAP detected, defaulting to tap0
No DAP interface was found on the connected probe. ARM-specific information cannot be printed.
Error while reading RISC-V info: Connected target is not a RISC-V device.
Xtensa Chip:
  IDCODE: 00120034e5
    Version:      1
    Part:         8195
    Manufacturer: 626 (Tensilica)

Probing target via SWD

Error identifying target using protocol SWD: Probe does not support SWD

zj@a:~/docs$

由于 ESP32-S3 自带 USB-Serial-JTAG Controller,故不需要单独的外接 debug probe 硬件来进行烧写或调试。确认方法:

cargo espflash board-info
# or
espflash board-info

ESP32-S3 支持使用 probe-rs 或 ESP32 fork 的 OpenCDC 进行 JTAG 调试。

probe-rs 是一个使用 JTAG 接口进行芯片 flash 烧写和调试的工具,支持 RISC-V/ARM/Xtensor。

安装 probe-rs 和相关工具:

zj@a:~/docs$ cargo install probe-rs --features cli
   Installed package `probe-rs v0.23.0` (executables `cargo-embed`, `cargo-flash`, `probe-rs`)

probe-rs 最重要的是 run 命令,可以集成到 cargo run 中:.cargo/config.toml

[target.<architecture-triple>]
runner = 'probe-rs run --chip esp32s3'

Now you can execute cargo run in your project as you would for any native binaries and you will receive RTT and defmt logs in that very same console as if you wrote to standard out.

  • It makes it possible to flash, start and print logs from your target with a simple cargo run.

probe-rs attach works exactly like probe-rs run except that it does not issue a reset and does not flash the target on connecting to preserve the currently running state. This is great for inspecting a target - where you might not even have knowledge of the firmware - without altering its state.

probe-rs 实现了 DAP 协议,可以直接在 VS Code 中调试代码。

probe-rs 和 DAP 集成:https://probe.rs/docs/tools/debugger/

  1. 下载 probe-vs 的 vs-code 插件:页面右侧 Resouces 下的 Download Extension https://marketplace.visualstudio.com/items?itemName=probe-rs.probe-rs-debugger
  2. 解压 vsix 文件到 emacs 目录,参考:https://github.com/svaante/dape
  3. 配置 dape;

probe-rs 示例:

zj@a:~/code/slint/examples$ ls -l /dev/*usbmodem*
crw-rw-rw- 1 root 9, 9  5 11 17:38 /dev/cu.usbmodem2101
crw-rw-rw- 1 root 9, 8  5 11 17:38 /dev/tty.usbmodem2101

zj@a:~/code/slint/examples$ probe-rs  list
The following debug probes were found:
[0]: ESP JTAG (VID: 303a, PID: 1001, Serial: 3C:84:27:04:FE:18, EspJtag)

zj@a:~/code/slint/examples$ probe-rs  info
Probing target via JTAG

 WARN probe_rs::probe::espusbjtag: More than one TAP detected, defaulting to tap0
No DAP interface was found on the connected probe. ARM-specific information cannot be printed.
Error while reading RISC-V info: Connected target is not a RISC-V device.
Xtensa Chip:
  IDCODE: 00120034e5
    Version:      1
    Part:         8195
    Manufacturer: 626 (Tensilica)

Probing target via SWD

Error identifying target using protocol SWD: Probe does not support SWD


zj@a:~/code/slint/examples$ probe-rs  chip list  |grep esp
esp32c6
        esp32c6
esp32s2
        esp32s2
esp32h2
        esp32h2
esp32s3
        esp32s3
esp32
        esp32-3.3v
esp32c2
        esp32c2
esp32c3
        esp32c3
esp32c6_lp
        esp32c6_lp

zj@a:~/code/slint/examples$ probe-rs  chip info esp32s3
esp32s3
Cores (1):
    - cpu0 (Xtensa)
NVM: 0x00000000..0x04000000 (64.00 MiB)
RAM: 0x3fc88000..0x3fcf0000 (416.00 KiB)
RAM: 0x3fcf0000..0x3fd00000 (64.00 KiB)
RAM: 0x40370000..0x40378000 (32.00 KiB)
RAM: 0x40378000..0x403e0000 (416.00 KiB)
NVM: 0x42000000..0x44000000 (32.00 MiB)
NVM: 0x3c000000..0x3e000000 (32.00 MiB)
rust-esp32 - 这篇文章属于一个选集。
§ 12: 本文

相关文章

Rust 驱动 Audio - 播放和录音
·6323 字
Rust Esp32 Rust Esp32
Rust 驱动 Camera - 采集和播放
·7304 字
Rust Esp32 Rust Esp32
Rust 驱动 LCD - 显示中英文
·818 字
Rust Esp32 Rust Esp32
Rust 驱动 LCD - 显示图片
·4232 字
Rust Esp32 Rust Esp32