STM32F411CEU6 Backup Registers and SRAM

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
RedSky1
Posts: 2
Joined: Sun Jul 26, 2020 12:00 pm
Answers: 1

STM32F411CEU6 Backup Registers and SRAM

Post by RedSky1 »

Hi All,

First time poster and a bit of a rookie on STM32 and Arduino coding. I'm currently using the 1.9.0 Core and a STM32F411CEU6 based 'black pill'
and trying to use the 4KB SRAM these chips have to store variables in the backup battery backed memory.
I have a 3v lithium battery, positive on the VBAT pin and negative to ground and connecting the Black Pill using a 232 FTDI serial dongle, standard stuff.

Not a lot of information around on using this, The functions reference I found to write up some test code was in the Core backup.h source file to use enableBackupDomain() to enable the chip features and readBackupSRAM and writeBackupSRAM to read and write from SRAM.
The memory location (BKPSRAM_BASE) I found on a Google search for STM32F4 backup SRAM location but couldn't find this information in the datasheet.

The below code is what I have come up with to test out the RTC registers & SRAM functionality. The RTC register part works perfectly however the bit I am stuck on is specifically the SRAM part, I can get nothing but 0's back shown on the serial monitor no matter what I do or try.

If anyone has an ideas or has managed to get this working I would appreciate the feedback, I could be way off on the proper use of these functions.

Code: Select all

uint32_t WriteRegisterValue = 123456;
uint32_t ReadRegisterValue;
uint32_t WriteSRAMValue[10];
uint32_t ReadSRAMValue[10];

uint32_t BKPSRAM_BASE=0x40024000;

void setup() {
  Serial.begin(115200);
  delay (1000);

  enableBackupDomain(); 
}

void loop() {

  //Store number in RTC Backup Registers
  setBackupRegister(1, WriteRegisterValue);
  
  //Store numbers in RTC SRAM
  WriteSRAMValue[1]=244;
  WriteSRAMValue[2]=344;
  writeBackupSRAM(1, WriteSRAMValue, 2);
  
  delay(2000);
  
  //Retrieve number in RTC Backup Registers
  ReadRegisterValue = getBackupRegister(1);
  Serial.println(ReadRegisterValue);
  
  //Retrieve numbers in RTC SRAM
  readBackupSRAM(1, ReadSRAMValue, 2);
  Serial.println(ReadSRAMValue[1]);
  Serial.println(ReadSRAMValue[2]);
  
  delay(2000);
}
by RedSky1 » Mon Jul 27, 2020 4:21 am
Well turns out I answered my own question...

Why could I not easily find the memory address and could not get this SRAM stuff to work on the STM32F411? Because it does not have the 4KB SRAM on this variant!

The STM32F407/415 does, as does a number of others, the STM32F411 & STM32F401 in the common 'Black Pills' does not.

Looks like i'll need to make do with 80 bytes of RTC register memory as the flash writes in Emulated EEPROM are amazingly slow due to the need to clear the flash before each write.

That's a lesson for me, study the differences between chips in the same family more next time. I'll leave this here in the hope it may save someone else some time :)
Go to full post
RedSky1
Posts: 2
Joined: Sun Jul 26, 2020 12:00 pm
Answers: 1

Re: STM32F411CEU6 Backup Registers and SRAM

Post by RedSky1 »

Well turns out I answered my own question...

Why could I not easily find the memory address and could not get this SRAM stuff to work on the STM32F411? Because it does not have the 4KB SRAM on this variant!

The STM32F407/415 does, as does a number of others, the STM32F411 & STM32F401 in the common 'Black Pills' does not.

Looks like i'll need to make do with 80 bytes of RTC register memory as the flash writes in Emulated EEPROM are amazingly slow due to the need to clear the flash before each write.

That's a lesson for me, study the differences between chips in the same family more next time. I'll leave this here in the hope it may save someone else some time :)
picclock
Posts: 21
Joined: Sat Aug 14, 2021 8:21 am

Re: STM32F411CEU6 Backup Registers and SRAM

Post by picclock »

FWIW AN3969 states
For low-cost purposes, external EEPROM can be replaced using one of the following
features of STM32F40x/STM32F41x:
●On-chip 4 Kbytes backup SRAM
●On-chip Flash, with specific software algorithm
The STM32F40x/STM32F41x features 4 Kbytes backup SRAM that can be powered from
the VBAT supply when the main VDD supply is powered off.

As of July 24 the application note is still current. If it was incorrect I would think it would be amended or removed.

In addition, https://stackoverflow.com/questions/206 ... in-stm32f4 ,
gives further insight with code examples.

I haven't checked them out, but if true would make an excellent library project.

Hope this info is of use to others seeking knowledge.

best regards
picclock
GonzoG
Posts: 460
Joined: Wed Jan 15, 2020 11:30 am
Answers: 32
Location: Prudnik, Poland

Re: STM32F411CEU6 Backup Registers and SRAM

Post by GonzoG »

picclock wrote: Fri Jul 19, 2024 7:11 am ...
Hope this info is of use to others seeking knowledge.

best regards
picclock
Hope not as it's WRONG. Read what RedSky1 wrote 4 years ago...
Post Reply

Return to “General discussion”