[SOLVED] Writing more than 1024 Bytes into FLASH via J-Link results in unintended sector erase

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

  • [SOLVED] Writing more than 1024 Bytes into FLASH via J-Link results in unintended sector erase

    Hello SEGGER Team,

    I have made some experiments with my EFM32HG322F64 MCU and experienced the following. If I want to write 1024 or more Bytes into the FLASH then other parts of the given sectors get erased (please see dump1.bin). This MCU I’m using has 64 kByte FLASH and 1 kByte sector size, but I managed to reproduce this phenomenon with other MCUs and chips as well, so it is definitely not the fault of the MCU I’m using right now. It is also important to mention that this issue only occurs if I write 1024 or more Bytes and the sector size did not influence this (I tried with other MCUs as well where the sector size was smaller or larger). However, if I write less than 1024 Bytes then there is no problem, regardless of the starting address and/or crossing sector boundary.

    Let’s say I want to write 1024 Bytes 0xAAs in the range of 0x000 – 0x400 sector. Everything works well. However if I cross the sector boundary, let’s say 0x001 – 0x401 then other parts of the given sectors gets erased (other sectors remain intact, please see dump1.png and dump1.bin):


    The interesting part is that if I create 3 kBytes of 0xBBs and first load it then this problem does not occur, so other parts of the sectors do not get erased (please see dump2.png and dump2.bin):


    I have collected the commands I’m using via J-Link Commander in .txt files (JLinkCommanderCommands1.txt and JLinkCommanderCommands2.txt) and I also attached the .bin files so that you can also reproduce the issue.

    Have you seen such an issue before and could you propose how to fix it?

    Thanks in advance
    Files
  • Hi,
    what you experience is intended behavior and does not require a "fix" as nothing is broken.

    Short explanation:
    - Most flashes can only be written when in erased state.
    - A sector is the smallest unit that can be erased.
    => To write data to a programmed sector, the sector must be erased first.

    The reason why this is only happening if > 1KB is written is,
    that by default J-Link will use read-modify-write (RMW) for all data that is to be programmed if it is < 1KB (RMW threshold).
    This means, J-Link
    1) reads back the entire sector and merges it with the data to be written,
    2) erases the sector and
    3) programs the whole sector with the merged data.
    If the size of the data is bigger than the RMW threshold, 1) is skipped.

    For further information and how to adjust the RMW threshold, please refer to the following article:
    wiki.segger.com/Read-Modify-Write_Flash

    BR
    Fabian
    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.
  • Hi SEGGER - Fabian,

    Thank you very much for you quick help and detailed explanation. Setting the RMW threshold based on the article you referenced solved my issue.
    Once again, thank you.

    Regards,
    GVG
  • Hi GVG,
    Good to hear that you are up and running again.

    We will close this thread now.

    BR
    Fabian
    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.