天天看点

J-Link 命令行烧录

J-Link 命令行烧录

因为我有很多需要烧录的HEX文件,用J-Flash烧录起来很不方便,因此尝试用批处理命令来进行烧录处理。这样的,只需要一个批处理脚本,就可以完成整个烧录。

J-Link.exe

命令使用说明。

这里我有两个HEX文件,一个Bin文件。两个HEX分别是Softdevice和Bootloader,Bin文件是APP。在烧录时,为了方便,我将这三个文件进行合并,合并成一个HEX文件。

方法:先将Bin文件转化为HEX文件,然后合并三个HEX文件为一个HEX文件。

将用到的命令写程一个批处理脚本

firmware_product_hw.bat

.\srec_cat.exe .\burn.bin -Binary -offset 0x380c0 -o burn.hex -Intel
mergehex -m .\softdevice_bootloader_product_hw.hex .\burn.hex -o firmware_product_hw.hex
pause
           

然后配置烧录脚本

52840.txt

si 1 // 选择SW接口
speed 4000 // 4000kHz
device NRF52840_XXAA // 芯片型号
r 
h
erase
loadfile F:\Projects\Guard_bar\code\test\firmware_product_hw.hex
q
           

命令运行:

"C:\Program Files (x86)\SEGGER\JLink\JLink.exe" "F:\Tool\bin2hex\52840.txt"
           

结果:

C:\Users\28328>"C:\Program Files (x86)\SEGGER\JLink\JLink.exe" "F:\Tool\bin2hex\52840.txt"
SEGGER J-Link Commander V6.72d (Compiled May 15 2020 16:48:00)
DLL version V6.72d, compiled May 15 2020 16:47:06


J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...O.K.
Firmware: J-Link V9 compiled Dec 13 2019 11:14:50
Hardware version: V9.30
S/N: 59300616
License(s): RDI, FlashBP, FlashDL, JFlash, GDB
VTref=3.138V
Selecting SWD as current target interface.

Selecting 4000 kHz as target interface speed


Target connection not established yet but required for command.
Device "NRF52840_XXAA" selected.


Connecting to target via SWD
InitTarget() start
InitTarget() end
Found SW-DP with ID 0x2BA01477
Unknown DP version. Assuming DPv0
Scanning AP map to find all available APs
AP[2]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x24770011)
AP[1]: JTAG-AP (IDR: 0x02880000)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
Cortex-M4 identified.
Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.

PC = 00000A80, CycleCnt = 00000000
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000
SP(R13)= 20000400, MSP= 20000400, PSP= 00000000, R14(LR) = FFFFFFFF
XPSR = 01000000: APSR = nzcvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00

FPS0 = 00000000, FPS1 = 00000000, FPS2 = 00000000, FPS3 = 00000000
FPS4 = 00000000, FPS5 = 00000000, FPS6 = 00000000, FPS7 = 00000000
FPS8 = 00000000, FPS9 = 00000000, FPS10= 00000000, FPS11= 00000000
FPS12= 00000000, FPS13= 00000000, FPS14= 00000000, FPS15= 00000000
FPS16= 00000000, FPS17= 00000000, FPS18= 00000000, FPS19= 00000000
FPS20= 00000000, FPS21= 00000000, FPS22= 00000000, FPS23= 00000000
FPS24= 00000000, FPS25= 00000000, FPS26= 00000000, FPS27= 00000000
FPS28= 00000000, FPS29= 00000000, FPS30= 00000000, FPS31= 00000000
FPSCR= 00000000

Erasing device...
J-Link: Flash download: Total time needed: 0.715s (Prepare: 0.188s, Compare: 0.000s, Erase: 0.523s, Program: 0.000s, Verify: 0.000s, Restore: 0.003s)
Erasing done.

Downloading file [F:\Projects\Guard_bar\code\test\firmware_product_hw.hex]...
J-Link: Flash download: Bank 0 @ 0x00000000: 2 ranges affected (274432 bytes)
J-Link: Flash download: Total time needed: 3.215s (Prepare: 0.050s, Compare: 0.175s, Erase: 0.000s, Program: 2.943s, Verify: 0.017s, Restore: 0.028s)
O.K.


Script processing completed.


C:\Users\28328>
           

运行脚本将会弹出下面的烧录窗口。

J-Link 命令行烧录

最后

把所有用到的命令放到一个脚本中

make.bat

echo 开始生成bin文件

copy F:\Projects\Oil_drip\Code\nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_rail_lubricatior\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.axf .\nrf52832_xxaa.axf

copy E:\Nordic_data\Nordic_SDK_1702\nRF5_SDK_17.0.2_d674dde\examples\peripheral\timer\pca10056\blank\arm5_no_packs\_build\nrf52840_xxaa.hex .\bootloader_52840.hex

call ".\axfparse第一步点这个.bat"

.\sectoolWin32 -i1 no none 0 none 0 -o final.bin -s 0x1 0xff -crc32 -md5 -sha1 -sha256 -aes -3des -idea -rsa1024

call ".\mergehex_product_hw.bat"

"C:\Program Files (x86)\SEGGER\JLink\JLink.exe" "F:\Tool\bin2hex\52840.txt"

pause
           

这样,多文件烧录起来就方便多了。

因为Softdevice和bootloader是不会改的, 所以,这里为了编译烧录方便,直接把批处理脚本放到KEIL中的编译后执行命令设置中去,这样,每一次编译完就自动去合并文件并烧录。

J-Link 命令行烧录
J-Link 命令行烧录
J-Link 命令行烧录

完美o( ̄▽ ̄)d

鉴于JFlash工具操作页面比较繁琐,我用Qt写了一个简单的JLink烧录工具,可在

global_config

中对支持的设备类型进行配置。

J-Link 命令行烧录

完善更新后的版本(支持Linux):

J-Link 命令行烧录