2025-02-26 9:58 AM
Hello everyone,
I want to store configuration data in a flash section that should be retained after updating the code on the controller / flashing a new program. Is this possible using the CubeIDE? If yes, how is it done. If no, can this be done otherwise? As far as I can tell, when downloading the code onto the microcontroller, the whole flash storage will be erased.
Thanks for your help!
2025-02-26 10:02 AM
CubeIDE will only erase as much flash as it needs for the programming:
So just make sure that your "user data" is outside that range
2025-02-26 10:14 AM
My observation sadly does not match with this description. I'm using a STM32H753 Nucleo board. I modified the linker script as follows:
MEMORY
{
RAM_D1 (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
DTCMRAM (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1920K
USER_FLASH(rw) : ORIGIN = 0x81E0000, LENGTH = 128K
}
So, I reserved Bank 2 Sector 7 as my own flash memory. Furthermore, I declared it as NOLOAD:
.user_flash(NOLOAD) :
{
*(.user_flash*);
} > USER_FLASH
But when trying to debug the program using the CubeIDE, the data from these sections is overwritten with 224 bytes of zeros followed by 228 Bytes of ones. (I might have mixed up the amount of zeros and ones here)
2025-02-26 10:18 AM
> CubeIDE will only erase as much flash as it needs for the programming:
But it erases all sectors occupied by the new program and does not restore previous data after the last byte of the programmed data. If your user data is stored in the last sector of the image after the program, make your own tool for updating.
2025-02-26 10:34 AM
@Pavel A. wrote:
[...] it erases all sectors occupied by the new program [...]
Thanks for your reply. Does the USER_FLASH section count as "occupied by the program"?
2025-02-26 11:56 AM
Everything contained in the resulting program counts as occupied by the program. Check the linker map file if not sure.
2025-02-26 12:30 PM
Perhaps use OBJDUMP to establish WHAT in the .ELF file is being put into a NOBITS section.
You can look at the .MAP too, but I tend to use the .ELF as the arbiter of what exactly the linked object is telling the programmer/loader to do.