cancel
Showing results for 
Search instead for 
Did you mean: 

how can I store something in a non volatile memory, any simple example to start with ?

Raider E
Associate III
Posted on May 29, 2017 at 02:55

I just would like to store one or two values in the in a non volatile memory and not sure how to do it.any ideas or a an example to start with.

Many thanks

1 REPLY 1
Zt Liu
Senior III
Posted on May 31, 2017 at 16:38

hi, Raider!

You may first decide whether your data will be placed in flash or eeprom(if any).

For example, 

I have a STM32L011 on my desk, 

there are 512 bytes of eeprom.

I may use following code to write and read eeprom, using cubeMX

static uint32_t eepromData;

HAL_FLASHEx_DATAEEPROM_Unlock();

//write eeprom

HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAM_WORD,DATA_EEPROM_BASE, 0x12345678);

//read eeprom

memcpy(&eepromData,(void*)DATA_EEPROM_BASE,sizeof(uint32_t));

Similar examples are presented in CubeMx project examples in FLASH folder.

Good Luck!

Zt

.