[SOLVED] Cannot write registers in STM32G491

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

  • [SOLVED] Cannot write registers in STM32G491

    Hello,

    I am developping an application that can run on multiple MCUs. I have tested my code on a nucleo G474 and I was flashing it using a 6-pin jlink on the gpios.

    I received the final board which has a STM32G791, and after configuring my code to support this MCU I tried to flash the board and it failed when the script tried to flash the binary.

    ****** Error: Failed to erase sectors 0 @ address 0x08000000 ((erase error))
    Failed to erase sectors.

    Unspecified error -1


    Attached are the scripts I used for both targets


    Source Code

    1. device stm32g474re
    2. speed 4000
    3. r
    4. #unlocking flash
    5. w4 0x08 0x45670123
    6. w4 0x08 0xCDEF89AB
    7. #read flash access control register
    8. mem32 0x0 1
    9. w4 0x0 0x00000602
    10. mem32 0x0 1
    11. mem32 0x20 1
    12. w4 0x20 0xF0000000
    13. mem32 0x20 1
    14. sleep 500
    15. # workaround to bypass flash verification
    16. exec SetSkipProgOnCRCMatch=0
    17. exec SetVerifyDownload=0
    18. loadfile path/to/app.bin 0x08000000
    19. r
    20. g
    21. q
    Display All



    Source Code

    1. device stm32g491re
    2. speed 4000
    3. r
    4. #unlocking flash
    5. w4 0x08 0x45670123
    6. w4 0x08 0xCDEF89AB
    7. #read flash access control register
    8. mem32 0x0 1
    9. w4 0x0 0x00000602
    10. mem32 0x0 1
    11. mem32 0x20 1
    12. w4 0x20 0xF0000000
    13. mem32 0x20 1
    14. sleep 500
    15. # workaround to bypass flash verification
    16. exec SetSkipProgOnCRCMatch=0
    17. exec SetVerifyDownload=0
    18. loadfile path/to/app.bin 0x08000000
    19. r
    20. g
    21. q
    Display All
    I am not sure what I'm doing wrong here. What is sure though, is that I can write registers on the nucleo board but not on the target board, but I can read them on both MCUs


    I tried to reset the options bytes as I've seen in an other post on this forum ([SOLVED] STM32L052 failed to erase sectors) using JLinkSTM32, but it failed with the message
    Unexpected IDCODE DEV_ID 0x0479 found.
    Which is weird because this IDCODE is specified in the STM32G4 reference manual

    What am I missing?

    Regards,
    Thomas

    The post was edited 1 time, last by Thomas Jeantet ().

  • Hi Thomas,
    Thank you for the inquiry.

    Regarding the commands:
    I had a quick glance at it and one major issue is that you do not write the registers you intend to write to.
    E.g. 0x08 is not the address of the FLASH_KEYR. It is the offset of the FLASH_KEYR to the Flash register base address.
    you would have to write to address 0x40022000 (Flash register base address) + 0x08 (FLASH_KEYR offset) to write the register.

    Regarding the JLinkSTM32-Utility:

    The STM32G491devies are CAT4 devices which were not yet handled by the STM32 Utility.
    I fixed this internally.
    The fix will be part of the next release planned for Friday this, or next week.

    Thank you for making this known to us.

    The latest version can always be downloaded here:
    segger.com/downloads/jlink#J-L…twareAndDocumentationPack

    Best regards,
    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.