Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EEPROM cleared Suddenly. #3674

Closed
arihantdaga opened this issue Oct 3, 2017 · 4 comments
Closed

EEPROM cleared Suddenly. #3674

arihantdaga opened this issue Oct 3, 2017 · 4 comments

Comments

@arihantdaga
Copy link

Basic Infos

Hardware

Hardware: ESP-12E
Core Version: 1.8.3
Using Arduino Version.

Description

I am working on ESP8266 for quiet some time.Its been good so far. I am using EEPROM for storing some custom settings. For the purpose i am using Embedis Library(https://github.com/thingSoC/embedis). And i begin EEPROM using
EEPROM.begin(4096);
Most of the time its working fine, but one night suddenly EEPROM got flushed and it was left with 0xff for the complete 4096 bytes. It keep happening sometimes out of blue. For most of the time its working fine, but suddenly sometimes it is erased. I could not figure out any solid reason for this.

Settings in IDE

Module: ?NodeMCU 1.0 ?
Flash Size: 4MB/(3MB SPIFSS)
CPU Frequency: 80Mhz
Flash Frequency: 80Mhz
Upload Using: SERIAL

@devyte
Copy link
Collaborator

devyte commented Oct 3, 2017

@arihantdaga How long have you been using the eeprom? How often do you write to it?
The ESP doesn't have eeprom. The eeprom api is meant for compatibility, the data is really stored on the flash in a specific area, which means if you write too often, the flash sector(s) in question will wear out quickly and start failing.
The number of writes to a specific sector before damage depends on the flash vendor, but as a rule of thumb you consider 10000 full write cycles.

@arihantdaga
Copy link
Author

Thank you @devyte . I am using eeprom for storing settings as well as storing switch status(I have 5 switches).
I have been using it for quiet some time though. but what do you mean by " 10000 full write cycles." Does one eeprom.commit means one full cycle ? .
And what will happen after 10000 cycles, will it still work sometime and not work sometimes? or it stops working completely ? . Because in my case i am able to write the config and retrieve it but just sometimes it looses the data suddenly.

And 10,000 can be very less in my case, is there an alternative for persistent storage in esp apart from EEPROM then ? for storing settings. ?

@devyte
Copy link
Collaborator

devyte commented Oct 3, 2017

@arihantdaga after a sector is damages, anything can happen. It can fail to work at all, it can work somtimes, or what's worst of all, it can seem to work, but then the data is lost after some short time.
About the write cycle, you should read up on flash tech. I'm not sure exactly how the EEPROM layer works, nor how the flash api works either, but in general, when you write a piece of data, you have to read a page, erase the page, merge your data into what was read, and then write the page back. Depending on implementation of the translation layer, and of the writing code, this doesn't necessarily happen on every write operation. However, if you are writing small pieces of data, it will happen for the same sector each time.
I personally avoid the EEPROM like the plague, and also avoid using e.g.: Wifi with persistent true. And I use the SPIFFS for storing data, in a file. SPIFFS does wear leveling under the hood, so write operations get distributed all over the SPIFFS flash area, which is a lot.
This issue is either hardware issue, or usage error. In either case, closing, see #3655 .

@devyte devyte closed this as completed Oct 3, 2017
@php4fan
Copy link

php4fan commented Dec 4, 2023

I have observed the "eeprom" being randomly deleted a few times. I do always read and write small amounts of data in the same places, but there's no way I've got anywhere remotely near 10000 writes even on the boards that have been used the most. And the last time it has happened to me (today) it was on a brand new one.
I can't say for sure whether the data was deleted or corrupted, the only thing I can say for sure is it didn't have the value that had been stored, and that my code hadn't touched it since the last write.

I'm sure there is an issue with data being randomly deleted/rewritten. I don't know whether it's hardware or software, but if it was hardware it would mean that the flash memory is utter garbage and that seems very unlikely. If that was the case, wouldn't the program also get randomly corrupted? That I've never seen happen. I bet a few years from now you'll find out that there's actually been a bug the whole time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants