Arduino STM32 JLink OB下载教程
1. 准备工作
软件:Setup_JLinkARM_V468.exe,上篇已成功安装的相关软件。
硬件:STM32F1板子(STM32F103ZET6)、JLink OB下载器。
2.软件配置
安装“Setup_JLinkARM_V468.exe”,本例安装目录为“D:\Program Files (x86)\SEGGER\JLinkARM_V468\”,安装完成后可以在设备管理器中看到J-Link driver。
打开D:\Program Files (x86)\Arduino\hardware\Arduino_STM32\STM32F1\boards.txt文件,在需要使用JLink下载的STM32系列(本例STM32F103ZET6)下添加代码并保存。
genericSTM32F103Z.menu.upload_method.jLinkMethod=JLINK
genericSTM32F103Z.menu.upload_method.jLinkMethod.upload.protocol=jlink
genericSTM32F103Z.menu.upload_method.jLinkMethod.upload.tool=jlink_upload
genericSTM32F103Z.menu.upload_method.jLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG
genericSTM32F103Z.menu.upload_method.jLinkMethod.upload.device=STM32F103ZE
重新启动Arduino IDE可以看到上载方式增加了“JLINK”项。
打开D:\Program Files (x86)\Arduino\hardware\Arduino_STM32\STM32F1\platform.txt文件,添加如下代码并保存,已存在可省略。
tools.jlink_upload.cmd=jlink_upload
tools.jlink_upload.cmd.windows=jlink_upload.bat
tools.jlink_upload.cmd.macosx=jlink_upload
tools.jlink_upload.path={runtime.hardware.path}/tools/win
tools.jlink_upload.path.macosx={runtime.hardware.path}/tools/macosx
tools.jlink_upload.path.linux={runtime.hardware.path}/tools/linux
tools.jlink_upload.path.linux64={runtime.hardware.path}/tools/linux64
tools.jlink_upload.upload.params.verbose=-d
tools.jlink_upload.upload.params.quiet=n
tools.jlink_upload.upload.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.bin"
打开D:\Program Files (x86)\Arduino\hardware\Arduino_STM32\tools\win\jlink_upload.bat文件,添加如下代码并保存。对于不同系列的STM32,需要更改最后一行中对应的“STM32Fxxxxx”。
rem: @echo off
rem: Note %~dp0 get path of this batch file
rem: Need to change drive if My Documents is on a drive other than C:
set driverLetter=%~dp0
set driverLetter=%driverLetter:~0,2%
%driverLetter%
cd %~dp0
rem: the two line below are needed to fix path issues with incorrect slashes before the bin file name
set tmpBinFilePath=%1
set tmpBinFilePath=%tmpBinFilePath:/=\%
rem: create commander script file with the tmp bin that the Arduino IDE creates
@echo erase > %tmpbinfilepath%.jlink
@echo loadbin %tmpbinfilepath% , 0x8000000 >> %tmpbinfilepath%.jlink
@echo r >> %tmpbinfilepath%.jlink
@echo q >> %tmpbinfilepath%.jlink
jlink\JLink.exe -device STM32F103ZE -if SWD -speed 4000 -CommanderScript %tmpBinFilePath%.jlink
在“D:\Program Files (x86)\Arduino\hardware\Arduino_STM32\tools\win”文件夹下新建文件夹“jlink”,并将JLink安装目录下的“JLink.exe”和“JLinkARM.dll”两个文件拷贝到该文件夹下。
完成配置,JLink上载比串口烧写速度快,也不需要改变BOOT0跳线,很方便。