Library 45- Interface backup SRAM on STM32F4

Almost all (except STM32F401/STM32F411) STM32F4xx MCUs have internal backup SRAM, which stores data, if power is at least on Vbat, or main voltage is active.

These MCUs have internal 4-kBytes of SRAM. It is on location where if you read “too much” you can make a HardFault error and this is something you don’t want. So be careful when you are doing with this ram.

Backup SRAM can be also used as EEPROM, if your Vbat battery 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.

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

Important: If you will try working with backup SRAM on STM32F401 or STM32F411 devices, you will get “HardFault” error when you will try to read from backup SRAM register locations.

These devices don’t have backup SRAM inside so do not try to do that or your device can stuck.

Also, not available on any STM32F4 Nucleo board.

Library

Features

  • Interface 4-kBytes of backup SRAM
    • Does not work on STM32F401/411
  • 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!