probe-rs

probe-rs 项目是一组工具,用于使用各种调试探针与嵌入式 MCU 进行交互。它类似于 OpenOCDpyOCDSegger 工具等。支持 ARMRISC-V 架构以及一系列工具,包括但不限于:

请按照 probe-rs 网站上的安装设置说明进行操作。

包含 USB-JTAG-SERIAL 外设的乐鑫产品无需任何外部硬件即可使用 probe-rs

probe-rs 烧写

probe-rs 可以用于烧写程序,因为它支持 ESP-IDF image format

  • 烧写 ESP32-C3 的命令示例: probe-rs run --chip esp32c3

添加以下内容到项目中的 .cargo/config.toml 文件,就可以把烧写命令用作自定义 Cargo runner:

[target.'cfg(any(target_arch = "riscv32", target_arch = "xtensa"))']
runner = "probe-rs run --chip esp32c3"

通过此配置,就可以使用 cargo run 来烧写并监控你的应用程序。

VS Code 扩展

VS Code 有 probe-rs 扩展。关于如何安装、配置和使用,请参考 probe-rs VS Code 文档

示例 launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "probe-rs-debug",
            "request": "launch",
            "name": "Launch",
            "cwd": "${workspaceFolder}",
            "chip": "esp32c3", //!MODIFY
            "flashingConfig": {
                "flashingEnabled": true,
                "resetAfterFlashing": true,
                "haltAfterReset": true,
                "formatOptions": {
                    "format": "idf" //!MODIFY (or remove). Valid values are: 'elf'(default), 'idf'
                }
            },
            "coreConfigs": [
                {
                    "coreIndex": 0,
                    "programBinary": "target/riscv32imc-unknown-none-elf/debug/${workspaceFolderBasename}", //!MODIFY
                }
            ]
        },
        {
            "type": "probe-rs-debug",
            "request": "attach",
            "name": "Attach",
            "cwd": "${workspaceFolder}",
            "chip": "esp32c3", //!MODIFY
            "coreConfigs": [
                {
                    "coreIndex": 0,
                    "programBinary": "target/riscv32imc-unknown-none-elf/debug/${workspaceFolderBasename}", //!MODIFY
                }
            ]
        }
    ]
}

Launch 配置将烧写设备并开始调试,而 Attach 将在正在运行的应用程序上开始调试。有关更多详细信息,请参考 launch 和 attach 之间差异的 VS Code 文档。

cargo-flashcargo-embed

probe-rs 附带这两个工具:

  • cargo-flash:一个烧写工具,可将二进制文件烧写到目标设备,并运行。
  • cargo-embedcargo-flash 的超集,允许打开 RTT 终端或 GDB 服务器。可以用配置文件来定义其行为。

GDB 集成

probe-rs 包含 GDB stub,可以使用常用工具集成到你的常用工作流程中。 probe-rs gdb 命令会启动 GDB server,默认在 1337 端口上运行。

espressif/binutils-gdb 包含支持所有乐鑫设备的 GDB。