[SOLVED] Use J-Link commander to flash a file to area that is not erased?

  • 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:

    Code
    ExitOnError 1
    Connect
    h
    
    
    LoadFile C:\devtrees\test-bin\test-bin.bin,0x08080000
    
    
    r
    exit

    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 https://wiki.segger.com/J-Link_Commander

    Here is an example session trying to flash a non-erased chip:


    And here is the J-Link command file that the script produced for that session:

    Code
    ExitOnError 1
    Connect
    h
    
    
    LoadFile C:\devtrees\test-bin\test-bin.bin,08080000
    
    
    r
    exit
  • There is something wrong here…
    A „loadfile“ has always done and should still do erase + verify implicitly, besides programming.

    Could you please provide a log file of a failing session?
    https://wiki.segger.com/Enable_J-Link_log_file

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • I should have thought to do this before. Here's an annotated manual jlink session that gets the script out of the picture and just tries to erase a couple sectors of flash:


    And attached is the log file in case it shows something helpful: just-erase.gd32f303zk.jlink.log

    Edited 4 times, last by mwb1100 (September 1, 2022 at 8:42 PM).

  • I just tried updating the J-Link software package to v7.70e. This also resulted in the J-Link's firmware being updated.

    The test performs exactly the same (except that the erase command does a reset now as explained in the release notes).

    The erase of a memory range still doesn't actually do the erase.

  • One more clue:

    Since the GD32F303 is a close clone of the STM32F103 (it's actually more like the STM32F103 than it is the STM32F303), I tried connecting to it as an STM32F103ZG. The F103ZG has 1MB of flash so the flash pages in the range 0x08080000 - 0x08081ffff exist on that chip. Telling jlink.exe that it's connecting to an STM32F103ZG makes the erase operation work:


    However, I don't think that's an effective workaround for me because this project uses flash up to the end of the GD32F303ZK's flash address space to store data so I need the tool to be able to write to flash above the 1MB limit that the STM32F103ZG has.

  • We reproduced and fixed the issue.
    The fix is already available in the newly released J-Link V7.80.

    Could you give the latest version a try?

    BR
    Sebastian

    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!