Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Backup SRAM as EEPROM in STM32F4

There are two ways of emulating EEPROM on the STM32F4:

  1. On-chip 4 Kbytes backup SRAM
  2. On-chip Flash, with specific software algorithm

The second option is described here: AN3969.

But google, unfortunately, hasn't been able to provide information on how to use the first option - using the 4Kb of backup SRAM as EEPROM?..

Can anyone help on the topic?

like image 780
Jolle Avatar asked Dec 18 '13 20:12

Jolle


People also ask

What is backup SRAM?

The backup SRAM's user area is used to save not only the Alarm History data but also the sampling data, internal device backup data, and filing data. The capacity of the backup SRAM that can be used for Alarm History data depends on the type of display unit and the space used by other data.

What is backup domain in stm32?

The STM32L496 includes 32 backup registers (each 32-bit) that can be written/read and protected and are included in the backup domain. This domain also includes the RTC and remains powered by VBAT when VDD power is switched off (provided that VBAT remains powered).


1 Answers

must do these:

  1. Enable the PWR clock

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    
  2. Enable access to the backup domain

    PWR_BackupAccessCmd(ENABLE);
    
  3. Enable backup SRAM Clock

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);
    
  4. Enable the Backup SRAM low power Regulator to retain it's content in VBAT mode

    PWR_BackupRegulatorCmd(ENABLE);
    

and you can write/read datas to sram (these codes from BKP_Domain codes in STM32F4xx_DSP_StdPeriph_Lib) (in my mcu stm32f417 BKPSRAM_BASE=0x40024000)

   // Write to Backup SRAM with 32-Bit Data 
   for (i = 0x0; i < 0x100; i += 4) {
       *(__IO uint32_t *) (BKPSRAM_BASE + i) = i;
   }

   // Check the written Data 
   for (i = 0x0; i < 0x100; i += 4) {
          if ((*(__IO uint32_t *) (BKPSRAM_BASE + i)) != i){
              errorindex++;
          }
   }

then if you want:

    // Wait until the Backup SRAM low power Regulator is ready
    while(PWR_GetFlagStatus(PWR_FLAG_BRR) == RESET)
    {}

you can find these functions in STM32F4xx_DSP_StdPeriph_Lib.

like image 105
ytasan Avatar answered Sep 30 '22 09:09

ytasan