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...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!