Skip to main content
Explorer
December 30, 2024
Solved

Preserving EEPROM-Emulation area when programming new code - VScode with JLink

  • December 30, 2024
  • 2 replies
  • 987 views

I already posted this question on stackexchange, but unfortunately no answers, so please don't me asking here again.

I'm using the last flash page (page 31: 0x0800 F800 - 0x0800 FFFF2) as eeprom emulation area on my STM32G030C8.
I'm working with VScode and programming + debugging the flash with JLink over USB.

Is there a way to prevent the eeprom emulation area from being erased when programming new code, as there is stored some calibration data?

Where or how can I manage erasing only part of the flash, when using normal build and debugging command in VScode?

Thanks!

    This topic has been closed for replies.
    Best answer by ETX
    Thanks for your feedback.
     
    By now I solved my problem this way:
     
    (1) Modify the linker script 'STM32G030C8Tx_FLASH.ld' and add the EE emulation area
    MEMORY
    {
    RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 8K
    FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 62K
    EMULATED_EEPROM    (xrw)   : ORIGIN = 0x0800F800,   LENGTH = 2K
    }
     
    /* Define output sections */
    SECTIONS
    {
    /* The startup code into "FLASH" Rom type memory */
      .ourData :
      {
    . = ALIGN(4);
    *(.ourData)
    . = ALIGN(4);
      } >EMULATED_EEPROM
    .
    .
    .
     
    (2) Change linker script name (to e.g. STM32G030C8Tx_EE_FLASH.ld) for MXCube not to erase it when updating code
    (3) Modify linker script path in 'CMakeLists.txt' like this
     
    # Set linker script
    set(linker_script_SRC               ${PROJ_PATH}/STM32G030C8Tx_EE_FLASH.ld)
    set(EXECUTABLE                      ${CMAKE_PROJECT_NAME})
     
    I've been reading out the memory areas and it seems to work fine.
    If there is anything wrong or to improve, please give some feedback.
    Thanks.

    2 replies

    Super User
    December 30, 2024

    Does the J-Link (J-Flash) do full erase? Is this what it says in its log?

    Just ensure that your program file (elf or hex) does not contain code or data in these flash sectors and they should not be erased when programming.

     

    ETXAuthorAnswer
    Explorer
    December 30, 2024
    Thanks for your feedback.
     
    By now I solved my problem this way:
     
    (1) Modify the linker script 'STM32G030C8Tx_FLASH.ld' and add the EE emulation area
    MEMORY
    {
    RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 8K
    FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 62K
    EMULATED_EEPROM    (xrw)   : ORIGIN = 0x0800F800,   LENGTH = 2K
    }
     
    /* Define output sections */
    SECTIONS
    {
    /* The startup code into "FLASH" Rom type memory */
      .ourData :
      {
    . = ALIGN(4);
    *(.ourData)
    . = ALIGN(4);
      } >EMULATED_EEPROM
    .
    .
    .
     
    (2) Change linker script name (to e.g. STM32G030C8Tx_EE_FLASH.ld) for MXCube not to erase it when updating code
    (3) Modify linker script path in 'CMakeLists.txt' like this
     
    # Set linker script
    set(linker_script_SRC               ${PROJ_PATH}/STM32G030C8Tx_EE_FLASH.ld)
    set(EXECUTABLE                      ${CMAKE_PROJECT_NAME})
     
    I've been reading out the memory areas and it seems to work fine.
    If there is anything wrong or to improve, please give some feedback.
    Thanks.