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);
}