F411 EEPROM issues, F103 EEPROM size

Post Reply
tkelly2784
Posts: 1
Joined: Sat Jan 02, 2021 11:01 pm

F411 EEPROM issues, F103 EEPROM size

Post by tkelly2784 »

Hello, this is my first post.

I was wanting to create a piece of code that tests the write cycle life of the flash memory in a black pill F411 using the EEPROM method. I have a friend who thinks at 10,000cycles the device will be destroyed haha. EEPROM read and write do not function correctly. I have no problem putting and getting in the setup area of the code and the data is retained over a reset. In the loop it will put and get, but my integer data is reset to -1 (unsigned go to their max value, so something is setting that area = 0-1) no matter what it was before the reset.

Code: Select all

#include <EEPROM.h>
int f=0;
int g=0;

void setup() {
  int eeAddress = 0; //EEPROM address to start reading from
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  EEPROM.get(0, f);
  Serial.println("You just reset, here are the stored varialbes"); Serial.println(f);    //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.
  eeAddress += sizeof(f); 
  EEPROM.get(eeAddress, g);
  Serial.println(g);
  g += 1;
  EEPROM.put(eeAddress, g);
  //if this setup portion is run g will index and 
}


void loop() {
//If this loop is run g and f are reset to -1 after a reset cycle 
f += 2;
EEPROM.put(0,f);
Serial.println(f);
delay(60);
}
My other question is there a better example of how to set the number of pages allocated to EEPROM other than what is described here? Is there an example for a F103 or F411?
By default, EEPROM emulation storage correspond to the last sector/page of Flash,
and its size correspond to the size of the last sector/page.
Nevertheless it is possible to customize address and size used for EEPROM.
In this case, following switches should be defined (in variant.h or build_opt.h)

FLASH_BASE_ADDRESS
FLASH_DATA_SECTOR or FLASH_PAGE_NUMBER (depending on STM32 family used)
see example of variant implementation: https://github.com/stm32duino/Arduino_C ... 2/pull/938
Post Reply

Return to “PR's bugs and enhancements”