AnsweredAssumed Answered

STM32F2xx Save User Data (ie virtual eeprom)

Question asked by manderin.tim on Apr 1, 2014
Latest reply on Apr 1, 2014 by Clive One

I have been attempting to store a few bytes in some non-volatile memory on the STM32fxx. From what I understand, there are two places to save data that does not require vbat battery backup... I may be out to lunch, but this is what I understand?

1) rtc backup (RTC->BKP0R)
2) Flash program memory

I have attempted to store user data in both of these locations without success. Here are the functions that I used which only seem to work while the chip is powered. Once the power is cycled, their values are lost.

1) Store the variable in the RTC Backup memory

void ee_write_to_backup_rtc(uint32_t data, uint32_t offset) {

 PWR_BackupAccessCmd(ENABLE);

 uint32_t tmp = (uint32_t)&(RTC->BKP0R);

 tmp += offset;

 *(__IO uint32_t *)tmp = (uint32_t)data;

 PWR_BackupAccessCmd(DISABLE);

 }

uint32_t ee_read_from_backup_rtc(uint16_t offset) {

 uint32_t tmp = (uint32_t)&(RTC->BKP0R);

 tmp += offset;

 return (*(__IO uint32_t *)tmp);

}

2) Store the variable in the ROM by modifying the value using the Flash functions

const uint32_t _EEPROM[6] = { 0, 0, 0, 0, 0, 0 };

void ee_write_to_backup_rtc(uint32_t data, uint32_t offset) {

 FLASH_Unlock();

 FLASH_ProgramWord((uint32_t)&_EEPROM + offset, data);

 FLASH_Lock();

}

uint32_t ee_read_from_backup_rtc(uint16_t offset) {

  return _EEPROM[offset];
}
 

Outcomes