Using STM32L475RCT to implement EEPROM crashes

Post here first, or if you can't find a relevant section!
Post Reply
karta146831
Posts: 1
Joined: Sat Jun 11, 2022 7:43 pm

Using STM32L475RCT to implement EEPROM crashes

Post by karta146831 »

HI Everyone

The board I use is STM32L475RCT6
I've tried three different libraries and official sample programs
But no matter which kind, the compilation is normal,it will crash directly when executed

1. https://github.com/khoih-prog/FlashStor ... EEPROM.ino

2.https://github.com/S-LABc/using-interna ... eeprom.ino

3.https://github.com/stm32duino/STM32Exam ... EEPROM.ino


Below is the function of the EEPROM I wrote using the UNO and ESP32, I don't know how to modify it to make it work on the L475

Hope someone can tell me what's wrong

#include <EEPROM.h>

String cmd;
String ID;
// define the number of bytes you want to access
#define EEPROM_SIZE 4096

void setup() {
Serial.begin(115200);
// initialize EEPROM with predefined size
EEPROM.begin(EEPROM_SIZE);
}
////
void writeStringToEEPROM(int addrOffset, const String &strToWrite)
{
byte len = strToWrite.length();
EEPROM.write(addrOffset, len);
for (int i = 0; i < len; i++)
{
EEPROM.write(addrOffset + 1 + i, strToWrite);
}
}
String readStringFromEEPROM(int addrOffset)
{
int newStrLen = EEPROM.read(addrOffset);
char data[newStrLen + 1];
for (int i = 0; i < newStrLen; i++)
{
data = EEPROM.read(addrOffset + 1 + i);
}
data[newStrLen] = '\0';
return String(data);
}
////
void loop() {
if (Serial.available()) {
String s = "";
while (Serial.available()) {
char c = Serial.read();
if(c!='\n'){
s += c;
}
delay(5);
}
if(s!=""){
cmd =s;
//Serial.println(cmd);
if(cmd.substring(0,3)=="ID=")
{
ID = cmd.substring(3,6);
Serial.println(ID);
//EEPROM.write(0,ID);
writeStringToEEPROM(0,ID);
EEPROM.commit();
Serial.println("OK");
delay(100);
}

else if(cmd=="ID?\r")
{
String retrievedString = readStringFromEEPROM(0);
Serial.println(retrievedString);
delay(100);
}
else if(cmd=="help\r")
{
Serial.println("ID?");
Serial.println("ID=");
}
else{}

}
}//if (Serial.available())

}//loop
Post Reply

Return to “General discussion”