[SOLVED] Flash programming of STM32F103 using J-Flash/J-link

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Flash programming of STM32F103 using J-Flash/J-link

    Hello,

    Case1:
    I am trying to flash my code into STM32F103 micro using J-flash tool with J-link ultra Jtag hardware. I have selected X_Allowoptionbytes.jflash, but I get a pop us saying that "Program (0x1FFFF800-ox1FFFF80F) does not fit into selected flash sectors". what could be the reason for this error? I am using J-flash V4.98.

    Case2:
    Also I tried to program using J-link.exe tool via command line, I am getting error as below. I guess option byte0 is programmed to 0xA5 in the target.

    "Error: Failed to prepare for programming.
    Could not read target memory
    please check your flash setting !
    writing target memory failed"

    Regards
    Harish
  • Hello Harish,

    sorry for the delay in response.

    In order to program the option bytes of a STM32F103xx device with J-Flash, you need to reallocate the option bytes from 0x1FFFF800-ox1FFFF80F to 0x6000000 - 0x600000F. (This is explained in UM8001: Chapter 13 "Device specifics", section 13.16.2 "STM32F10xxx" subsection 13.16.2.2 "Option byte programming")
    This can be done using the J-Flash "Merge" "Relocate..." and "Delete range..." commandos.

    Best regards,
    Niklas
    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: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Harish,

    J-Link Commander provides no functionality to edit binary files.
    However, you can use any tool of your choice to reallocate the options bytes in your binary file
    and then download it with J-Link Commander using the command loadbin .

    Best regards,
    Niklas
    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: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Niklas,

    I have used Jflash to relocate option bytes and I have tried loadfile command to flash *.mot file to target, I got an error "Writing target memory failed".
    What could be going wrong?
    Attached the screen shot.
    Images
    • Jlink flash.JPG

      73.37 kB, 675×470, viewed 1,907 times
  • Hello Harish,

    According to your J-Link Commander screenshot, you did not select the "STM32F103C6 (allow opt. bytes)" variant. "STM32F013C6" *without* "allow opt. bytes" does not allow to program the option bytes. Furthermore, i noticed that you are using a old version of the J-Link software. Can you please update to the latest one (V5.10k) and give it another try with the command line option below?

    JLink.exe -device "STM32F103C6 (allow opt. bytes)" -if SWD -speed 1000 -autoconnect 1

    Now enter the commands:
    r
    loadfile <File>

    Attached to this answer are:
    - 1 J-Link Commander screenshot of a successful session
    - The used data file which includes test data for the internal flash [0x8000000 - 0x8007FFF) + default values for the option bytes [0x6000000 - 0x600000F]


    Best regards
    Erik

    Files
    • TestData.zip

      (27.45 kB, downloaded 663 times, last: )
    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: segger.com/ticket/

    Or you can contact us via e-mail.
  • Good to hear that it is working on your side as well.
    Does it work with ST link V2 jtag emulator or it works only with segger emulator?
    Do you refer to using the J-Link Commander with ST Link? If yes, the answer is no: J-Link Commander can be used with SEGGER products, only.


    Best regards
    Erik
    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: segger.com/ticket/

    Or you can contact us via e-mail.