Retained memory

Gen 3 Devices (nRF52) (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.

Gen 4 Devices (RTL872x) (P2, Photon 2, and M-SoM):

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

Retained memory is preserved on RTL872x devices in the following cases:

Case Saved
When entering sleep modes 5.3.1 and later
OTA firmware updates 5.3.1 and later
System.backupRamSync() 5.3.1 and later
System.reset() Not saved
Reset button or reset pin Not saved
Every 10 seconds 5.3.1 to 5.8.0 only

Calling System.backupRamSync() will manually save the contents of retained memory to a dedicated flash page on the RTL872x processor and will be restored after the device is reset. You should avoid saving the data extremely frequently as it is slower than RAM and will cause flash wear and is relatively slow to execute.

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

Retained memory is 3068 bytes.

Gen 2 Devices (STM32) (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.