本文主要是介绍Jlink下载固件到RAM区,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Jlink下载固件到RAM区
- 准备批处理
- 搜索exe批处理
- 调用jlink批处理
- 准备jlink脚本
- 调用执行
环境:J-Flash V7.96g
平台:arm cortex-m3
准备批处理
搜索exe批处理
find_file.bat
@echo off:: 自动识别脚本名和路径
set "SCRIPT_DIR=%~dp0"
set "SCRIPT_NAME=%~nx0":: 检查是否提供了正确的参数
if "%~1"=="" (echo Usage: %SCRIPT_NAME% file_nameexit /b 1
)set FIND_EXE_NAME=%~1echo Using common paths "C:\Program Files (x86)" to search for %FIND_EXE_NAME%...
for /f "tokens=*" %%i in ('dir /a/b/s/on "C:\Program Files (x86)\*%FIND_EXE_NAME%"') do (echo result: "%%i"SET FIND_EXE_NAME_PATH=%%igoto :found
)echo Using common paths "C:\Program Files" to search for %FIND_EXE_NAME%...
for /f "tokens=*" %%i in ('dir /a/b/s/on "C:\Program Files\*%FIND_EXE_NAME%"') do (echo result: "%%i"SET FIND_EXE_NAME_PATH=%%igoto :found
)rem 搜索其他盘
for /F "Skip=2" %%d in ('Wmic Logicaldisk Where "DriveType=3" Get Name') do (echo Using common paths %%d to search for %FIND_EXE_NAME%for /f "tokens=*" %%i in ('dir /a/b/s/on "%%d\*%FIND_EXE_NAME%"') do (echo result: "%%i"SET FIND_EXE_NAME_PATH=%%igoto :found)
):found
echo Found %FIND_EXE_NAME% at %FIND_EXE_NAME_PATH%
goto :eof
调用jlink批处理
autodownload.bat
@echo off
setlocal enabledelayedexpansion:: 自动识别脚本名和路径
set "SCRIPT_DIR=%~dp0"
set "SCRIPT_NAME=%~nx0":: 检查是否提供了正确的参数
if "%~1"=="" (echo Usage: %SCRIPT_NAME% path_to_bin_file load_addressexit /b 1
)if "%~2"=="" (echo Usage: %SCRIPT_NAME% path_to_bin_file load_addressexit /b 1
):: 设置一个标志,看看可选的目录
::set "JLINK_PATH=C:\Program Files\SEGGER\JLink\JLink.exe"
set "JLINK_PATH=":: 检查用户是否提供了可选的路径
if not "%~3"=="" (if exist "%~3\JLink.exe" (set "JLINK_PATH=%~3\JLink.exe")
):: 常用文件夹搜索路径
if "%JLINK_PATH%"=="" (:: 调用搜索JLink.exe的模块call find_file.bat JLink.exe:: 检查JLINK_PATH环境变量是否已设置if not defined FIND_EXE_NAME_PATH (echo ==not found==goto :found) else (SET JLINK_PATH=!FIND_EXE_NAME_PATH!goto :found)
):found
if "%JLINK_PATH%"=="" (echo JLink.exe not found. Please make sure JLink is installed and the executable is in your PATH.exit /b 1
)
echo Using JLink.exe at: %JLINK_PATH%:: 复制flash_ram.jlink模板并替换占位符
set "JLINK_SCRIPT=%SCRIPT_DIR%flash_ram_temp.jlink"
copy /Y "%SCRIPT_DIR%flash_ram.jlink" "%JLINK_SCRIPT%"
powershell -Command "(Get-Content '%JLINK_SCRIPT%') -replace 'BIN_FILE_PATH', '%~1' -replace 'LOAD_ADDRESS', '%~2' | Set-Content -Path '%JLINK_SCRIPT%'":: 运行JLink命令脚本
"%JLINK_PATH%" -CommanderScript "%JLINK_SCRIPT%":: 删除临时脚本
del "%JLINK_SCRIPT%":: 运行JLink命令脚本
::"%JLINK_PATH%" -CommanderScript "%SCRIPT_DIR%flash_ram.jlink" "%~1" "%~2"::禁用延迟扩展
endlocal
准备jlink脚本
flash_ram.jlink
// 通用 Cortex-M3 设备
device Cortex-M3
speed 4000
if SWD
si 1 // 选择SWD接口
r
h// 将 .bin 文件加载到 RAM 区
//loadbin %1 %2
loadbin BIN_FILE_PATH LOAD_ADDRESS// 复位并运行
r
g// 退出
q
调用执行
# 脚本名 bin文件地址 需烧录RAM区域起始地址
.\autodownload.bat "C:\Users\gs\Desktop\xxx.bin" 0x10000000
这篇关于Jlink下载固件到RAM区的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!