Problem with sketch EEPROM read/write only with STM32 and not with AVR

Hello. This sketch works with AVR.
Is not working with STM32.
Any Ideas why?

#include <EEPROM.h>

unsigned int serverport = 11111;
unsigned int serverport2 = 22222;
unsigned int INTERVAL = 55555;  

   byte high = EEPROM.read(27);
   byte low = EEPROM.read(28);
   unsigned int serverportnew=word(high,low);

   byte high2 = EEPROM.read(29);
   byte low2 = EEPROM.read(30);
   unsigned int serverportnew2=word(high2,low2);

   byte high1 = EEPROM.read(31);
   byte low1 = EEPROM.read(32);
   unsigned int INTERVAL5=word(high1,low1);  

void setup()
{

 Serial.begin(9600); 
 Serial.println("START..");   

}  

void loop()
{    
 Serial.print("eeprom 27,28 :  ");
 Serial.println(serverportnew);

 Serial.print("eeprom 29,30 :  ");
 Serial.println(serverportnew2);

 Serial.print("eeprom 31,32 :  ");
 Serial.println(INTERVAL5);

 delay(4000);

 EEPROM.update(27,highByte( serverport));
 EEPROM.update(28,lowByte ( serverport));

 EEPROM.update(29,highByte(serverport2));
 EEPROM.update(30,lowByte(serverport2));

 EEPROM.update(31,highByte(INTERVAL));
 EEPROM.update(32,lowByte(INTERVAL));

 delay(4000);
 
}

EEPROM_TEST1.ino (1.1 KB)

"Does not work" is the most terrible description of the problem. What does happen? What do you expect?

Also, please edit you post to include code tags. See "How to use the forum".

The STM32 doesn't have any EEPROM.

I expect in the first "RUN" to read the EEPROM 0 or 65535 and after the sketch finish the first loop , after "RESET" the second "RUN" the values 11111 , 22222 , and 55555 must be displayed at serial.
With arduino nano and 2560 this sketch is OK. With STM32 is always reading 65535.

If I move the :

byte high = EEPROM.read(27);
byte low = EEPROM.read(28);
unsigned int serverportnew=word(high,low);

byte high2 = EEPROM.read(29);
byte low2 = EEPROM.read(30);
unsigned int serverportnew2=word(high2,low2);

byte high1 = EEPROM.read(31);
byte low1 = EEPROM.read(32);
unsigned int INTERVAL5=word(high1,low1);

from the Global variables to the void setup or to the void loop, sketch is functional with EEPROM . But why the behaviour is different in AVR and STM32 ?

The STM32 indeed has no EEPROM, but given it doesn't fail to compile (aka, can find a EEPROM.h) suggests the Arduino core has a "fake" EEPROM implementation just like the ESP.

For a start, try to make a simplified version which just reads and writes a single byte :slight_smile:

PS If you make changes to the code and want to share the outcome, please also share the new code. How trivial that new code may look.

BJHenry:
The STM32 doesn't have any EEPROM.

The library EEPROM.h is occupying some space from the Flash EPROM and emulating EEPROM.
All the functions with EEPROM are the same.

I have successfully saved data to the EEPROM STM32 Blue Pill.
Data remains stored even though STM32 has been reset or lost power.
Please read on this website.