为了使用ST-Link Utility进行闪烁,我编写了以下有效的命令:
"C:\Program Files\STMicroelectronics\STM32 ST-Link Utility\ST-Link_CLI.exe" -c SN=XXXXXXXXXXXXX SWD UR FREQ=400 -P "C:\flash STM32\test.hex" -V -HardRst
我想通过使用ST-Link_CLI.exe
命令和批处理文件所在文件夹中的.hex
文件获取序列号来自动执行此操作,因此我可以单击此.bat
文件以使用任何调试器进行刷新(SN)即已连接。
我可以使用以下方法获得序列号:
@echo off
setlocal EnableDelayedExpansion
set "output_cnt=0"
for /F "delims=" %%f in ('"C:\Program Files\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility\ST-LINK_CLI.exe" -List') do (
set /a output_cnt+=1
set "output[!output_cnt!]=%%f"
)
for /L %%a in (1 1 !output_cnt!) do call echo !output[%%a]!
pause
set "str=SN"
for /L %%n in (1 1 !output_cnt!) do (
echo !output[%%n]!|find "SN" >nul
if errorlevel 1 (echo notfound) else (echo found at!output[%%n]!)
)
pause
!output[%%a]!
中的行包含字符串" SN:XXXXXXXXXXX"
时,[output_cnt
为SN
关于编写有效的批处理脚本,我是一个完全的新手,我想知道是否有人可以帮助我自动执行此任务。
您可以使用FOR /F
循环拆分字符串。
...
set "serial=NONE"
for /L %%n in (1 1 !output_cnt!) do (
echo !output[%%n]!
FOR /F "tokens=1,* delims=: " %%1 in ("!output[%%n]!") do (
if "%%1" == "SN" (
set "serial=%%2"
)
)
)
echo Found serial: !serial!