SAM D21 Non-Volatile Memory Controller (NVMCTRL) Overview
Module Overview
The Non-Volatile Memory (NVM) module provides an interface to the device's Non-Volatile Memory controller, so that memory pages can be written, read, erased, and reconfigured in a standardized manner.
Driver Feature Macro Definition
Driver feature macro | Supported devices |
---|---|
FEATURE_NVM_RWWEE | SAM L21/L22, SAM D21-64K, SAM DA1, SAM C20/C21 |
FEATURE_BOD12 | SAM L21 |
The specific features are only available in the driver when the selected device supports those features.
Memory Regions
The NVM memory space of the SAM devices is divided into two sections: The Main Array section, and an Auxiliary space section. The Main Array space can be configured to have an (emulated) EEPROM and/or bootloader section. The memory layout with the EEPROM and bootloader partitions is shown in the figure.
The Main Array is divided into rows and pages, where each row contains four pages. The size of each page may vary from 8-1024 bytes dependent of the device. Device specific parameters such as the page size and total number of pages in the NVM memory space are available via the nvm_get_parameters() function.
An NVM page number and address can be computed via the following equations:
(1)
PageNum = (RowNumx4) + PagePosInRow
(2)
PageAddr = PageNum ∗ PageSize
The figure below shows an example of the memory page and address values associated with logical row 7 of the NVM memory space.
Region Lock Bits
As mentioned in Memory Regions, the main block of the NVM memory is divided into several individually addressable pages. These pages are grouped into 16 equal sized regions, where each region can be locked separately issuing an NVM_COMMAND_LOCK_REGION command or by writing the LOCK bits in the User Row. Rows reserved for the EEPROM section are not affected by the lock bits or commands.
Read/Write
Reading from the NVM memory can be performed using direct addressing into the NVM memory space, or by calling the nvm_read_buffer() function.
Writing to the NVM memory must be performed by the nvm_write_buffer() function - additionally, a manual page program command must be issued if the NVM controller is configured in manual page writing mode.
Before a page can be updated, the associated NVM memory row must be erased first via the nvm_erase_row() function. Writing to a non-erased page will result in corrupt data being stored in the NVM memory space.