The MCUXpresso SDK provides a peripheral driver for the flash_dma driver module of MCUXpresso SDK devices.
Typical use case
Example use of FLASH_DMA API.
int main(void)
{
uint32_t i = 0;
BOARD_InitHardware();
FLASH_Init(DEMO_FLASH_BASE, &config);
PRINTF("FLASH_Init\r\n");
FLASH_CreateHandleDMA(DEMO_FLASH_BASE, &g_flashDmaHandle, FLASH_UserCallback, NULL, &g_flashWriteDMAHandle,
&g_flashreadDMAHandle);
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;
}
PRINTF("FLASH_StartWriteDMA addr = 0x%x size = %d \r\n", TEST_START_ADDR, TEST_MEM_SIZE);
FLASH_StartWriteDMA(DEMO_FLASH_BASE, &g_flashDmaHandle, &config, TEST_START_ADDR, (uint32_t *)data_buf,
TEST_MEM_SIZE / 4);
while (g_Transfer_Done != true)
{
}
g_Transfer_Done = false;
if (pass)
{
PRINTF("Passed!\r\n");
}
else
{
PRINTF("Failed!\r\n");
}
while (1)
;
}
|
| status_t | FLASH_CreateHandleDMA (flash_dma_handle_t *handle, flash_dma_callback_t callback, void *userData, dma_handle_t *writeHandle, dma_handle_t *readHandle) |
| | Initialize the FLASH DMA handle. More...
|
| |
| status_t | FLASH_StartReadDMA (flash_dma_handle_t *handle, flash_config_t *config, uint32_t addr, const uint32_t *pBuf, uint32_t lengthInWords) |
| | Perform a non-blocking FLASH read using DMA. More...
|
| |
| status_t | FLASH_StartWriteDMA (flash_dma_handle_t *handle, flash_config_t *config, uint32_t addr, const uint32_t *pBuf, uint32_t lengthInWords) |
| | Perform a non-blocking FLASH write using DMA. More...
|
| |
| void | FLASH_AbortDMA (flash_dma_handle_t *handle) |
| | Abort a FLASH transfer using DMA. More...
|
| |
| typedef void(* flash_dma_callback_t)(flash_dma_handle_t *handle, status_t status, void *userData) |
This function initializes the FLASH DMA handle.
- Parameters
-
| handle | FLASH handle pointer. |
| callback | User callback function called at the end of a transfer. |
| userData | User data for callback. |
| writeHandle | DMA handle pointer for FLASH write, the handle shall be static allocated by users. |
| readHandle | DMA handle pointer for FLASH read, the handle shall be static allocated by users. |
- Return values
-
| kStatus_InvalidArgument | Input argument is invalid. |
| status_t FLASH_StartReadDMA |
( |
flash_dma_handle_t * |
handle, |
|
|
flash_config_t * |
config, |
|
|
uint32_t |
addr, |
|
|
const uint32_t * |
pBuf, |
|
|
uint32_t |
lengthInWords |
|
) |
| |
- Note
- This interface returned immediately after transfer initiates
- Parameters
-
| handle | FLASH DMA handle pointer. |
| config | pointer to configuration structure |
| addr | Specifies the start address of the FLASH to be written, the address should be aligned with 4 bytes |
| pBuf | Pointer of the read data buffer |
| lengthInWords | The size of data to be written |
- Return values
-
| kStatus_Success | Successfully start a transfer. |
| kStatus_InvalidArgument | Input argument is invalid. |
| kStatus_FLASH_Busy | FLASH is not idle, is running another transfer. |
| status_t FLASH_StartWriteDMA |
( |
flash_dma_handle_t * |
handle, |
|
|
flash_config_t * |
config, |
|
|
uint32_t |
addr, |
|
|
const uint32_t * |
pBuf, |
|
|
uint32_t |
lengthInWords |
|
) |
| |
- Note
- This interface returned immediately after transfer initiates
- Parameters
-
| handle | FLASH DMA handle pointer. |
| config | pointer to configuration structure |
| addr | Specifies the start address of the FLASH to be written, the address should be aligned with 4 bytes |
| pBuf | Pointer of the write data buffer |
| lengthInWords | The size of data to be written |
- Return values
-
| kStatus_Success | Successfully start a transfer. |
| kStatus_InvalidArgument | Input argument is invalid. |
| kStatus_FLASH_Busy | FLASH is not idle, is running another transfer. |
| void FLASH_AbortDMA |
( |
flash_dma_handle_t * |
handle | ) |
|
- Parameters
-
| base | FLASH peripheral base address. |
| handle | FLASH DMA handle pointer. |