天天看點

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 指令行燒錄