MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
FLASH_DMA: flash_dma driver

Overview

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)
{
status_t result = 0;
uint32_t i = 0;
/* Board pin, clock, debug console init */
BOARD_InitHardware();
/* Configure Flash */
/*Flash module init*/
FLASH_Init(DEMO_FLASH_BASE, &config);
PRINTF("FLASH_Init\r\n");
/* Configure DMA. */
DMA_Init(DMA0);
DMA_EnableChannel(DMA0, FLASH_WRITE_DMA_CHANNEL);
DMA_EnableChannel(DMA0, FLASH_READ_DMA_CHANNEL);
DMA_CreateHandle(&g_flashWriteDMAHandle, DMA0, FLASH_WRITE_DMA_CHANNEL);
DMA_CreateHandle(&g_flashreadDMAHandle, DMA0, FLASH_READ_DMA_CHANNEL);
FLASH_CreateHandleDMA(DEMO_FLASH_BASE, &g_flashDmaHandle, FLASH_UserCallback, NULL, &g_flashWriteDMAHandle,
&g_flashreadDMAHandle);
/* erase test page*/
result = FLASH_PageErase(DEMO_FLASH_BASE, &config, FLASH_ADDR_TO_PAGE(TEST_START_ADDR));
if (result)
{
PRINTF("FLASH_PageErase error result = %d \r\n", result);
while (1)
;
}
/*set test data */
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;
/*show result*/
if (pass)
{
PRINTF("Passed!\r\n");
}
else
{
PRINTF("Failed!\r\n");
}
while (1)
;
}

Files

file  fsl_flash_dma.h
 

Data Structures

struct  flash_dma_handle_t
 FLASH DMA handle, users should not touch the content of the handle. More...
 

Typedefs

typedef void(* flash_dma_callback_t )(flash_dma_handle_t *handle, status_t status, void *userData)
 FLASH DMA callback called at the end of transfer. More...
 

DMA Transactional

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...
 

Data Structure Documentation

struct _flash_dma_handle

Data Fields

bool writeInProgress
 write finished
 
bool readInProgress
 read finished
 
dma_handle_twriteHandle
 DMA handler for FLASH write.
 
dma_handle_treadHandle
 DMA handler for FLASH read.
 
flash_dma_callback_t callback
 Callback for FLASH DMA transfer.
 
void * userData
 User Data for FLASH DMA callback.
 
uint32_t state
 Internal state of FLASH DMA transfer.
 

Typedef Documentation

typedef void(* flash_dma_callback_t)(flash_dma_handle_t *handle, status_t status, void *userData)

Function Documentation

status_t FLASH_CreateHandleDMA ( flash_dma_handle_t *  handle,
flash_dma_callback_t  callback,
void *  userData,
dma_handle_t writeHandle,
dma_handle_t readHandle 
)

This function initializes the FLASH DMA handle.

Parameters
handleFLASH handle pointer.
callbackUser callback function called at the end of a transfer.
userDataUser data for callback.
writeHandleDMA handle pointer for FLASH write, the handle shall be static allocated by users.
readHandleDMA handle pointer for FLASH read, the handle shall be static allocated by users.
Return values
kStatus_InvalidArgumentInput 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
handleFLASH DMA handle pointer.
configpointer to configuration structure
addrSpecifies the start address of the FLASH to be written, the address should be aligned with 4 bytes
pBufPointer of the read data buffer
lengthInWordsThe size of data to be written
Return values
kStatus_SuccessSuccessfully start a transfer.
kStatus_InvalidArgumentInput argument is invalid.
kStatus_FLASH_BusyFLASH 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
handleFLASH DMA handle pointer.
configpointer to configuration structure
addrSpecifies the start address of the FLASH to be written, the address should be aligned with 4 bytes
pBufPointer of the write data buffer
lengthInWordsThe size of data to be written
Return values
kStatus_SuccessSuccessfully start a transfer.
kStatus_InvalidArgumentInput argument is invalid.
kStatus_FLASH_BusyFLASH is not idle, is running another transfer.
void FLASH_AbortDMA ( flash_dma_handle_t *  handle)
Parameters
baseFLASH peripheral base address.
handleFLASH DMA handle pointer.