-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
esp32/modesp32.c: add esp32 non volatile storage support #4707
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
Conversation
Please what is the right way to deliver a test (ex: directory, similar test) ? |
This is fun! |
Thanks for the contribution, it looks quite good, to just read/write bytes objects. @Lisa999 how does this compare to your implementation? |
I see that the ESP IDF has functions to get/set a range of signed/unsigned integer types (8-64 bit). I don't know, is it worth exposing all of that functionality? |
@dpgeorge: This is a nice try, but i have to disagree with this approach. Here are my functions: example (code to see which reset has been performed for the next cycle): The only thing i'm doubting about is whether to put it into ESP or into ESP32... I happy to make a PR, IF you promise to pull #3576 after @andynd has fixed it. |
This follow Micropython's Django Principle. |
Django? Django is all-inclusive, Flask Lightweight. Even so, blob's should be used to store binary data. If you want to store strings, then use the nvs_set_str function. https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_flash.html
|
Thanks @Lisa999 for the input. It's probably a good idea to at least add "type" annotations to the method names so others can be added in the future if needed; such as Looking more at what the ESP IDF provides, I'd also suggest to make the NVS interface an object, rather than just functions in a module. This is because it's possible to open multiple NVS handles. It's like a mini database. Eg: nvs = esp32.NVS("my_storage", "w") # open read/write
nvs.set_i32("key", 1234)
nvs2 = esp32.NVS("other_storage", "r") # open read-only
blob = nvs2.get_blob("key2") |
See #4436 for a related issue. |
ESP-IDF Non-volatile storage library docs can be found here: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_flash.html (Link above is broken though the text is correct) |
@dpgeorge: Since you build the Partition class for the ESP32, i'll keep my part of the bargain and have NVS working for Micropython v1.11 . However it's still functions based, do you have an example of a good object based class so i can rewrite my code? |
I think the Also, it might be neater to use subscription to read/write NVS values, similar to how nvs = esp32.NVS('storage', 'w')
nvs.i32['key'] = 1234 # store value
print(nvs.blob['key2']) # retrieve value See |
Its not clear to me why Partition class needed to be merged before implementing NVS. There is very little interaction between OTA/Partition functions and nvs functions. @Lisa999 what was your intention in waiting for Partition functionality to be merged? Also are you working on this PR now ? |
@nevercast : the Partition PR is not connected to this PR. I already have a working NVS class, however not object oriented but function oriented. @dpgeorge refered to the Partition class as an example how to build something like an object oriented class. The NVS OO class is on my to do list, probably going to start with the next few weeks. |
@Lisa999 Any plans to finish OO implementation of NVS? |
Absolutely, as promised. Is on my todo list. However it gets overridden all the time by urgent matters that take up all of my time. I hope to make a start the next few weeks, i need to get this off my todo list. :-) |
@Lisa999 would you mind publishing your work on NVS somewhere? probably I can step in to finish the OO work, as I'm interested in NVS too ... |
This commit implements basic NVS support for the esp32. It follows the pattern of the esp32.Partition class and exposes an NVS object per NVS namespace. The initial support provided is only for signed 32-bit integers and binary blobs. It's easy (albeit a bit tedious) to add support for more types. See discussions in: #4436, #4707, #6780
This is superseded by the NVS supporte added in c10d431 |
qstr: Use `const` consistently to avoid a cast.
quick ref: