diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 572c001..b31204a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -120,6 +120,94 @@ "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", "type": "process", diff --git a/README.md b/README.md index e0d520c..0609f0d 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,12 @@ source [find interface/cmsis-dap.cfg] source [find target/gd32e23x.cfg] ``` +模板同时提供 `Flash MCU (Connect Under Reset)`、`Reset MCU (Connect Under Reset)` 和 +`Mass Erase MCU (Connect Under Reset)` 三个可选任务,用于固件复用 SWD 引脚后普通方式无法连接的场景。 +这些任务会在启动 OpenOCD 时临时设置 `connect_assert_srst`,不需要修改工具链目录中的 cfg 文件。 +使用前必须将调试器的 RST 线连接到 MCU 的 NRST;若固件会复用 SWD 引脚,还应在松开复位后保留至少 +2 秒的调试挂接窗口。未连接 RST 线时继续使用不带 `Connect Under Reset` 后缀的普通任务。 + 每台开发电脑配置一次用户环境变量(路径按本机实际位置填写): ```powershell @@ -375,10 +381,11 @@ cmake --build Build/Release ### 烧录 -通过 VSCode 任务栏运行 `Flash MCU` 任务,或命令行: +通过 VSCode 任务栏运行 `Flash MCU` 任务。若固件运行后会复用 SWD 引脚,且调试器的 RST 已连接到 +MCU 的 NRST,则改用 `Build and Flash (Connect Under Reset)`。普通模式也可通过命令行烧录: ```bash -openocd -f interface/cmsis-dap.cfg -f target/gd32e23x.cfg -c "program Build/Debug/Application.elf verify reset exit" +openocd -f interface/cmsis-dap.cfg -f target/gd32e23x.cfg -c "program Build/Debug/Application/Application.elf verify reset exit" ``` ### 产物