1.2.12 1.9.10 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 MHC 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
Name | Description |
---|---|
FCW_Initialize | Initializes given instance of the FCW peripheral |
FCW_Read | Reads length number of bytes from a given address in FLASH memory |
FCW_RowWrite | Writes one row of data to given FCW address |
FCW_SingleDoubleWordWrite | Writes Two Words into the Flash |
FCW_QuadDoubleWordWrite | Writes Eight Words into the Flash |
FCW_PageErase | Erases a Page in the FCW |
FCW_ErrorGet | Returns the error state of FCW controller |
FCW_IsBusy | Returns the current status of FCW controller |
FCW_CallbackRegister | Sets the pointer to the function (and it's context) to be called when the operation is complete |
FCW_ProgramFlashBankSelect | Selects program flash bank |
FCW_ProgramFlashBankGet | Returns selected program flash bank |
FCW_PFM_WriteProtectRegionSetup | Creates program flash region |
FCW_PFM_WriteProtectEnable | Enable write protection for program flash |
FCW_PFM_WriteProtectDisable | Disable write protection for program flash |
FCW_PFM_WriteProtectLock | Disable Writes to Program Flash Write Protect Lock register |
FCW_BootFlashWriteProtectEnable | Enable write protection for boot flash |
FCW_BootFlashWriteProtectDisable | Disable write protection for boot flash |
FCW_BootFlashWriteProtectLock | Disable Writes to boot Flash Write Protect register |
Data types and constants
Name | Type | Description |
---|---|---|
FCW_ERROR | Enum | Defines the FCW Error Type |
PROGRAM_FLASH_BANK | Enum | Defines program flash bank |
BOOT_FLASH_BANK | Enum | Defines boot flash bank |
FCW_BOOT_FLASH_WRITE_PROTECT | Enum | Defines boot flash write protect page |
PFM_WP_REGION | Enum | Defines PFM write protect region |
PFM_WP_REGION_SETUP | Struct | PFM write protect region Setup Structure |
FCW_CALLBACK | Typedef | Defines the data type and function signature for the FCW peripheral callback function |