Skip to content

atmel-samd: Introduce a nvm module for non-volatile byte-level memory access.#203

Merged
dhalbert merged 2 commits into
adafruit:masterfrom
tannewt:eeprom
Aug 25, 2017
Merged

atmel-samd: Introduce a nvm module for non-volatile byte-level memory access.#203
dhalbert merged 2 commits into
adafruit:masterfrom
tannewt:eeprom

Conversation

@tannewt
Copy link
Copy Markdown
Member

@tannewt tannewt commented Aug 24, 2017

This allows for persisting small configuration values even when the file system
is read-only from CircuitPython.

Fixes #160

… access.

This allows for persisting small configuration values even when the file system
is read-only from CircuitPython.

Fixes micropython#160
@tannewt tannewt added this to the 2.0 milestone Aug 24, 2017
@tannewt tannewt requested a review from dhalbert August 24, 2017 17:36
Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

I like the way this works! Very straightforward to use, and should be applicable across a bunch of architectures.

Comment thread atmel-samd/main.c Outdated
}
#endif
// Mark the last section as eeprom now.
fuses.eeprom_size = NVM_EEPROM_EMULATOR_SIZE_256;
Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert Aug 25, 2017

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a computation of the enum value so it is flexible.

Comment thread shared-bindings/nvm/ByteArray.c Outdated
//| :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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Typo: 'avialble` -> 'available'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Comment thread shared-bindings/nvm/ByteArray.c Outdated
//|
//| Return the length. This is used by (`len`)
//|
STATIC mp_obj_t nvm_bytearray___len__(mp_obj_t self_in) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed. Its unary_op internally :-/

@dhalbert
Copy link
Copy Markdown
Collaborator

When I tested this on a CPX, I saw CIRCUITPYTHON1 and the crystal-less usb calibration value in the first bytes of microcontroller.nvm. Do you think this was left over from a previous non-nvm firmware load, or is main.c overwriting nvm with the cal data? I'm not sure of the order of firmware, nvm and calibration areas in the flash.

* Add tests.
* Fix non-zero index.
* Fix len()
@tannewt
Copy link
Copy Markdown
Member Author

tannewt commented Aug 25, 2017

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.

@dhalbert dhalbert merged commit 266be30 into adafruit:master Aug 25, 2017
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.

2 participants