[SOLVED] STM32L052 failed to erase sectors

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

  • [SOLVED] STM32L052 failed to erase sectors

    Hello,

    I have a custom board with a STM32L052C8, up until yesterday I was able to flash/erase it without any problem. Since this morning I get an error when flashing a new firmware:

    Source Code

    1. Found SWD-DP with ID 0x0BC11477
    2. Found SWD-DP with ID 0x0BC11477
    3. AP-IDR: 0x04770031, Type: AHB-AP
    4. Found Cortex-M0 r0p1, Little endian.
    5. FPUnit: 4 code (BP) slots and 0 literal slots
    6. CoreSight components:
    7. ROMTbl 0 @ F0000000
    8. ROMTbl 0 [0]: F00FF000, CID: B105100D, PID: 000BB4C0 ROM Table
    9. ROMTbl 1 @ E00FF000
    10. ROMTbl 1 [0]: FFF0F000, CID: B105E00D, PID: 000BB008 SCS
    11. ROMTbl 1 [1]: FFF02000, CID: B105E00D, PID: 000BB00A DWT
    12. ROMTbl 1 [2]: FFF03000, CID: B105E00D, PID: 000BB00B FPB
    13. Cortex-M0 identified.
    14. PC = 080009E4, CycleCnt = 00000000
    15. R0 = FFFFFFFF, R1 = FFFFFFFF, R2 = FFFFFFFF, R3 = FFFFFFFF
    16. R4 = FFFFFFFF, R5 = FFFFFFFF, R6 = FFFFFFFF, R7 = FFFFFFFF
    17. R8 = FFFFFFFF, R9 = FFFFFFFF, R10= FFFFFFFF, R11= FFFFFFFF
    18. R12= FFFFFFFF
    19. SP(R13)= 20002000, MSP= 20002000, PSP= FFFFFFFC, R14(LR) = FFFFFFFF
    20. XPSR = F1000000: APSR = NZCVq, EPSR = 01000000, IPSR = 000 (NoException)
    21. CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00
    22. Downloading file [stage/lpc_app.bin]...
    23. Comparing flash [100%] Done.
    24. Erasing flash [100%] Done.
    25. Verifying flash [100%] Done.
    26. J-Link: Flash download: Restarting flash programming due to program error (possibly skipped erasure of half-way erased sector).
    27. J-Link: Flash download: Skip optimizations disabled for second try.
    28. Error while programming flash: Programming failed.
    29. Reset delay: 0 ms
    30. Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
    Display All


    I have tried to manually erase the flash using J-Link but I get another error:

    Source Code

    1. Device "STM32L052C8" selected.
    2. Found SWD-DP with ID 0x0BC11477
    3. Found SWD-DP with ID 0x0BC11477
    4. AP-IDR: 0x04770031, Type: AHB-AP
    5. Found Cortex-M0 r0p1, Little endian.
    6. FPUnit: 4 code (BP) slots and 0 literal slots
    7. CoreSight components:
    8. ROMTbl 0 @ F0000000
    9. ROMTbl 0 [0]: F00FF000, CID: B105100D, PID: 000BB4C0 ROM Table
    10. ROMTbl 1 @ E00FF000
    11. ROMTbl 1 [0]: FFF0F000, CID: B105E00D, PID: 000BB008 SCS
    12. ROMTbl 1 [1]: FFF02000, CID: B105E00D, PID: 000BB00A DWT
    13. ROMTbl 1 [2]: FFF03000, CID: B105E00D, PID: 000BB00B FPB
    14. Cortex-M0 identified.
    15. J-Link>erase
    16. Erasing device (STM32L052C8)...
    17. Comparing flash [100%] Done.
    18. Erasing flash [045%]
    19. ****** Error: Failed to erase sectors 0 @ address 0x08000000 (erase error)
    20. 100%] Done.
    21. Verifying flash [100%] Done.
    22. J-Link: Flash download: Total time needed: 0.050s (Prepare: 0.043s, Compare: 0.000s, Erase: 0.001s, Program: 0.000s, Verify: 0.000s, Restore: 0.004s)
    23. ERROR: Erase returned with error code -5.
    Display All


    Why does the erase fail? I have searched the forum for a definition of the error codes but could not find one.
    Files
    • erase.txt

      (6.3 kB, downloaded 782 times, last: )
  • Hi,


    "Erase returned with error code -5." just means that the erase failed during the erase procedure (opposed to failing during preparation, ram check, etc...).

    I just gave it a try and erase / program worked fine for me with a STM32L053R8 target.

    Since it did work before, did anything change regarding your setup?
    Does this issue only occur with one board?

    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,

    It's only happening with this board so far, we downloaded a new firmware and since then we get the erase error.
    We are able to read the flash using J-Link but cannot erase it. It could be that the microcontroller got damaged, but the new firmware only had minimal changes.
  • Hi,


    can you please read out the option bytes (e.g. with J-Link Commander) and post them here?


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


    Sorry for the delay in response.

    The 0x00000000 @ 0x1FF80008 could be the issue.
    As far as I understand the manual, 0x1FF80008 is FLASH_WRPROT1 and should be 0xFFFF0000 like 0x1FF8000C and 0x1FF80010.

    Does this issue also occur if 0x1FF80008 is 0xFFFF0000?


    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,

    I manually wrote 0xFFFF0000 at address 0x1FF80008 and the error is gone, I can now flash a new firmware.
    My understanding was that in case of mismatch between high and low parts of the option bytes, default reset values were used, which was wrong...

    Thanks Niklas for your help!

    The procedure to manually reset the option bytes is not quite straight forward, would it be possible to add the STM32L0 family to the JlinkSTM32 tool?
  • Hi,


    good to hear that you are up and running!

    Regarding the STM32:
    Without wanting to promise anything, I think support for STML0x is planned for the next version (of the stm32 tool, not the software package), which should also support STM32H7.
    Unfortunately, the official reference documentation for STM32H7 is still not publicly available, which is currently blocking this project.

    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.
  • Hi Forum,


    STM32L0xxxx support has been added to the J-Link STM32 Unlock tool in the latest version of the J-Link software & documentation pack (beta), V6.15d.
    STM32H7xxxx support has not been added due to the lack of official documentation.


    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.