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

Converted EEPROM library to use nvs instead of partition. #2678

Merged
merged 6 commits into from
Apr 23, 2019
Merged

Converted EEPROM library to use nvs instead of partition. #2678

merged 6 commits into from
Apr 23, 2019

Conversation

lbernstone
Copy link
Contributor

Converted EEPROM library to use nvs instead of partition.
Removed eeprom partition from all partition table CSV files.

…rom partition from all partition table CSV files.
nvs_commit(_handle);
nvs_set_blob(_handle, _name, hold_data, size);
free(hold_data);
nvs_commit(_handle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole block of code needs some comments to explain exactly what is going on :) I got lost with all those reads, writes and erases. What data is where... you need 2 blobs to hold the default 4K EEPROM, but reading through your code I got lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no way to expand a key, so in order to do so, it tests for free space, then holds the data while it deletes the key. If it is a new key, it just fills with zeros. I think changing the variable name to key_data will make it clearer.

@me-no-dev
Copy link
Member

left a few notes :)

@@ -117,11 +105,10 @@ class EEPROMClass {
template <class T> T writeAll (int address, const T &);

protected:
uint32_t _sector;
nvs_handle _handle;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you maybe forward declare the nvs_handle so it is not required to include nvs in the header?

Serial.println(EEPROM.readByte(address));
address += sizeof(byte);

Serial.println(char(EEPROM.readChar(address)));
Copy link
Contributor

@stickbreaker stickbreaker Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually compile? Shouldn't it be println((char)EEPROM.readChar(address));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

travis would have complained :) not sure how Make will like it though

Serial.println(EEPROM.readString(address));
address += sentence.length();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Length +1?

@me-no-dev me-no-dev merged commit 619568d into espressif:master Apr 23, 2019
@lbernstone lbernstone deleted the EEPROM2nvs branch April 23, 2019 21:07
@pgrisu
Copy link

pgrisu commented Apr 27, 2019

This is a good feature that save a bit of flash space but it breaks all deployed systems where factory settings are stored into EEPROM flash partition.
Already deployed devices based on previous arduino-esp32 will lose all EEPROM factory/config settings if they move to latest release by FOTA
@me-no-dev Please remember to mark this change as 'breaking changes' in next release notes

@me-no-dev
Copy link
Member

Will do! @lbernstone any ideas on how that can be detected and moved to NVS?

@fedy0
Copy link
Contributor

fedy0 commented Sep 11, 2019

@me-no-dev
The new move of the EEPROM by this pull request from flexible flash data partition to NVS, in my opinion, is superfluous

My reasons:
[1] Already Existing Interface: The Preference library already provides a complete and an excellent friendly access to ESP32's Non-Volatile Storage. As a novice in software, I've always been warned not to repeat myself
[2] Not Backward Compatible: The pull request breaks changes not only in deployed systems (which is fatal) as mentioned by @pgrisu but also in the classical EEPROM examples.
[3] NVS Usage: Non-Volatile Storage (NVS) was primarily designed to store key-value pairs in flash which the preference library mastered.
[4] Flexibility: The partition table already encouraged user-defined partitions (with data subtypes starting @0x99) which EEPROMClass can enjoy that this pull request deprecated.
[5] Same storage: All data partitions are on one flash memory with predefined subtypes (as used in the partition table) acting as constraints to their method of usage. If an NVS partition is truncated (for example, when the partition table layout is changed), its contents should be erased which is same for the previous EEPROM implementation. Why move the EEPROM?

arduino-esp32 is too matured to start having breaking changes caused by memory partitioning.
Thanks once again for your great contribution in the Preference library @me-no-dev

@tomtobback
Copy link

Hi, in addition to breaking EEPROM it also breaks any files stored earlier in SPIFFS; the SPIFFS offset moved from 0x291000 to 0x290000. On on my system, any SPIFFS files saved with core 1.0.2 cannot be read by core 1.0.3. I can only read SPIFFS with 1.0.3 when i edit my partitions/default.csv back to the 1.0.2 values (line 6: spiffs). Those 1000 bytes gained are not worth breaking backward compatibility in my humble opinion. I was surprised not to find any documentation on this because i assume lots of people have/will run into this problem.

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

Successfully merging this pull request may close these issues.

6 participants