1.29.15 1.30.10 1.31.10 1.33.10 1.37.10 1.39.10 1.40.13 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

The main Flash memory can not be read while it is being erased or written, the CPU is stalled during the entire operation.

  • All functions that modify the main Flash can be run from RAM memory to avoid CPU stall while main main Flash is being erased or written.

  • Some devices has the Flash region that support read-while-write feature, it is called Data Flash. The user could execute code from main Flash while the the Data Flash is being erased or written.

The FLASH memory is divided into a number of physical rows, each containing four identically sized flash pages. Pages may be read or written to individually, however pages must be erased before being reprogrammed and the smallest granularity available for erasure is one single row.

NVM APIs are implemented to be non-blocking, the API will return immediately unless stalled by Flash operation. The user application can either use polling or callback method to indicate the transfer status.

  • With polling, the application will need to continuously check if the flash operation is completed.

  • With callback, the registered callback function will be called once the flash operation is completed. This means the application do not have to poll continuously.

Here is an example code to erase a row and program a page of memory using polling method

// Define a constant array in Flash.
// It must be aligned to row boundary and size has to be in multiple of rows
const uint8_t nvm_user_start_address[NVMCTRL_FLASH_ROWSIZE] __attribute__((aligned(NVMCTRL_FLASH_ROWSIZE),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 row */
    NVMCTRL_RowErase((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_PageWrite Writes one page of data to given NVM address
NVMCTRL_RowErase Erases a Row in the NVM
NVMCTRL_ErrorGet Returns the error state 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_RWWEEPROM_Read Reads length number of bytes from a given address in Data FLASH memory
NVMCTRL_RWWEEPROM_PageWrite Writes one page of data to given RWWEEPROM address
NVMCTRL_RWWEEPROM_RowErase Erases a Row in the RWWEEPROM
NVMCTRL_CallbackRegister Sets the pointer to the function (and it's context) to be called when the operation is complete
NVMCTRL_CacheInvalidate Invalidates all cache lines
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_ROWSIZE Macro Defines the size (in bytes) of a NVMCTRL Row
NVMCTRL_RWWEEPROM_START_ADDRESS Macro Defines the start address of NVMCTRL RWWEEPROM
NVMCTRL_RWWEEPROM_SIZE Macro Defines the size (in bytes) of RWWEEPROM
NVMCTRL_RWWEEPROM_PAGESIZE Macro Defines the size (in bytes) of a NVMCTRL RWWEEPROM Page
NVMCTRL_RWWEEPROM_ROWSIZE Macro Defines the size (in bytes) of a NVMCTRL RWWEEPROM Row
NVMCTRL_ERROR Macros Defines the NVMCTRL Error Type constants
NVMCTRL_CALLBACK Typedef Defines the data type and function signature for the NVMCTRL peripheral callback function