atmel-samd: Introduce a nvm module for non-volatile byte-level memory access.#203
Conversation
… access. This allows for persisting small configuration values even when the file system is read-only from CircuitPython. Fixes micropython#160
| } | ||
| #endif | ||
| // Mark the last section as eeprom now. | ||
| fuses.eeprom_size = NVM_EEPROM_EMULATOR_SIZE_256; |
There was a problem hiding this comment.
If CIRCUITPY_INTERNAL_NVM_SIZE is other than 256, fuses.eeprom_size will be the wrong value. You could put an #if check in here that errors out if it's not ==256. Or, to be more general, in the mpconfigboard.h files you could #define a constant that's the right fuse enum value.
There was a problem hiding this comment.
Added a computation of the enum value so it is flexible.
| //| :class:`ByteArray` -- Presents a stretch of non-volatile memory as a bytearray. | ||
| //| ================================================================================ | ||
| //| | ||
| //| Non-volatile memory is avialble as a byte array that persists over reloads |
There was a problem hiding this comment.
Typo: 'avialble` -> 'available'
| //| | ||
| //| Return the length. This is used by (`len`) | ||
| //| | ||
| STATIC mp_obj_t nvm_bytearray___len__(mp_obj_t self_in) { |
There was a problem hiding this comment.
This should work, but __len__() doesn't seem to work right in Circuit/MicroPython:
>>> len(microcontroller.nvm)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'ByteArray' has no len()
>>> len(bytearray(7))
7
>>> microcontroller.nvm.__len__()
256
>>> bytearray(7).__len__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'bytearray' object has no attribute '__len__'
>>> [1,2].__len__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute '__len__'
It doesn't work in the unix build either, so it's not some idiosyncrasy of atmel-samd
There was a problem hiding this comment.
Fixed. Its unary_op internally :-/
|
When I tested this on a CPX, I saw |
* Add tests. * Fix non-zero index. * Fix len()
|
Yup, I moved the location of the config data to before the eeprom section. It needs to be at the end of memory for the nvm controller to understand where it is. |
This allows for persisting small configuration values even when the file system
is read-only from CircuitPython.
Fixes #160