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?
(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.