fix(vscode): match HDMI hardware-reset tasks

This commit is contained in:
2026-09-15 18:32:10 +08:00
parent 142b0133d9
commit dccce6967c
2 changed files with 22 additions and 101 deletions
+3 -91
View File
@@ -52,7 +52,7 @@
"args": [ "args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}", "-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}", "-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "init; reset halt; flash write_image erase ${command:cmake.launchTargetFilename}; reset; exit" "-c", "init; adapter deassert srst; sleep 200; catch {reset halt}; reset halt; flash write_image erase ${command:cmake.launchTargetFilename}; reset; exit"
], ],
"group": "build", "group": "build",
"problemMatcher": [], "problemMatcher": [],
@@ -77,7 +77,7 @@
"args": [ "args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}", "-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}", "-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "init; reset; exit" "-c", "init; adapter deassert srst; sleep 200; reset; exit"
], ],
"group": "build", "group": "build",
"problemMatcher": [], "problemMatcher": [],
@@ -102,7 +102,7 @@
"args": [ "args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}", "-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}", "-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "init; reset halt; ${config:gd32.openocd.massEraseCommand}; exit" "-c", "init; adapter deassert srst; sleep 200; catch {reset halt}; reset halt; ${config:gd32.openocd.massEraseCommand}; exit"
], ],
"group": "build", "group": "build",
"problemMatcher": [], "problemMatcher": [],
@@ -120,94 +120,6 @@
"tooltip": "Erase MCU" "tooltip": "Erase MCU"
} }
}, },
{
"label": "Build and Flash (Connect Under Reset)",
"dependsOn": [
"Build",
"Flash MCU (Connect Under Reset)"
],
"dependsOrder": "sequence",
"group": "build",
"icon": {
"id": "insert",
"tooltip": "Build and Flash (Connect Under Reset)"
}
},
{
"label": "Flash MCU (Connect Under Reset)",
"type": "process",
"command": "${env:GD32_OPENOCD_BIN}/openocd.exe",
"args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "adapter srst delay 100; reset_config srst_only srst_nogate connect_assert_srst; init; adapter deassert srst; sleep 200; catch {reset halt}; reset halt; flash write_image erase ${command:cmake.launchTargetFilename}; reset; exit"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "gather",
"tooltip": "Flash MCU (Connect Under Reset)"
}
},
{
"label": "Reset MCU (Connect Under Reset)",
"type": "process",
"command": "${env:GD32_OPENOCD_BIN}/openocd.exe",
"args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "adapter srst delay 100; reset_config srst_only srst_nogate connect_assert_srst; init; adapter deassert srst; sleep 200; reset; exit"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "discard",
"tooltip": "Reset MCU (Connect Under Reset)"
}
},
{
"label": "Mass Erase MCU (Connect Under Reset)",
"type": "process",
"command": "${env:GD32_OPENOCD_BIN}/openocd.exe",
"args": [
"-s", "${env:GD32_OPENOCD_SCRIPTS}",
"-f", "${env:GD32_OPENOCD_SCRIPTS}/${config:gd32.openocd.targetConfig}",
"-c", "adapter srst delay 100; reset_config srst_only srst_nogate connect_assert_srst; init; adapter deassert srst; sleep 200; catch {reset halt}; reset halt; ${config:gd32.openocd.massEraseCommand}; exit"
],
"group": "build",
"problemMatcher": [],
"options": {
"cwd": "${command:cmake.buildDirectory}/Application",
"environment": {
"OPENOCD_SCRIPTS": "${env:GD32_OPENOCD_SCRIPTS}"
}
},
"presentation": {
"clear": true
},
"icon": {
"id": "clear-all",
"tooltip": "Erase MCU (Connect Under Reset)"
}
},
{ {
"label": "OpenOCD Server", "label": "OpenOCD Server",
"type": "process", "type": "process",
+19 -10
View File
@@ -299,18 +299,28 @@ OpenOCD 的 cfg 文件由工程自己的 `.vscode/settings.json` 指定,环境
cfg 必须可以直接启动完整会话,包含调试器 interface 和目标芯片配置;只有 `target/gd32e23x.cfg` 这种 target-only 文件不能单独启动调试会话。 cfg 必须可以直接启动完整会话,包含调试器 interface 和目标芯片配置;只有 `target/gd32e23x.cfg` 这种 target-only 文件不能单独启动调试会话。
例如 CMSIS-DAP 的 wrapper cfg 可以写成: 例如 CMSIS-DAP 的 wrapper cfg 可以写成(使用下述硬件复位任务时,还需追加后面的 RST 配置):
```tcl ```tcl
source [find interface/cmsis-dap.cfg] source [find interface/cmsis-dap.cfg]
source [find target/gd32e23x.cfg] source [find target/gd32e23x.cfg]
``` ```
模板同时提供 `Flash MCU (Connect Under Reset)`、`Reset MCU (Connect Under Reset)` 和 模板的 `Flash MCU`、`Reset MCU` 和 `Mass Erase MCU` 任务默认使用 RST 硬件复位:OpenOCD
`Mass Erase MCU (Connect Under Reset)` 三个可选任务,用于固件复用 SWD 引脚后普通方式无法连接的场景。 连接时保持复位,连接后松开 RST,并等待 200 ms 后执行烧录、复位或擦除操作。每台开发机需要满足以下条件:
这些任务会在启动 OpenOCD 时临时设置 `connect_assert_srst`,不需要修改工具链目录中的 cfg 文件。
使用前必须将调试器的 RST 线连接到 MCU 的 NRST;若固件会复用 SWD 引脚,还应在松开复位后保留至少 - 调试器的 RST 线连接到 MCU 的 NRST。
2 秒的调试挂接窗口。未连接 RST 线时继续使用不带 `Connect Under Reset` 后缀的普通任务。 - `gd32.openocd.targetConfig` 指定的 cfg 包含以下配置:
```tcl
adapter srst delay 100
reset_config srst_only srst_nogate connect_assert_srst
```
- 若固件会复用 SWD 引脚,松开复位后应保留至少 2 秒的调试挂接窗口。
cfg 位于 `GD32_OPENOCD_SCRIPTS` 指向的工具目录中,不随工程仓库分发;更换电脑或 OpenOCD
版本后需要再次确认上述配置。未连接 RST 线的硬件应改用软复位配置。
每台开发电脑配置一次用户环境变量(路径按本机实际位置填写): 每台开发电脑配置一次用户环境变量(路径按本机实际位置填写):
@@ -381,11 +391,10 @@ cmake --build Build/Release
### 烧录 ### 烧录
通过 VSCode 任务栏运行 `Flash MCU` 任务。若固件运行后会复用 SWD 引脚,且调试器的 RST 已连接到 通过 VSCode 任务栏运行 `Flash MCU` 任务,或使用同样的硬件复位时序从命令行烧录:
MCU 的 NRST,则改用 `Build and Flash (Connect Under Reset)`。普通模式也可通过命令行烧录:
```bash ```powershell
openocd -f interface/cmsis-dap.cfg -f target/gd32e23x.cfg -c "program Build/Debug/Application/Application.elf verify reset exit" & "$env:GD32_OPENOCD_BIN\openocd.exe" -s "$env:GD32_OPENOCD_SCRIPTS" -f "target/openocd_gdlink_gd32e23x.cfg" -c "init; adapter deassert srst; sleep 200; catch {reset halt}; reset halt; flash write_image erase Build/Debug/Application/Application.elf; reset; exit"
``` ```
### 产物 ### 产物