Library 45- Interface backup SRAM on STM32F4

Almost all (with few exceptions) STM32F4xx MCUs have internal backup SRAM, which stores data, if power is available at least on Vbat rails.

These MCUs have internal 4-kBytes of SRAM. Backup SRAM can be also used as EEPROM, if your Vbat supply is always active, so you can store data which will stay there also if you reset your device. You just have to make sure that you don’t shut down your power supply or re-write them during startup sequence of MCU.

Difference between backup SRAM and normal SRAM is that backup SRAM stays the same if main voltage is off (but Vbat is still active), while classic SRAM will loose data stored inside.

Library

Features

  • Interface 4-kBytes of backup SRAM
    • Does not work on STM32F401/411 and some others, backup SRAM not-present devices
  • Read/Write 8-bit value
  • Read/Write 16-bit value
  • Read/Write 32-bit value
  • Read/Write float value
  • Version 1.1 – December 22, 2014
    • Support for read/write float numbers

Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx PWR
  • TM
    • defines.h

Functions

Sketches

In this section, I will show you, how to “fill” entire backup SRAM correctly, so you will not get like “HardFault” error or any other.

  • Fill entire backup SRAM with 8-bit values
  • Fill entire backup SRAM with 16-bit values
  • Fill entire backup SRAM with 32-bit values

Example

Example below works really easy. When you upload your code, first release usb power and put back again, that you reset everyting first.

After power on, you will se one LED on:

  • RED led on: device was first time configured and value was written to backup sram
    • If you see this, then press reset button
  • GREEN led on: device read data back from backup SRAM successfully

Project is available on Github, download library below.

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...