Retained memory

retained, Backup RAM, SRAM, Static RAM

Gen 3 Devices (B-Series SoM, Tracker SoM, Tracker One, Boron, Argon, and E404X):

A 3068 bytes section of backup RAM is provided for storing values that are maintained across system reset and hibernate sleep mode. Unlike EEPROM emulation, the backup RAM can be accessed at the same speed as regular RAM and does not have any wear limitations.

On Gen 3 devices (Argon, Boron, B-Series SoM, Tracker SoM), retained memory is only initialized in Device OS 1.5.0 and later. In prior versions, retained memory would always be uninitialized on first power-up.


P2 and Photon 2 Devices:

The P2 and Photon 2 have limited support for retained memory in Device OS 5.3.1 and later.

Retained memory is preserved with the following limitations:

  • When entering HIBERNATE sleep mode.
  • Under programmatic reset, such as System.reset() and OTA firmware upgrades.
  • In limited cases when using pin reset (RESET button or externally triggered reset).

By default, the retained memory is saved every 10 seconds, so changes made to retained variables between the last save and an unplanned system reset will be lost. Calling System.backupRamSync on the P2 and Photon 2 can make sure the data is saved. The data is saved to a dedicated flash page in the RTL827x MCU however you should avoid saving the data extremely frequently as it is slower than RAM and will cause flash wear.

Prior to Device OS 5.3.1, retained memory is not supported. The flash file system can be used, or you can use an external chip such as an I2C or SPI FRAM.


Gen 2 Devices (E-Series, Electron, Photon, and P2; does not include E404X):

The STM32F2xx features 4KB of backup RAM (3068 bytes for Device OS version v0.6.0 and later) of which is available to the user. Unlike the regular RAM memory, the backup RAM is retained so long as power is provided to VIN or to VBAT. In particular this means that the data in backup RAM is retained when:

  • the device goes into deep sleep mode (SLEEP_MODE_DEEP or HIBERNATE)
  • the device is hardware or software reset (while maintaining power)
  • power is removed from VIN but retained on VBAT (which will retain both the backup RAM and the RTC)

Note that if neither VIN or VBAT is powered then the contents of the backup RAM will be lost; for data to be retained, the device needs a power source. For persistent storage of data through a total power loss, please use the EEPROM.

Power Conditions and how they relate to Backup RAM initialization and data retention:

Power Down Method Power Up Method When VIN Powered When VBAT Powered SRAM Initialized SRAM Retained
Power removed on VIN and VBAT Power applied on VIN - No[1] Yes No
Power removed on VIN and VBAT Power applied on VIN - Yes Yes No
Power removed on VIN Power applied on VIN - Yes No Yes
System.sleep(SLEEP_MODE_DEEP) Rising edge on WKP pin, or Hard Reset Yes Yes/No No Yes
System.sleep(SLEEP_MODE_DEEP,10) RTC alarm after 10 seconds Yes Yes/No No Yes
System.reset() Boot after software reset Yes Yes/No No Yes
Hard reset Boot after hard reset Yes Yes/No No Yes

[1] Note: If VBAT is floating when powering up for the first time, SRAM remains uninitialized. When using this feature for Backup RAM, it is recommended to have VBAT connected to a 3V3 or a known good power source on system first boot. When using this feature for Extra RAM, it is recommended to jumper VBAT to GND on the Photon, P1, and Electron to ensure it always initializes on system first boot. On the Electron, VBAT is tied to 3V3 and you must not connect it to GND.