Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

This section describes the programming interface of the QSPI peripheral driver.

The following is a basic step-by-step overview of how to initialize QSPI and use QSPI for transfers. For API specific examples, see the examples below. The following example uses the interrupt-driven APIs and a blocking transfer to illustrate a high-level step-by-step usage.

//Init QSPI module. User should transfer a state memory for QSPI internal use
QSPI_DRV_Init(instance, &state);
//Get QSPI default settings and configure the QSPI
qspi_config_t config;
//Get default QSPI configure parameters.
QSPI_DRV_GetDefaultQspiConfig(&config);
//Configure QSPI buffer size according to flash page size connected with QSPI
config.AHBbufferSize[3] = FLASH_PAGE_SIZE;
//Write QSPI configure param into QSPI registers.
QSPI_DRV_ConfigQspi(instance, &config);
//According to serial flash feature to configure flash settings
qspi_flash_config_t flash_config;
...
QSPI_DRV_ConfigFlash(instance, &flash_config);
//Execute serial flash command in cmdIdx of LUT.
QSPI_DRV_ExecuteFlashCommand(instance, cmdIdx);
//If it is program command, provide data using blocking way.
QSPI_DRV_WriteDataBlocking(instance,src_addr,size);
...
...
//Deinitialize QSPI module.
QSPI_DRV_Deinit(instance);

QSPI Run-time state structures

The QSPI driver uses a run-time state structure to track the ongoing data transfers. The state structure for the driver is called qspi_state_t. This structure holds data that the QSPI peripheral driver uses to communicate between the transfer function and the interrupt handler and other driver functions. The interrupt handler in the driver also uses this information to keep track of its progress. The user is only required to pass the memory for the run-time state structure. The QSPI driver populates the members.

QSPI Configure structures

The QSPI driver uses instances of the qspi_config_t structure to represent the QSPI bus and buffer configuration required to communicate to an external flash that is connected to QSPI.

The configuration structure consists of the following settings: SCLK (baud rate in Hz), clock source, watermark settings, and AHB buffer settings for read data via AHB bus.

QSPI Flash Configure structures

The QSPI driver uses instances of the qspi_flash_config_t structure to represent the flash features connected to the QSPI module.

The configuration structure consists of the following settings: flash size (supports maximum 2 flash), lookup table for flash commands, flash timing settings, flash endianess, and specific flash feature settings.

QSPI Initialization

To initialize the QSPI driver, call the QSPI_DRV_Init() function and pass the instance number of the QSPI peripheral. For example, to use the QSPI0 module, pass a value 0 to the initialization function. In addition, the user also passes in the pointer to the run-time state structure used by the driver to keep track of data transfers.

QSPI Transfers

The driver supports three different methods to transfer data: polling, interrupt, and DMA. The polling transfer is a blocking function and others are both non-blocking.

When using DMA to transfer data, ensure that the data is consistent when there is cache for memory. This means, when reading/ writing the data from/to memory, the application should ensure that data from or to the memory device is not cached.

Example for non-blocking function APIs and associated functions (interrupt and DMA-driven):

//Write data via eDMA, it is non-blocking
QSPI_DRV_WriteDataEdma(instance, src_addr,size);
....
//Wait until all data is written into TXFIFO
while(QSPI_DRV_GetTxStatus(instance) == kStatus_QSPI_DeviceBusy)
{}

QSPI De-initialization

To deinitialize and shut down the QSPI module, call the function QSPI_DRV_Deinit().