2014-11-04 09:22 AM
I want to be able to store values in a non-volatile memory so that the microcontroller can load these settings at start up.
These settings might change at run-time and it is important for the systems functionality that these settings are stored. I know the only non-volatile memory on the STM32F103 is the flash and it is possible to save values on flash(emulated as EEPROM for ease of use) according to this Appnote ''EEPROM emulation in STM32F101xx and STM32F103xx microcontrollers (AN2594)''(http://www.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1743/LN1734/PF257846
) How can I store block of memory (struct data) in flash memory? One idea is to write this struct into flash half word by half word. Bad idea? Thanks a lot for your answers ;) #stm32f103-flash-memory2014-11-04 09:27 AM
The EEPROM Emulation is a bit ugly.
You'd just want to define a structure, a copy the new one in by erasing the sector/page and writing the flash a word at a time. You can access (read) the data in place. You could also journal copies of the structure and pick the most recent, as a method to reduce wear on the flash cells.2014-11-04 10:56 PM
For example I have this struc
struct
t_mastruct{
char
ch;
int
nb;
float
pi;
}
;
t_mastruct variable;
variable.ch
=
'a'
;
variable.nb
=
12345
;
variable.pi
=
3.141592
;
To write this on EEPROM, I do#define SETTINGSSAVED_FLASHADDR 0x0801FC00
FLASH_Unlock(); FLASH_ErasePage(SETTINGSSAVED_FLASHADDR);// How to write 'variabler' on EEPROM ? // Perhaps this ? /* uint32_t *p = (uint32_t*)&variable; uint32_t Address; for ( Address = 0; Address < sizeof(t_mastruct); Address++ ){ FLASH_ProgramHalfWord(SETTINGSSAVED_FLASHADDR, (volatile uint32_t)(*p)); SETTINGSSAVED_FLASHADDR += 2; } */ FLASH_Lock();