Jump to main content

##

# 3.46.12 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:

Name | Description
--- | ---
QSPIx_Initialize | Initializes given instance of the QSPI peripheral
QSPIx_CommandWrite | Writes command to QSPI slave device
QSPIx_RegisterRead | Reads particular register of QSPI slave device
QSPIx_RegisterWrite | Writes to particular register of QSPI slave device
QSPIx_MemoryRead | Reads from the specified address of the serial flash device
QSPIx_MemoryWrite | Writes to the specified address of the serial flash device

SPI Mode:

Name | Description
--- | ---
QSPIx_Initialize | Initializes given instance of the QSPI peripheral
QSPIx_TransferSetup | Setup QSPI operational parameters as desired by the client.
QSPIx_WriteRead | Write and Read data on QSPI peripheral.
QSPIx_Write | Write data on QSPI peripheral.
QSPIx_Read | Read data on QSPI peripheral.
QSPIx_IsBusy | Returns transfer status of QSPI peripheral.
QSPIx_CallbackRegister | Allows application to register callback with PLIB.

Data types and constants

Name | Type | Description
--- | --- | ---
QSPI_ADDRESS_LENGTH | Enum | Defines the data type to specify address length
QSPI_LANE_WIDTH | Enum | Defines the data type to specify lane width
QSPI_OPTION_LENGTH | Enum | Defines the data type to specify option length
QSPI_CLOCK_PHASE | Enum | Identifies QSPI Clock Phase Options
QSPI_CLOCK_POLARITY | Enum | Identifies QSPI Clock Polarity Options
QSPI_DATA_BITS | Enum | Identifies SPI bits per transfer
QSPI_TRANSFER_SETUP | Struct | Identifies the setup parameters which can be changed dynamically
qspi_command_xfer_t | Struct | Defines the data type for the QSPI commands transfer
qspi_register_xfer_t | Struct | Defines the data type for the QSPI register data transfer
qspi_memory_xfer_t | Struct | Defines the data type for the QSPI memory transfer
QSPI_CALLBACK | Typedef | Pointer to a Callback function. This is used in SPI mode only