1.32.16 Non-Volatile Memory Controller (NVMCTRL)
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.
Using The Library
NVMCTRL Peripheral library provides non-Blocking API's and they can be used to perform below functionalities on the NVMCTRL peripheral.
-
Initialize the NVMCTRL
-
Register a callback
-
Perform NVM write and erase operations
-
Manage region locks
-
Manage SmartEEPROM
-
Check error and status of NVM
The Flash memory main address space on this device is arranged as two memory banks. It is possible to execute code from one memory bank while a write or erase operation is progressing on the other memory bank. The entire flash memory is divided into 32 regions.
Each region has a corresponding lock bit which can be programmed (with Lock Region command) to temporarily prevent write and erase operations. Temporarily here means until the region is unlocked with an unlock command. These lock bits can be erased (with an Unlock Region command)) to temporarily unlock a region. When the device is reset, region lock values are loaded with the default value stored in the NVM User Page.
The main address space is divided into blocks . Each of the block contains several flash pages. Commands used for the main address space and NVM User Page are different.
There are multiple commands to perform erase and write operations.
Memory | WP | WQW | EP | EB |
---|---|---|---|---|
Main Address Space | X | X | X | |
User Page Address Space | X | X |
-
EB: Erase Block
-
EP: Erase Page
-
WP: Write Page
-
WQW: Write Quad Word
SmartEEPROM is the feature which perform EEPROM emulation on the device flash. There are fuse bits in the NVM User Page to configure SmartEEPROM total size and page size. Refer the datasheet and code examples for more details on the SmartEEPROM.
Here is an example code to erase a block and program a page of memory using polling method
// Define a constant array in Flash. // It must be aligned to block boundary and size has to be in multiple of rows const uint8_t nvm_user_start_address[NVMCTRL_FLASH_BLOCKSIZE] __attribute__((aligned(NVMCTRL_FLASH_BLOCKSIZE),keep,externally_visible,space(prog)))= {0}; void populate_buffer(uint8_t* data) { int i = 0; for (i = 0; i < (NVMCTRL_FLASH_PAGESIZE); i++) { *(data + i) = i; } } int main (void) { uint8_t pageBuffer[NVMCTRL_FLASH_PAGESIZE] = {0}; /*Populate pageBuffer to programmed*/ populate_buffer(pageBuffer); while(NVMCTRL_IsBusy()); /* Erase the block */ NVMCTRL_BlockErase((uint32_t)nvm_user_start_address); /* Wait for row erase to complete */ while(NVMCTRL_IsBusy()); /* Program a page of data */ NVMCTRL_PageWrite((uint32_t *)pageBuffer, (uint32_t)nvm_user_start_address); /* Wait for page program to compete */ while(NVMCTRL_IsBusy()); }
Library Interface
Non-Volatile Memory Controller peripheral library provides the following interfaces:
Functions
Name | Description |
---|---|
NVMCTRL_Initialize | Initializes given instance of the NVMCTRL peripheral |
NVMCTRL_Read | Reads length number of bytes from a given address in FLASH memory |
NVMCTRL_SetWriteMode | Sets the write mode for Flash |
NVMCTRL_PageWrite | Writes one page of data to given NVM address |
NVMCTRL_BlockErase | Erases a Block in the NVM |
NVMCTRL_ErrorGet | Returns error conditions of NVM controller |
NVMCTRL_StatusGet | Returns status conditions of NVM controller |
NVMCTRL_IsBusy | Returns the current status of NVM controller |
NVMCTRL_RegionLock | Locks a NVMCTRL region |
NVMCTRL_RegionUnlock | Unlocks a NVM region |
NVMCTRL_RegionLockStatusGet | Returns the value of RUNLOCK register |
NVMCTRL_BankSwap | Swaps NVM Banks |
NVMCTRL_MainCallbackRegister | Sets the pointer to the function (and it's context) to be called when an operation on the Flash is complete, provided the corresponding interrupt is enabled |
NVMCTRL_SmartEEPROM_IsBusy | Checks whether SmartEEPROM is ready to perform next command |
NVMCTRL_SmartEepromStatusGet | Returns status conditions of SmartEEPROM |
NVMCTRL_SmartEEPROM_IsActiveSectorFull | Check whether active sector used by the SmartEEPROM is full |
NVMCTRL_SmartEepromSectorReallocate | Performs sector reallocation for the SmartEEPROM |
NVMCTRL_SmartEepromFlushPageBuffer | Flush SmartEEPROM data when in buffered mode |
NVMCTRL_SmartEEPROMCallbackRegister | Sets the pointer to the function (and it's context) to be called when an operation on the SmartEEPROM is complete, provided the corresponding interrupt is enabled |
NVMCTRL_EnableMainFlashInterruptSource | Enables a given interrupt source for the Flash |
NVMCTRL_DisableMainFlashInterruptSource | Disables a given interrupt source for the Flash |
NVMCTRL_EnableSmartEepromInterruptSource | Enables a given interrupt source for the SmartEEPROM |
NVMCTRL_DisableSmartEepromInterruptSource | Disables a given interrupt source for the SmartEEPROM |
NVMCTRL_PageBufferWrite | Writes data to the internal buffer of NVM known as the page buffer |
NVMCTRL_PageBufferCommit | Commits the data present in NVM internal page buffer to flash memory |
Data types and constants
Name | Type | Description |
---|---|---|
NVMCTRL_FLASH_START_ADDRESS | Macro | Defines the start address of NVMCTRL Flash |
NVMCTRL_FLASH_SIZE | Macro | Defines the size (in bytes) of Flash |
NVMCTRL_FLASH_PAGESIZE | Macro | Defines the size (in bytes) of a NVMCTRL Page |
NVMCTRL_FLASH_BLOCKSIZE | Macro | Defines the size (in bytes) of a NVMCTRL Block |
NVMCTRL_WRITEMODE | Enum | Defines the NVMCTRL Write Modes |
NVMCTRL_INTERRUPT0_SOURCE | Enum | Defines the Interrupt sources for the main flash |
NVMCTRL_INTERRUPT1_SOURCE | Enum | Defines the Interrupt sources for the SmartEEPROM |
NVMCTRL_CALLBACK | Typedef | Defines the data type and function signature for the NVMCTRL peripheral callback function |