收敛 reset.bat 到 stlink-flash skill 并删除该批处理
stlink_flash.py 新增 hard 子命令(-c SWD RM=Hrst -HardRst PULSE=100), RM= 被 CLI 拒绝时自动降级为系统复位并打印 RESET_NOTE;至此 reset.bat 的 全部子命令(复位/hard/halt/run/list/flash/cmp)均已由 skill 覆盖。 删除 MDK-ARM/reset.bat(git rm)。@build/@download 两条旧批处理入口至此 全部收敛到 .dsh/skills/ 下的 skill,一个能力一个实现。 同步更新引用:AGENTS.md、README、MDK-ARM/README、7 篇 docs、4 个 skill (stlink-flash/serial-boot-test/new-machine-setup 及 config.example.json)。 真机验证:hard 子命令 RM= 被拒 → RESET_NOTE → 回退系统复位 → STLINK_RC=0。
This commit is contained in:
+6
-6
@@ -10,7 +10,7 @@
|
||||
| `STM32F407-Demo.uvprojx` | **Keil 工程文件**(源文件清单、编译选项、目标配置) |
|
||||
| `STM32F407-Demo.uvoptx` | Keil 用户选项(调试器、断点等) |
|
||||
| `startup_stm32f407xx.s` | 启动文件(**`Heap_Size EQU 0x200`(512B)在此限定**) |
|
||||
| `reset.bat` | **复位/烧录/回读**(`ST-LINK_CLI` 封装,见下) |
|
||||
| `.dsh/skills/stlink-flash/scripts/stlink_flash.py` | **复位/烧录/回读**(`ST-LINK_CLI` 封装,见下;原 `reset.bat` 已于 2026-10-10 删除) |
|
||||
|
||||
## 构建与烧录
|
||||
|
||||
@@ -18,19 +18,19 @@
|
||||
# 编译(@build = keil-build skill;相对路径,勿用绝对路径)
|
||||
& '.venv\Scripts\python.exe' .dsh\skills\keil-build\scripts\keil_build.py # 退出码 0 = 0 errors, 0 warnings
|
||||
|
||||
# 烧录 + 复位运行(推荐路径)
|
||||
& "MDK-ARM\reset.bat" flash <文件.hex|.bin>
|
||||
# 烧录 + 复位运行(@download = stlink-flash skill)
|
||||
& '.venv\Scripts\python.exe' .dsh\skills\stlink-flash\scripts\stlink_flash.py flash <文件.hex|.bin>
|
||||
|
||||
# 仅复位
|
||||
& "MDK-ARM\reset.bat"
|
||||
& '.venv\Scripts\python.exe' .dsh\skills\stlink-flash\scripts\stlink_flash.py reset
|
||||
```
|
||||
|
||||
### ⚠️ 烧录铁律
|
||||
|
||||
- `reset.bat flash` = `ST-LINK_CLI -c SWD -P <文件> -Rst -Run`——**`-Rst -Run` 不可省略**!
|
||||
- `stlink_flash.py flash` = `ST-LINK_CLI -c SWD -P <文件> -Rst -Run`——**`-Rst -Run` 不可省略**!
|
||||
裸 `-P` 会报 `Programming Complete`,但目标核处于异常状态时写入并不落地(芯片内容不变)
|
||||
- 烧录后**必须回读校验**:`ST-LINK_CLI -c SWD -CmpFile <文件> 0x08000000`(`No difference found` 才算真写入)
|
||||
- 本机 3 线接线(nRST 未接),**只重启不烧录**用 `reset.bat` 无参
|
||||
- 本机 3 线接线(nRST 未接),**只重启不烧录**用 `stlink_flash.py reset`
|
||||
|
||||
## 台架探针与判读脚本
|
||||
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
:: ST-LINK CLI location: env var DTU_STLINK_CLI = full path of ST-LINK_CLI.exe.
|
||||
:: Explicit value is used as-is (invalid value = hard error, no silent fallback);
|
||||
:: when unset, fall back to PATH (where ST-LINK_CLI.exe).
|
||||
set "STLINK="
|
||||
if defined DTU_STLINK_CLI goto stlink_check
|
||||
where ST-LINK_CLI.exe >nul 2>&1
|
||||
if errorlevel 1 goto stlink_missing
|
||||
for /f "delims=" %%i in ('where ST-LINK_CLI.exe 2^>nul') do (
|
||||
if not defined STLINK set "STLINK=%%i"
|
||||
)
|
||||
if not defined STLINK goto stlink_missing
|
||||
goto stlink_done
|
||||
|
||||
:stlink_check
|
||||
if exist "%DTU_STLINK_CLI%" goto stlink_done
|
||||
echo ENV_ERROR: DTU_STLINK_CLI is set but does not exist: "%DTU_STLINK_CLI%"
|
||||
echo Fix the variable value. No fallback to PATH or other installs is attempted.
|
||||
exit /b 2
|
||||
|
||||
:stlink_missing
|
||||
echo ENV_ERROR: ST-LINK_CLI.exe not found (DTU_STLINK_CLI unset and not on PATH)
|
||||
echo Set it to the full path of ST-LINK_CLI.exe, e.g.:
|
||||
echo [Environment]::SetEnvironmentVariable('DTU_STLINK_CLI', 'C:\Tools\STLink\ST-LINK_CLI.exe', 'User')
|
||||
exit /b 2
|
||||
|
||||
:stlink_done
|
||||
if not defined STLINK set "STLINK=%DTU_STLINK_CLI%"
|
||||
if exist "%STLINK%" goto stlink_ready
|
||||
echo RESET_FAIL: ST-LINK_CLI not found at "%STLINK%"
|
||||
exit /b 2
|
||||
|
||||
:stlink_ready
|
||||
|
||||
if "%~1"=="" goto :reset_run
|
||||
if /i "%~1"=="hard" goto :hard
|
||||
if /i "%~1"=="halt" goto :halt
|
||||
if /i "%~1"=="run" goto :run
|
||||
if /i "%~1"=="list" goto :list
|
||||
if /i "%~1"=="flash" goto :flash
|
||||
if /i "%~1"=="cmp" goto :cmp
|
||||
goto :help
|
||||
|
||||
:reset_run
|
||||
echo RESET: system reset and run (SWD)
|
||||
"%STLINK%" -c SWD -Rst -Run -Q
|
||||
exit /b %ERRORLEVEL%
|
||||
|
||||
:hard
|
||||
echo RESET: nRST pulse 100ms (falls back to system reset if CLI lacks RM=)
|
||||
"%STLINK%" -c SWD RM=Hrst -HardRst PULSE=100 -Q
|
||||
if not errorlevel 1 exit /b 0
|
||||
echo RESET_NOTE: this ST-LINK_CLI rejects RM= (v3.5.0 known gap), falling back to system reset
|
||||
"%STLINK%" -c SWD -Rst -Run -Q
|
||||
exit /b %ERRORLEVEL%
|
||||
|
||||
:halt
|
||||
echo RESET: system reset and halt core (debug; resume with 'run')
|
||||
"%STLINK%" -c SWD -Rst -Halt
|
||||
exit /b %ERRORLEVEL%
|
||||
|
||||
:run
|
||||
echo RUN: resume halted core
|
||||
"%STLINK%" -c SWD -Run
|
||||
exit /b %ERRORLEVEL%
|
||||
|
||||
:list
|
||||
"%STLINK%" -List
|
||||
exit /b %ERRORLEVEL%
|
||||
|
||||
:flash
|
||||
if "%~2"=="" set "FW=%~dp0STM32F407-Demo\STM32F407-Demo.hex"
|
||||
if not "%~2"=="" set "FW=%~2"
|
||||
if not exist "%FW%" (
|
||||
echo FLASH_FAIL: firmware not found "%FW%"
|
||||
exit /b 2
|
||||
)
|
||||
echo FLASH: program "%FW%" then reset and run
|
||||
"%STLINK%" -c SWD -P "%FW%" -Rst -Run -Q
|
||||
exit /b %ERRORLEVEL%
|
||||
|
||||
:cmp
|
||||
if "%~2"=="" set "FW=%~dp0STM32F407-Demo\STM32F407-Demo.hex"
|
||||
if not "%~2"=="" set "FW=%~2"
|
||||
if not exist "%FW%" (
|
||||
echo CMP_FAIL: firmware not found "%FW%"
|
||||
exit /b 2
|
||||
)
|
||||
echo CMP: readback compare "%FW%" vs device flash
|
||||
echo CMP_NOTE: connecting resets the target - run this AFTER log capture, not before
|
||||
"%STLINK%" -c SWD -CmpFile "%FW%" 0x08000000
|
||||
exit /b %ERRORLEVEL%
|
||||
|
||||
:help
|
||||
echo Usage: reset.bat [command]
|
||||
echo.
|
||||
echo (none) System reset and run (restart board via SWD)
|
||||
echo hard nRST pulse 100ms; auto-falls back to system reset if CLI lacks RM=
|
||||
echo halt System reset and halt core (in-session read; auto-resumes after disconnect)
|
||||
echo run Resume a halted core
|
||||
echo list List connected ST-LINK probes
|
||||
echo flash [F] Program F (default: latest build hex) then reset and run
|
||||
echo cmp [F] Readback compare F vs device flash; "No difference found" = write landed
|
||||
echo (connecting resets the target: run it after log capture, not before)
|
||||
echo.
|
||||
echo Exit codes: 0=OK 1=probe or target error 2=usage or tool missing
|
||||
|
||||
endlocal
|
||||
Reference in New Issue
Block a user