3.6.18 Quad Serial Peripheral Interface (QSPI)

The Quad SPI Interface (QSPI) is a synchronous serial data link that provides communication with external devices in Master mode. It is similar to SPI protocol except that it has additional data lines.

The QSPI can be used in normal SPI mode or in Serial Memory mode to connect to external Flash memories. The normal SPI has four communication lines: Chip Select, Clock, MOSI, and MISO. For QSPI, additional data lines are available. The command/data/address are sent through single, dual or quad IO based on the mode selected.

As data is sent over multiple lines, it helps in increasing bandwidth compared to a standard SPI transfer. With the support of the Quad SPI protocol, the QSPI allows the system to use high-performance serial Flash memories which are small and inexpensive, in place of larger and more expensive parallel Flash memories.

The QSPI allows the system to execute code directly from a serial Flash memory (XIP) without code shadowing to RAM. The serial Flash memory mapping is seen in the system as other memories such as SRAM, and FLASH memory.

Using The Library

The QSPI Peripheral Library operates in Serial Memory Mode or SPI Mode to interface with the QSPI based Serial Flash Memories operating in Single-bit SPI, Dual SPI, and Quad SPI.

The QSPI Peripheral library provides non-Blocking API's, which can be used to perform the following functionalities on the QSPI Slave device.

  • Send a command

    • qspi_command_xfer_t data type needs to filled to send a command to the slave device

  • Register read/write

    • qspi_register_xfer_t data type needs to be filled to read data from a register or to write data to a register.

  • Memory read/write

    • qspi_memory_xfer_t data type needs to be filled to read data from flash memory or to write data to the FLASH memory.

Here is an example code to read data from SST26 QSPI flash memory using QSPI peripheral

#define SST26_HIGH_SPEED_READ 0x0B

static qspi_memory_xfer_t qspi_memory_xfer;
static uint32_t buffer[256];
uint32_t address = 0x0

memset((void *)&qspi_memory_xfer, 0, sizeof(qspi_memory_xfer_t));

// Read memory location starting from address 0x0
qspi_memory_xfer.instruction = SST26_HIGH_SPEED_READ;

// Use QAUD SPI Lane
qspi_memory_xfer.width = QUAD_CMD;
qspi_memory_xfer.dummy_cycles = 6;

if (QSPI0_MemoryRead(&qspi_memory_xfer, buffer, sizeof(buffer), address) == false)
{
    // Handle Error
}

Library Interface

Quad Serial Peripheral Interface peripheral library provides the following interfaces:

Functions

QSPI Mode:

NameDescription
QSPIx_InitializeInitializes given instance of the QSPI peripheral
QSPIx_CommandWriteWrites command to QSPI slave device
QSPIx_RegisterReadReads particular register of QSPI slave device
QSPIx_RegisterWriteWrites to particular register of QSPI slave device
QSPIx_MemoryReadReads from the specified address of the serial flash device
QSPIx_MemoryWriteWrites to the specified address of the serial flash device

SPI Mode:

NameDescription
QSPIx_InitializeInitializes given instance of the QSPI peripheral
QSPIx_TransferSetupSetup QSPI operational parameters as desired by the client.
QSPIx_WriteReadWrite and Read data on QSPI peripheral.
QSPIx_WriteWrite data on QSPI peripheral.
QSPIx_ReadRead data on QSPI peripheral.
QSPIx_IsBusyReturns transfer status of QSPI peripheral.
QSPIx_CallbackRegisterAllows application to register callback with PLIB.

Data types and constants

NameTypeDescription
QSPI_ADDRESS_LENGTHEnumDefines the data type to specify address length
QSPI_LANE_WIDTHEnumDefines the data type to specify lane width
QSPI_OPTION_LENGTHEnumDefines the data type to specify option length
QSPI_CLOCK_PHASEEnumIdentifies QSPI Clock Phase Options
QSPI_CLOCK_POLARITYEnumIdentifies QSPI Clock Polarity Options
QSPI_DATA_BITSEnumIdentifies SPI bits per transfer
QSPI_TRANSFER_SETUPStructIdentifies the setup parameters which can be changed dynamically
qspi_command_xfer_tStructDefines the data type for the QSPI commands transfer
qspi_register_xfer_tStructDefines the data type for the QSPI register data transfer
qspi_memory_xfer_tStructDefines the data type for the QSPI memory transfer
QSPI_CALLBACKTypedefPointer to a Callback function. This is used in SPI mode only