2.44 Flash Write Control (FCW)

The FCW module provides interface to the device's Flash controller, so that memory pages can be written, read, erased 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 Flash is being erased or written.

FCW APIs are implemented to be non-blocking, the API will return immediately if not stalled by Flash operation. The user application can either poll the status or get callback once the flash operation is completed.

  • 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. The interrupt must be enabled in MCC for callback method

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

#define APP_FLASH_ADDRESS  (FCW_FLASH_START_ADDRESS + (FCW_FLASH_SIZE / 2))

uint8_t CACHE_ALIGN rowBuffer[FCW_FLASH_ROWSIZE] = {0};

void populate_buffer(uint8_t* data)
{
    int i = 0;

    for (i = 0; i < (FCW_FLASH_ROWSIZE); i++)
    {
        *(data + i) = i;
    }
}

int main (void)
{
    /*Populate rowBuffer to programmed*/
    populate_buffer(rowBuffer);

    while(FCW_IsBusy());

    /* Erase the page */
    FCW_PageErase(APP_FLASH_ADDRESS);

    /* Wait for page erase  to complete */
    while(FCW_IsBusy());

    /* Program a row of data */
    FCW_RowWrite((uint32_t *)rowBuffer, APP_FLASH_ADDRESS);

    /* Wait for row program to compete */
    while(FCW_IsBusy());
}

Library Interface

Flash Write Control (FCW) peripheral library provides the following interfaces:

Functions

NameDescription
FCW_InitializeInitializes given instance of the FCW peripheral
FCW_ReadReads length number of bytes from a given address in FLASH memory
FCW_RowWriteWrites one row of data to given FCW address
FCW_SingleDoubleWordWriteWrites Two Words into the Flash
FCW_QuadDoubleWordWriteWrites Eight Words into the Flash
FCW_PageEraseErases a Page in the FCW
FCW_ErrorGetReturns the error state of FCW controller
FCW_IsBusyReturns the current status of FCW controller
FCW_CallbackRegisterSets the pointer to the function (and it's context) to be called when the operation is complete
FCW_ProgramFlashBankSelectSelects program flash bank
FCW_ProgramFlashBankGetReturns selected program flash bank
FCW_PFM_WriteProtectRegionSetupCreates program flash region
FCW_PFM_WriteProtectEnableEnable write protection for program flash
FCW_PFM_WriteProtectDisableDisable write protection for program flash
FCW_PFM_WriteProtectLockDisable Writes to Program Flash Write Protect Lock register
FCW_BootFlashWriteProtectEnableEnable write protection for boot flash
FCW_BootFlashWriteProtectDisableDisable write protection for boot flash
FCW_BootFlashWriteProtectLockDisable Writes to boot Flash Write Protect register

Data types and constants

NameTypeDescription
FCW_ERROREnumDefines the FCW Error Type
PROGRAM_FLASH_BANKEnumDefines program flash bank
BOOT_FLASH_BANKEnumDefines boot flash bank
FCW_BOOT_FLASH_WRITE_PROTECTEnumDefines boot flash write protect page
PFM_WP_REGIONEnumDefines PFM write protect region
PFM_WP_REGION_SETUPStructPFM write protect region Setup Structure
FCW_CALLBACKTypedefDefines the data type and function signature for the FCW peripheral callback function
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.