So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By dlx
#74836 Hello,

I have an ESP12F with 4M Bytes of memory.
When I run the command ESP.getFlashChipRealSize(), I get 4 194 304 bytes.

I am using the arduino library 8266 core 2.4.1
My arduino IDE 1.8.5 settings are "Board generic ESP8266 Module" and "Flash size 4M(1M SPIFFS)".
(In fact I don't need SPIFFS).

My program size is 251 404 bytes.
So when I use: eeprom.begin(4096) + EEPROM.read(0) I am reading the byte at the address:
251 404(program) + 1 048 576(1M spiffs) + 1
Is it correct?

And why am I limited to 4096 with the eeprom.begin when I have 4 194 304 - 251 404 - 1 048 576 = 2 894 324 free bytes?
Why are we limited to one sector and how to read/write past this sector?

Many thanks for your help
User avatar
By Pablo2048
#74843 Just look into EEPROM.cpp and you can see computed address for eeprom begin (in constructor of EEPROMClass) and in begin method you will see that eeprom is simulated byt creating shadow buffer in RAM memory (_data = new uint8_t[size]). IMHO this explain all your questions...
User avatar
By dlx
#74848 Thanks for your answer, nevertheless it is not so clear for me. Prior to posting this message I had already opened the EEPROM.cpp file and understood that EEPROM.begin(1000000) was still limited inside the function by the SPI_FLASH_SEC_SIZE.
After your comment I read it again and realized there are two class constructors:
EEPROMClass::EEPROMClass(uint32_t sector)
and EEPROMClass::EEPROMClass(void)

I would like to write a simple program to test the EEPROM.
To do this, I need to know how much EEPROM space is left, write a for loop to write inside each byte of the free space and read the EEPROM again to check the content.

Below is what I did before posting my question. Of course it didn't work and I only got 4096 good values, all the rest being 0.
I read the EEPROM.cpp and understood it was limited.

Even after your comment, I still don't know how to use the free EEPROM space at its maximum.

Would you explain it again please?

Thanks,


====================================================
void setup() {
Serial.begin(115200);
while (!Serial) ;
EEPROM.begin(4194304);
}

void loop() {
Serial.print("Flash real size: ");
Serial.println(ESP.getFlashChipRealSize(), DEC);

Serial.println("****** eepromWriting ******");
for (long i=0; i<EEPROM_SIZE; i++){
EEPROM.write(i,170);
yield();
}
EEPROM.commit();


Serial.println("****** eepromReading ******");
for (long index = 0 ; index < EEPROM_SIZE ; index++) {
Serial.print(EEPROM.read(index), HEX);
Serial.print(" ");
if (index%40==0 && index != 0){
Serial.println();
}
yield();
}
}
====================================================
User avatar
By Pablo2048
#74922 1. if you have opened EEPROM.cpp before, then you certainly know, that your math for first address of EEPROM was wrong (actual sketch size does not take effect in eeprom address computation, EEPROM starts on flash sector boundary)
2. because of the naturality of Flash (need for sector erase before write new content) and to lower the need of sector rewrite there is shadow RAM buffer with same size as EEPROM. ESP8266 has 80kB RAM (~30-40kB available for sketch) so it is nonsense to waste RAM to make more EEPROM-like Flash.
3. EEPROM library does not do any kind of wear leveling (as SPIFFS does) so every EEPROM.commit overwrite whole Flash sector even when you change only single byte in EEPROM. Flash has limited number of sector rewrite to about 10000 AFAIK.
4. If you want to use remaining Flash then you have to use functions to access flash, which EEPROM library already use (spi_flash_erase_sector, spi_flash_write, spi_flash_read, spi_flash_erase_sector).
5. there was (or is) attempt to eliminate need for RAM buffer as i remember, but I don't remember how this effort end (search git Arduino for ESP8266 for new EEPROM library, EEPROM+, ...)