大概步骤按 probe-rs 官网的教程走即可。
前提:在wsl2 中使用usb 需要通过 usbipd-win 这个工具,需要先确保这个工具能正常连通,在linux 中能看到对应的usb文件
- wsl 中安装 probe-rs , 有多种方法,我是通过 cargo binstall probe-rs-tools 安装的,如果没有binstall 先通过 cargo install cargo-binstall 安装
cargo binstall probe-rs-tools
- vscode 安装 probe-rs 插件 ,并配置 调试启动 文件
注意chip、 formatOptions 和programBinary 的配置
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "probe-rs-debug",
"request": "launch",
"name": "probe-rs Test",
"cwd": "${workspaceFolder}",
"connectUnderReset": true,
"chip": "esp32c3",
"flashingConfig": {
"flashingEnabled": true,
"haltAfterReset": true,
"formatOptions": {
"binaryFormat": "idf"
}
},
"coreConfigs": [
{
"coreIndex": 0,
"programBinary": "./target/riscv32imc-unknown-none-elf/debug/${workspaceFolderBasename}"
}
]
}
]
}
- 启动调试时可能提示如下错误:
Error: Failed to open the debug probe. Caused by: 0: The debug probe could not be created. 1: A USB error occurred. 2: Permission denied (os error 13)
因为权限问题报错,需要增加udev 规则以解决此问题,步骤大概为下载对应rules 文件 保存到 /etc/udev/rules.d 中,接着运行如下命令加载rules
udevadm control --reload udevadm trigger
如果运行以上命令后得到一个失败的提示: Failed to send reload request: No such file or directory ,式则运行 sudo service udev restart 启动 udev 服务 ,
我在运行 启动udev 服务时 一直返回结果 : udev does not support containers, not started 。多次尝试未果后我通过probe-rs 官网的提示,使用sudo配置了 /etc/wsl.conf 文件增加了如下内容:
[boot] command="service udev start"
在运修改wsl.conf 后通过 wsl –shutdown 重启了 wsl ,启动后运行 sudo udevadm control –reload 成功。然后通过usbipd wsl attach –busid $设备编号 将usb 附加到 wsl中后运行probe-rs 成功进入调试。
如果运行probe-rs 时未提示 permission denied 而是提示 Error: No connected probes were found. 很大概率是 没有通过usbipd 连接设备到 wsl中。
- 官网配置urdev rules步骤:
By default, the debug probes are only accessible by users with root privileges on Linux based systems. It is recommend to use appropriate udev rules to allow users without root privileges access to the debug probes as well.
- Download the rules file and place it in /etc/udev/rules.d.
- Run udevadm control –reload to ensure the new rules are used.
- Run udevadm trigger to ensure the new rules are applied to already added devices.
If you’re still unable to access the debug probes after following these steps, try adding your user to the plugdev group.
[^1]: The file needs to have an initial number lower than 73, otherwise the udev rules do not get applied properly. See this Github discussion for more information.
If you are using WSL, you may need to enable the udev service. To check if the service is running, run service udev status. If the service is not started, edit /etc/wsl.conf (with sudo) and make sure the following is included:
[boot] command=”service udev start”
参考网页: