The MCUXpresso SDK provides a peripheral driver for the flash driver module of MCUXpresso SDK devices.
Typical use case
Example use of FLASH API.
int main(void)
{
bool pass = true;
uint32_t i = 0;
uint8_t data_buf[TEST_MEM_SIZE];
BOARD_InitHardware();
FLASH_Init(DEMO_FLASH_BASE, &config);
PRINTF("FLASH_Init\r\n");
if (result)
{
PRINTF("FLASH_PageErase error result = %d \r\n", result);
while (1)
;
}
for (i = 0; i < TEST_MEM_SIZE; i++)
{
data_buf[i] = (uint8_t)i;
}
result =
FLASH_Program(DEMO_FLASH_BASE, &config, TEST_START_ADDR, (uint8_t *)&data_buf[0], TEST_MEM_SIZE - 1);
if (result)
{
PRINTF("FLASH_Program error result = %d \r\n", result);
while (1)
;
}
if (memcmp((void *)TEST_START_ADDR, (uint8_t *)&data_buf[0], TEST_MEM_SIZE - 1))
{
pass = false;
}
if (pass)
{
PRINTF("Passed!\r\n");
}
else
{
PRINTF("Failed!\r\n");
}
while (1)
;
}
|
#define | FLASH_TIME_BASE(clk) |
| Time base of FLASH timing, 2us: 64 cycles in 32 MHz/32 cycles in 16 MHz/16 cycles in 8 MHz.
|
|
#define | FLASH_ERASE_TIME_BASE 16000 |
| Time base of FLASH timing, 2ms: 16000 cycles in 8 MHz(internal fixed clock)
|
|
#define | FLASH_PROG_CYCLE 30 |
| Program times in normal write mode.
|
|
#define | FLASH_ADDR_TO_PAGE(addr) ((uint8_t)((addr) >> 11)) |
| FLASH address convert to page.
|
|
|
enum | flash_status_t {
kStatus_FLASH_Success = MAKE_STATUS(kStatusGroup_Generic, 0),
kStatus_FLASH_Fail = MAKE_STATUS(kStatusGroup_Generic, 1),
kStatus_FLASH_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),
kStatus_FLASH_AddressError = MAKE_STATUS(kStatusGroup_FLASH, 0),
kStatus_FLASH_EraseError = MAKE_STATUS(kStatusGroup_FLASH, 1),
kStatus_FLASH_WriteError = MAKE_STATUS(kStatusGroup_FLASH, 2),
kStatus_FLASH_ProtectionViolation,
kStatus_FLASH_AHBError = MAKE_STATUS(kStatusGroup_FLASH, 4),
kStatus_FLASH_Busy = MAKE_STATUS(kStatusGroup_FLASH, 5),
kStatus_FLASH_WriteDmaIdle = MAKE_STATUS(kStatusGroup_FLASH, 6),
kStatus_FLASH_ReadDmaIdle = MAKE_STATUS(kStatusGroup_FLASH, 7)
} |
|
enum | flash_block_t {
kFLASH_Block0 = 1U,
kFLASH_Block1 = 2U
} |
|
uint32_t flash_config_t::totalSize |
uint32_t flash_config_t::pageSize |
uint8_t flash_config_t::smartMaxEraseTime |
uint8_t flash_config_t::smartMaxWriteTime |
uint16_t flash_config_t::programCycle |
uint32_t flash_config_t::timeBase |
uint32_t flash_lock_bit_t::lockCtrl0 |
uint32_t flash_lock_bit_t::lockCtrl1 |
uint32_t flash_lock_bit_t::lockCtrl2 |
uint32_t flash_lock_bit_t::lockCtrl3 |
uint32_t flash_lock_bit_t::lockCtrl4 |
uint32_t flash_lock_bit_t::lockCtrl5 |
uint32_t flash_lock_bit_t::lockCtrl6 |
uint32_t flash_lock_bit_t::lockCtrl7 |
uint32_t flash_lock_bit_t::lockCtrl8 |
Enumerator |
---|
kStatus_FLASH_Success |
flash operation is successful
|
kStatus_FLASH_Fail |
flash operation is not successful
|
kStatus_FLASH_InvalidArgument |
Invalid argument.
|
kStatus_FLASH_AddressError |
Address is out of range.
|
kStatus_FLASH_EraseError |
The erase operation is error.
|
kStatus_FLASH_WriteError |
The erase operation is error.
|
kStatus_FLASH_ProtectionViolation |
The program/erase operation is requested to execute on protected areas.
|
kStatus_FLASH_AHBError |
The AHB operation is error.
|
kStatus_FLASH_Busy |
Flash is busy.
|
kStatus_FLASH_WriteDmaIdle |
Flash write finish.
|
kStatus_FLASH_ReadDmaIdle |
Flash read finish.
|
Enumerator |
---|
kFLASH_Block0 |
The block 0 of Flash.
|
kFLASH_Block1 |
The block 1 of Flash.
|
static uint32_t FLASH_GetStatusFlags |
( |
void |
| ) |
|
|
inlinestatic |
This function get all FLASH status flags.
- Returns
- FLASH status flags.
static void FLASH_ClearStatusFlags |
( |
uint32_t |
mask | ) |
|
|
inlinestatic |
This function clears FLASH status flags with a provided mask.
- Parameters
-
mask | The status flags to be cleared |
static void FLASH_EnableInterrupts |
( |
uint32_t |
mask | ) |
|
|
inlinestatic |
This function enables the FLASH interrupt.
- Parameters
-
static void FLASH_DisableInterrupts |
( |
uint32_t |
mask | ) |
|
|
inlinestatic |
This function disables the FLASH interrupt.
- Parameters
-
static uint32_t FLASH_GetBusyStatusFlags |
( |
void |
| ) |
|
|
inlinestatic |
This function get all FLASH busy status flags.
- Returns
- FLASH busy status flags.
This function initializes the UART configuration structure to a default value.
* config->
blockBase = FSL_FEATURE_FLASH_BASE_ADDR;
* config->
totalSize = FSL_FEATURE_FLASH_SIZE_BYTES;
* config->
pageSize = FSL_FEATURE_FLASH_PAGE_SIZE_BYTES;
*
- Parameters
-
config | pointer to flash config structure |
- Returns
- none
This function erases the appropriate number of flash pages based on the desired start address and length.
- Parameters
-
config | pointer to configuration structure |
start | Specifies the start address of the FLASH to be erased, the address should be aligned with 4 bytes |
lengthInBytes | The length, given in bytes (not words or long-words) to be erased. Must be word aligned. |
This function erases a page based on page_index.
- Parameters
-
config | pointer to configuration structure |
pageIdx | The page index to be erased |
- Returns
- status
This function erases a block based on block.
- Parameters
-
config | pointer to configuration structure |
block | Specifies the block to be erased |
- Returns
- status
This function programs the flash memory with the desired data for a given flash area as determined by the addr and n_word.
- Parameters
-
base | FLASH peripheral base address. |
config | pointer to configuration structure |
start | Specifies the start address of the FLASH to be written, the address should be aligned with 4 bytes |
src | Pointer of the write data buffer |
lengthInBytes | The size of data to be written |
- Returns
- status
This function get the flash page lock bit.
- Parameters
-
base | FLASH peripheral base address. |
config | pointer to configuration structure |
lockBit | Pointer of the lock bit configuration structure(0: lock; 1: unlock) |
- Returns
- status
This function set the flash page lock bit base based on lockBit.
- Parameters
-
base | FLASH peripheral base address. |
config | pointer to configuration structure |
lockBit | Pointer of the lock bit configuration structure(0: lock; 1: unlock) |
- Returns
- status