3.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.

MemoryWPWQWEPEB
Main Address SpaceXXX
User Page Address SpaceXX
  • 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

NameDescription
NVMCTRL_InitializeInitializes given instance of the NVMCTRL peripheral
NVMCTRL_ReadReads length number of bytes from a given address in FLASH memory
NVMCTRL_SetWriteModeSets the write mode for Flash
NVMCTRL_PageWriteWrites one page of data to given NVM address
NVMCTRL_BlockEraseErases a Block in the NVM
NVMCTRL_ErrorGetReturns error conditions of NVM controller
NVMCTRL_StatusGetReturns status conditions of NVM controller
NVMCTRL_IsBusyReturns the current status of NVM controller
NVMCTRL_RegionLockLocks a NVMCTRL region
NVMCTRL_RegionUnlockUnlocks a NVM region
NVMCTRL_RegionLockStatusGetReturns the value of RUNLOCK register
NVMCTRL_BankSwapSwaps NVM Banks
NVMCTRL_MainCallbackRegisterSets 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_IsBusyChecks whether SmartEEPROM is ready to perform next command
NVMCTRL_SmartEepromStatusGetReturns status conditions of SmartEEPROM
NVMCTRL_SmartEEPROM_IsActiveSectorFullCheck whether active sector used by the SmartEEPROM is full
NVMCTRL_SmartEepromSectorReallocatePerforms sector reallocation for the SmartEEPROM
NVMCTRL_SmartEepromFlushPageBufferFlush SmartEEPROM data when in buffered mode
NVMCTRL_SmartEEPROMCallbackRegisterSets 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_EnableMainFlashInterruptSourceEnables a given interrupt source for the Flash
NVMCTRL_DisableMainFlashInterruptSourceDisables a given interrupt source for the Flash
NVMCTRL_EnableSmartEepromInterruptSourceEnables a given interrupt source for the SmartEEPROM
NVMCTRL_DisableSmartEepromInterruptSourceDisables a given interrupt source for the SmartEEPROM
NVMCTRL_PageBufferWriteWrites data to the internal buffer of NVM known as the page buffer
NVMCTRL_PageBufferCommitCommits the data present in NVM internal page buffer to flash memory

Data types and constants

NameTypeDescription
NVMCTRL_FLASH_START_ADDRESSMacroDefines the start address of NVMCTRL Flash
NVMCTRL_FLASH_SIZEMacroDefines the size (in bytes) of Flash
NVMCTRL_FLASH_PAGESIZEMacroDefines the size (in bytes) of a NVMCTRL Page
NVMCTRL_FLASH_BLOCKSIZEMacroDefines the size (in bytes) of a NVMCTRL Block
NVMCTRL_WRITEMODEEnumDefines the NVMCTRL Write Modes
NVMCTRL_INTERRUPT0_SOURCEEnumDefines the Interrupt sources for the main flash
NVMCTRL_INTERRUPT1_SOURCEEnumDefines the Interrupt sources for the SmartEEPROM
NVMCTRL_CALLBACKTypedefDefines the data type and function signature for the NVMCTRL peripheral callback function