To flash an GD32 device I'm working with, I use a script that writes a temporary J-Link Commander "command" file (or whatever the correct term is) that includes the LoadFile command to flash the .bin or .hex file. An example command file might look like:
The problem is that this fails if there is already data at address 0x08080000. If I erase the flash first it works great, but the script only knows how to erase the entire chip, not just the area of flash that the .bin (or .hex) file corresponds to. That means to update a single binary (this project flashes 3 binaries to various parts of the flash) I have to erase the chip then flash all 3 binaries, which is error prone when I have several versions of each binary that can be flashed.
The `erase` command can be used to erase only a selected range of flash, but the script file would need to figure out what the appropriate range is and it doesn't do that - it only has the capability to erase the entire chip.
Is there a way to tell `LoadFile` to erase the area of flash that it will be updating? I couldn't see such an option or setting in wiki.segger.com/J-Link_Commander
Here is an example session trying to flash a non-erased chip:
Display All
And here is the J-Link command file that the script produced for that session:
The problem is that this fails if there is already data at address 0x08080000. If I erase the flash first it works great, but the script only knows how to erase the entire chip, not just the area of flash that the .bin (or .hex) file corresponds to. That means to update a single binary (this project flashes 3 binaries to various parts of the flash) I have to erase the chip then flash all 3 binaries, which is error prone when I have several versions of each binary that can be flashed.
The `erase` command can be used to erase only a selected range of flash, but the script file would need to figure out what the appropriate range is and it doesn't do that - it only has the capability to erase the entire chip.
Is there a way to tell `LoadFile` to erase the area of flash that it will be updating? I couldn't see such an option or setting in wiki.segger.com/J-Link_Commander
Here is an example session trying to flash a non-erased chip:
Source Code
- c:\devtrees\test-bin>flash-gd32.py C:\devtrees\test-bin\test-bin.bin,08080000
- SEGGER J-Link Commander V7.66g (Compiled Jul 7 2022 10:37:30)
- DLL version V7.66g, compiled Jul 7 2022 10:35:46
- J-Link Command File read successfully.
- Processing script file...
- J-Link>ExitOnError 1
- J-Link Commander will now exit on Error
- J-Link>Connect
- J-Link connection not established yet but required for command.
- Connecting to J-Link via USB...O.K.
- Firmware: J-Link V10 compiled Nov 2 2021 12:14:50
- Hardware version: V10.10
- S/N: 600105391
- License(s): RDI, FlashBP, FlashDL, JFlash, GDB
- VTref=3.310V
- Device "GD32F303ZK" selected.
- Connecting to target via SWD
- Found SW-DP with ID 0x2BA01477
- DPIDR: 0x2BA01477
- CoreSight SoC-400 or earlier
- Scanning AP map to find all available APs
- AP[1]: Stopped AP scan as end of AP map has been reached
- AP[0]: AHB-AP (IDR: 0x24770011)
- 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
- [0][0]: E000E000 CID B105E00D PID 000BB00C SCS-M7
- [0][1]: E0001000 CID B105E00D PID 003BB002 DWT
- [0][2]: E0002000 CID B105E00D PID 002BB003 FPB
- [0][3]: E0000000 CID B105E00D PID 003BB001 ITM
- [0][4]: E0040000 CID B105900D PID 000BB9A1 TPIU
- [0][5]: E0041000 CID 00000000 PID 00000000 ???
- Cortex-M4 identified.
- J-Link>h
- PC = 08027744, CycleCnt = 2AD8BC18
- R0 = 00000000, R1 = CDCDCDCD, R2 = 80000000, R3 = 08031999
- R4 = 6802B4D0, R5 = 00000001, R6 = 6802B4D0, R7 = CCCC0007
- R8 = CCCC0008, R9 = CCCC0009, R10= CCCC000A, R11= CCCC000B
- R12= 08031998
- SP(R13)= 20003400, MSP= 200033D8, PSP= 20003400, R14(LR) = 21000000
- XPSR = 01000000: APSR = nzcvq, EPSR = 01000000, IPSR = 000 (NoException)
- CFBP = 02000000, CONTROL = 02, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00
- FPS0 = 4A71DF44, FPS1 = 20925D1B, FPS2 = 2010E87E, FPS3 = F69BF462
- FPS4 = 64DB8277, FPS5 = E3EB6079, FPS6 = 23C78804, FPS7 = D577FD7F
- FPS8 = DAC9F9F9, FPS9 = 502666CE, FPS10= 5B6F31D3, FPS11= 7A6FC353
- FPS12= FE89A50F, FPS13= 842683E1, FPS14= 842FBC66, FPS15= 2F0DAE5F
- FPS16= 6E59BC16, FPS17= 5E86E6ED, FPS18= ADB0E7B1, FPS19= 934CF140
- FPS20= FFF56F97, FPS21= 00EEBE6F, FPS22= CF3423CD, FPS23= B975F6E5
- FPS24= 849C7D2F, FPS25= AEED31C8, FPS26= 1ABDC822, FPS27= 9B88E032
- FPS28= 4EBE14CF, FPS29= A0EA7FD2, FPS30= B97B02D2, FPS31= 4ADCCC57
- FPSCR= 00000000
- J-Link>LoadFile C:\devtrees\test-bin\test-bin.bin,08080000
- Downloading file [C:\devtrees\test-bin\test-bin.bin]...
- Error while programming flash: Programming failed.
- Script processing completed.
- resetting...
- Done in 0 min 3.574 sec
And here is the J-Link command file that the script produced for that session: