The MCUXpresso SDK provides a driver for the Flash In Application Programming (FLASHIAP).
It provides a set of functions to call the on chip in application flash programming interface. User code executing from on chip flash or ram can call these function to erase and write the flash memory.
GFlash In Application Programming operation
FLASHIAP_PrepareSectorForWrite() prepares a sector for write or erase operation.
FLASHIAP_CopyRamToFlash() function programs the flash memory.
FLASHIAP_EraseSector() function erase a flash sector. A sector must be erased before write operation.
Typical use case
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/flashiap
|
typedef void(* | IAP_ENTRY_T )(uint32_t cmd[5], uint32_t stat[4]) |
| IAP_ENTRY API function type.
|
|
|
enum | _flashiap_status {
kStatus_FLASHIAP_Success = kStatus_Success,
kStatus_FLASHIAP_InvalidCommand = MAKE_STATUS(kStatusGroup_FLASHIAP, 1U),
kStatus_FLASHIAP_SrcAddrError,
kStatus_FLASHIAP_DstAddrError,
kStatus_FLASHIAP_SrcAddrNotMapped,
kStatus_FLASHIAP_DstAddrNotMapped,
kStatus_FLASHIAP_CountError,
kStatus_FLASHIAP_InvalidSector,
kStatus_FLASHIAP_SectorNotblank = MAKE_STATUS(kStatusGroup_FLASHIAP, 8U),
kStatus_FLASHIAP_NotPrepared,
kStatus_FLASHIAP_CompareError,
kStatus_FLASHIAP_Busy,
kStatus_FLASHIAP_ParamError,
kStatus_FLASHIAP_AddrError = MAKE_STATUS(kStatusGroup_FLASHIAP, 13U),
kStatus_FLASHIAP_AddrNotMapped,
kStatus_FLASHIAP_NoPower = MAKE_STATUS(kStatusGroup_FLASHIAP, 24U),
kStatus_FLASHIAP_NoClock
} |
| Flashiap status codes. More...
|
|
enum | _flashiap_commands {
kIapCmd_FLASHIAP_PrepareSectorforWrite = 50U,
kIapCmd_FLASHIAP_CopyRamToFlash = 51U,
kIapCmd_FLASHIAP_EraseSector = 52U,
kIapCmd_FLASHIAP_BlankCheckSector = 53U,
kIapCmd_FLASHIAP_ReadPartId = 54U,
kIapCmd_FLASHIAP_Read_BootromVersion = 55U,
kIapCmd_FLASHIAP_Compare = 56U,
kIapCmd_FLASHIAP_ReinvokeISP = 57U,
kIapCmd_FLASHIAP_ReadUid = 58U,
kIapCmd_FLASHIAP_ErasePage = 59U,
kIapCmd_FLASHIAP_ReadMisr = 70U,
kIapCmd_FLASHIAP_ReinvokeI2cSpiISP = 71U
} |
| Flashiap command codes. More...
|
|
|
static void | iap_entry (uint32_t *cmd_param, uint32_t *status_result) |
| IAP_ENTRY API function type. More...
|
|
status_t | FLASHIAP_PrepareSectorForWrite (uint32_t startSector, uint32_t endSector) |
| Prepare sector for write operation. More...
|
|
status_t | FLASHIAP_CopyRamToFlash (uint32_t dstAddr, uint32_t *srcAddr, uint32_t numOfBytes, uint32_t systemCoreClock) |
| Copy RAM to flash. More...
|
|
status_t | FLASHIAP_EraseSector (uint32_t startSector, uint32_t endSector, uint32_t systemCoreClock) |
| Erase sector. More...
|
|
status_t | FLASHIAP_ErasePage (uint32_t startPage, uint32_t endPage, uint32_t systemCoreClock) |
| This function erases page(s). More...
|
|
status_t | FLASHIAP_BlankCheckSector (uint32_t startSector, uint32_t endSector) |
| Blank check sector(s) More...
|
|
status_t | FLASHIAP_Compare (uint32_t dstAddr, uint32_t *srcAddr, uint32_t numOfBytes) |
| Compare memory contents of flash with ram. More...
|
|
Enumerator |
---|
kStatus_FLASHIAP_Success |
Api is executed successfully.
|
kStatus_FLASHIAP_InvalidCommand |
Invalid command.
|
kStatus_FLASHIAP_SrcAddrError |
Source address is not on word boundary.
|
kStatus_FLASHIAP_DstAddrError |
Destination address is not on a correct boundary.
|
kStatus_FLASHIAP_SrcAddrNotMapped |
Source address is not mapped in the memory map.
|
kStatus_FLASHIAP_DstAddrNotMapped |
Destination address is not mapped in the memory map.
|
kStatus_FLASHIAP_CountError |
Byte count is not multiple of 4 or is not a permitted value.
|
kStatus_FLASHIAP_InvalidSector |
Sector number is invalid or end sector number is greater than start sector number.
|
kStatus_FLASHIAP_SectorNotblank |
One or more sectors are not blank.
|
kStatus_FLASHIAP_NotPrepared |
Command to prepare sector for write operation was not executed.
|
kStatus_FLASHIAP_CompareError |
Destination and source memory contents do not match.
|
kStatus_FLASHIAP_Busy |
Flash programming hardware interface is busy.
|
kStatus_FLASHIAP_ParamError |
Insufficient number of parameters or invalid parameter.
|
kStatus_FLASHIAP_AddrError |
Address is not on word boundary.
|
kStatus_FLASHIAP_AddrNotMapped |
Address is not mapped in the memory map.
|
kStatus_FLASHIAP_NoPower |
Flash memory block is powered down.
|
kStatus_FLASHIAP_NoClock |
Flash memory block or controller is not clocked.
|
Enumerator |
---|
kIapCmd_FLASHIAP_PrepareSectorforWrite |
Prepare Sector for write.
|
kIapCmd_FLASHIAP_CopyRamToFlash |
Copy RAM to flash.
|
kIapCmd_FLASHIAP_EraseSector |
Erase Sector.
|
kIapCmd_FLASHIAP_BlankCheckSector |
Blank check sector.
|
kIapCmd_FLASHIAP_ReadPartId |
Read part id.
|
kIapCmd_FLASHIAP_Read_BootromVersion |
Read bootrom version.
|
kIapCmd_FLASHIAP_Compare |
Compare.
|
kIapCmd_FLASHIAP_ReinvokeISP |
Reinvoke ISP.
|
kIapCmd_FLASHIAP_ReadUid |
Read Uid isp.
|
kIapCmd_FLASHIAP_ErasePage |
Erase Page.
|
kIapCmd_FLASHIAP_ReadMisr |
Read Misr.
|
kIapCmd_FLASHIAP_ReinvokeI2cSpiISP |
Reinvoke I2C/SPI isp.
|
static void iap_entry |
( |
uint32_t * |
cmd_param, |
|
|
uint32_t * |
status_result |
|
) |
| |
|
inlinestatic |
Wrapper for rom iap call
- Parameters
-
cmd_param | IAP command and relevant parameter array. |
status_result | IAP status result array. |
- Return values
-
None. | Status/Result is returned via status_result array. |
status_t FLASHIAP_PrepareSectorForWrite |
( |
uint32_t |
startSector, |
|
|
uint32_t |
endSector |
|
) |
| |
This function prepares sector(s) for write/erase operation. This function must be called before calling the FLASHIAP_CopyRamToFlash() or FLASHIAP_EraseSector() or FLASHIAP_ErasePage() function. The end sector must be greater than or equal to start sector number.
- Parameters
-
startSector | Start sector number. |
endSector | End sector number. |
- Return values
-
status_t FLASHIAP_CopyRamToFlash |
( |
uint32_t |
dstAddr, |
|
|
uint32_t * |
srcAddr, |
|
|
uint32_t |
numOfBytes, |
|
|
uint32_t |
systemCoreClock |
|
) |
| |
This function programs the flash memory. Corresponding sectors must be prepared via FLASHIAP_PrepareSectorForWrite before calling calling this function. The addresses should be a 256 byte boundary and the number of bytes should be 256 | 512 | 1024 | 4096.
- Parameters
-
dstAddr | Destination flash address where data bytes are to be written. |
srcAddr | Source ram address from where data bytes are to be read. |
numOfBytes | Number of bytes to be written. |
systemCoreClock | SystemCoreClock in Hz. It is converted to KHz before calling the rom IAP function. |
- Return values
-
status_t FLASHIAP_EraseSector |
( |
uint32_t |
startSector, |
|
|
uint32_t |
endSector, |
|
|
uint32_t |
systemCoreClock |
|
) |
| |
This function erases sector(s). The end sector must be greater than or equal to start sector number. FLASHIAP_PrepareSectorForWrite must be called before calling this function.
- Parameters
-
startSector | Start sector number. |
endSector | End sector number. |
systemCoreClock | SystemCoreClock in Hz. It is converted to KHz before calling the rom IAP function. |
- Return values
-
status_t FLASHIAP_ErasePage |
( |
uint32_t |
startPage, |
|
|
uint32_t |
endPage, |
|
|
uint32_t |
systemCoreClock |
|
) |
| |
The end page must be greater than or equal to start page number. Corresponding sectors must be prepared via FLASHIAP_PrepareSectorForWrite before calling calling this function.
- Parameters
-
startPage | Start page number |
endPage | End page number |
systemCoreClock | SystemCoreClock in Hz. It is converted to KHz before calling the rom IAP function. |
- Return values
-
status_t FLASHIAP_BlankCheckSector |
( |
uint32_t |
startSector, |
|
|
uint32_t |
endSector |
|
) |
| |
Blank check single or multiples sectors of flash memory. The end sector must be greater than or equal to start sector number. It can be used to verify the sector eraseure after FLASHIAP_EraseSector call.
- Parameters
-
startSector | : Start sector number. Must be greater than or equal to start sector number |
endSector | : End sector number |
- Return values
-
status_t FLASHIAP_Compare |
( |
uint32_t |
dstAddr, |
|
|
uint32_t * |
srcAddr, |
|
|
uint32_t |
numOfBytes |
|
) |
| |
This function compares the contents of flash and ram. It can be used to verify the flash memory contents after FLASHIAP_CopyRamToFlash call.
- Parameters
-
dstAddr | Destination flash address. |
srcAddr | Source ram address. |
numOfBytes | Number of bytes to be compared. |
- Return values
-