PSoC 6 Hardware Abstraction Layer (HAL)
QSPI (Quad Serial Peripheral Interface)

General Description

High level interface for interacting with the Cypress Quad-SPI interface.

The QSPI block supports sending commands to and receiving commands from an another device (often an external memory) via single, dual, quad, or octal SPI.

Data Structures

struct  cyhal_qspi_command_t
 QSPI command settings. More...
 
struct  cyhal_qspi_command_t.instruction
 
struct  cyhal_qspi_command_t.address
 
struct  cyhal_qspi_command_t.mode_bits
 
struct  cyhal_qspi_command_t.data
 

Macros

#define CYHAL_QSPI_RSLT_ERR_BUS_WIDTH   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_QSPI, 0))
 
#define CYHAL_QSPI_RSLT_ERR_PIN   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_QSPI, 1))
 
#define CYHAL_QSPI_RSLT_ERR_DATA_SEL   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_QSPI, 2))
 
#define CYHAL_QSPI_RSLT_ERR_INSTANCE   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_QSPI, 3))
 

Typedefs

typedef void(* cyhal_qspi_event_callback_t) (void *callback_arg, cyhal_qspi_event_t event)
 

Enumerations

enum  cyhal_qspi_bus_width_t { CYHAL_QSPI_CFG_BUS_SINGLE = 1, CYHAL_QSPI_CFG_BUS_DUAL = 2, CYHAL_QSPI_CFG_BUS_QUAD = 4, CYHAL_QSPI_CFG_BUS_OCTAL = 8 }
 
enum  cyhal_qspi_size_t { CYHAL_QSPI_CFG_SIZE_8 = 8, CYHAL_QSPI_CFG_SIZE_16 = 16, CYHAL_QSPI_CFG_SIZE_24 = 24, CYHAL_QSPI_CFG_SIZE_32 = 32 }
 
enum  cyhal_qspi_event_t { CYHAL_QSPI_EVENT_NONE = 0, CYHAL_QSPI_IRQ_TRANSMIT_DONE = 1 << 0, CYHAL_QSPI_IRQ_RECEIVE_DONE = 1 << 1 }
 

Functions

cy_rslt_t cyhal_qspi_init (cyhal_qspi_t *obj, cyhal_gpio_t io0, cyhal_gpio_t io1, cyhal_gpio_t io2, cyhal_gpio_t io3, cyhal_gpio_t io4, cyhal_gpio_t io5, cyhal_gpio_t io6, cyhal_gpio_t io7, cyhal_gpio_t sclk, cyhal_gpio_t ssel, uint32_t hz, uint8_t mode)
 
void cyhal_qspi_free (cyhal_qspi_t *obj)
 
cy_rslt_t cyhal_qspi_set_frequency (cyhal_qspi_t *obj, uint32_t hz)
 
cy_rslt_t cyhal_qspi_read (cyhal_qspi_t *obj, const cyhal_qspi_command_t *command, void *data, size_t *length)
 
cy_rslt_t cyhal_qspi_read_async (cyhal_qspi_t *obj, const cyhal_qspi_command_t *command, void *data, size_t *length)
 
cy_rslt_t cyhal_qspi_write (cyhal_qspi_t *obj, const cyhal_qspi_command_t *command, const void *data, size_t *length)
 
cy_rslt_t cyhal_qspi_write_async (cyhal_qspi_t *obj, const cyhal_qspi_command_t *command, const void *data, size_t *length)
 
cy_rslt_t cyhal_qspi_transfer (cyhal_qspi_t *obj, const cyhal_qspi_command_t *command, const void *tx_data, size_t tx_size, void *rx_data, size_t rx_size)
 
void cyhal_qspi_register_callback (cyhal_qspi_t *obj, cyhal_qspi_event_callback_t callback, void *callback_arg)
 
void cyhal_qspi_enable_event (cyhal_qspi_t *obj, cyhal_qspi_event_t event, uint8_t intrPriority, bool enable)
 

Data Structure Documentation

◆ cyhal_qspi_command_t

struct cyhal_qspi_command_t
Data Fields
struct cyhal_qspi_command_t instruction
struct cyhal_qspi_command_t address
struct cyhal_qspi_command_t mode_bits
uint8_t dummy_count

Dummy cycles count >

struct cyhal_qspi_command_t data

◆ cyhal_qspi_command_t.instruction

struct cyhal_qspi_command_t.instruction
Data Fields
cyhal_qspi_bus_width_t bus_width

Bus width for the instruction >

uint8_t value

Instruction value >

bool disabled

Instruction phase skipped if disabled is set to true >

◆ cyhal_qspi_command_t.address

struct cyhal_qspi_command_t.address
Data Fields
cyhal_qspi_bus_width_t bus_width

Bus width for the address >

cyhal_qspi_size_t size

Address size >

uint32_t value

Address value >

bool disabled

Address phase skipped if disabled is set to true >

◆ cyhal_qspi_command_t.mode_bits

struct cyhal_qspi_command_t.mode_bits
Data Fields
cyhal_qspi_bus_width_t bus_width

Bus width for mode bits >

cyhal_qspi_size_t size

Mode bits size >

uint32_t value

Mode bits value >

bool disabled

Mode bits phase skipped if disabled is set to true >

◆ cyhal_qspi_command_t.data

struct cyhal_qspi_command_t.data
Data Fields
cyhal_qspi_bus_width_t bus_width

Bus width for data >

Macro Definition Documentation

◆ CYHAL_QSPI_RSLT_ERR_BUS_WIDTH

#define CYHAL_QSPI_RSLT_ERR_BUS_WIDTH   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_QSPI, 0))

Bus width Error. >

◆ CYHAL_QSPI_RSLT_ERR_PIN

#define CYHAL_QSPI_RSLT_ERR_PIN   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_QSPI, 1))

Pin related Error. >

◆ CYHAL_QSPI_RSLT_ERR_DATA_SEL

#define CYHAL_QSPI_RSLT_ERR_DATA_SEL   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_QSPI, 2))

Data select Error. >

◆ CYHAL_QSPI_RSLT_ERR_INSTANCE

#define CYHAL_QSPI_RSLT_ERR_INSTANCE   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_QSPI, 3))

QSPI instance related Error. >

Typedef Documentation

◆ cyhal_qspi_event_callback_t

typedef void(* cyhal_qspi_event_callback_t) (void *callback_arg, cyhal_qspi_event_t event)

Handler for QSPI callbacks

Enumeration Type Documentation

◆ cyhal_qspi_bus_width_t

QSPI Bus width

Some parts of commands provide variable bus width

◆ cyhal_qspi_size_t

Size in bits

◆ cyhal_qspi_event_t

QSPI interrupt triggers

Enumerator
CYHAL_QSPI_EVENT_NONE 

No event >

CYHAL_QSPI_IRQ_TRANSMIT_DONE 

Async transmit done. >

CYHAL_QSPI_IRQ_RECEIVE_DONE 

Async receive done. >

Function Documentation

◆ cyhal_qspi_init()

cy_rslt_t cyhal_qspi_init ( cyhal_qspi_t *  obj,
cyhal_gpio_t  io0,
cyhal_gpio_t  io1,
cyhal_gpio_t  io2,
cyhal_gpio_t  io3,
cyhal_gpio_t  io4,
cyhal_gpio_t  io5,
cyhal_gpio_t  io6,
cyhal_gpio_t  io7,
cyhal_gpio_t  sclk,
cyhal_gpio_t  ssel,
uint32_t  hz,
uint8_t  mode 
)

Initialize QSPI peripheral.

It should initialize QSPI pins (io0-io7, sclk and ssel), set frequency, clock polarity and phase mode. The clock for the peripheral should be enabled

Parameters
[out]objQSPI object
[in]io0Data pin 0
[in]io1Data pin 1
[in]io2Data pin 2
[in]io3Data pin 3
[in]io4Data pin 4
[in]io5Data pin 5
[in]io6Data pin 6
[in]io7Data pin 7
[in]sclkThe clock pin
[in]sselThe chip select pin
[in]hzThe bus frequency
[in]modeClock polarity and phase mode (0 - 3)
Returns
The status of the init request

◆ cyhal_qspi_free()

void cyhal_qspi_free ( cyhal_qspi_t *  obj)

Deinitilize QSPI peripheral

It should release pins that are associated with the QSPI object, and disable clocks for QSPI peripheral module that was associated with the object

Parameters
[in,out]objQSPI object

◆ cyhal_qspi_set_frequency()

cy_rslt_t cyhal_qspi_set_frequency ( cyhal_qspi_t *  obj,
uint32_t  hz 
)

Set the QSPI baud rate

Actual frequency may differ from the desired frequency due to available dividers and the bus clock Configures the QSPI peripheral's baud rate

Parameters
[in]objThe QSPI object to configure
[in]hzThe baud rate in Hz
Returns
The status of the set_frequency request

◆ cyhal_qspi_read()

cy_rslt_t cyhal_qspi_read ( cyhal_qspi_t *  obj,
const cyhal_qspi_command_t *  command,
void *  data,
size_t *  length 
)

Receive a command and block of data, synchronously.

Parameters
[in]objQSPI object
[in]commandQSPI command
[out]dataRX buffer
[in,out]lengthin - RX buffer length in bytes, out - number of bytes read
Returns
The status of the read request

◆ cyhal_qspi_read_async()

cy_rslt_t cyhal_qspi_read_async ( cyhal_qspi_t *  obj,
const cyhal_qspi_command_t *  command,
void *  data,
size_t *  length 
)

Receive a command and block of data in asynchronous mode. This requires __enable_irq() to have been called in order to work. To receive a notification when the read is complete, enable and register a callback using cyhal_qspi_irq_enable and cyhal_qspi_register_irq.

Parameters
[in]objQSPI object
[in]commandQSPI command
[out]dataRX buffer
[in,out]lengthin - RX buffer length in bytes, out - number of bytes read
Returns
The status of the read request

◆ cyhal_qspi_write()

cy_rslt_t cyhal_qspi_write ( cyhal_qspi_t *  obj,
const cyhal_qspi_command_t *  command,
const void *  data,
size_t *  length 
)

Send a command and block of data, synchronously.

Parameters
[in]objQSPI object
[in]commandQSPI command
[in]dataTX buffer
[in,out]lengthin - TX buffer length in bytes, out - number of bytes written
Returns
The status of the write request

◆ cyhal_qspi_write_async()

cy_rslt_t cyhal_qspi_write_async ( cyhal_qspi_t *  obj,
const cyhal_qspi_command_t *  command,
const void *  data,
size_t *  length 
)

Send a command and block of data in asynchronous mode. This requires __enable_irq() to have been called in order to work. To receive a notification when the read is complete, enable and register a callback using cyhal_qspi_irq_enable and cyhal_qspi_register_irq.

Parameters
[in]objQSPI object
[in]commandQSPI command
[in]dataTX buffer
[in,out]lengthin - TX buffer length in bytes, out - number of bytes written
Returns
The status of the write request

◆ cyhal_qspi_transfer()

cy_rslt_t cyhal_qspi_transfer ( cyhal_qspi_t *  obj,
const cyhal_qspi_command_t *  command,
const void *  tx_data,
size_t  tx_size,
void *  rx_data,
size_t  rx_size 
)

Send a command (and optionally data) and get the response. Can be used to send/receive device specific commands

Parameters
[in]objQSPI object
[in]commandQSPI command
[in]tx_dataTX buffer
[in,out]tx_sizein - TX buffer length in bytes, out - bytes actually written
[out]rx_dataRX buffer
[in,out]rx_sizein - RX buffer length in bytes, out - bytes actually read
Returns
The status of the transfer request

◆ cyhal_qspi_register_callback()

void cyhal_qspi_register_callback ( cyhal_qspi_t *  obj,
cyhal_qspi_event_callback_t  callback,
void *  callback_arg 
)

The QSPI event handler registration

Parameters
[in]objThe QSPI object
[in]callbackThe callback handler which will be invoked when the interrupt fires
[in]callback_argGeneric argument that will be provided to the handler when called

◆ cyhal_qspi_enable_event()

void cyhal_qspi_enable_event ( cyhal_qspi_t *  obj,
cyhal_qspi_event_t  event,
uint8_t  intrPriority,
bool  enable 
)

Configure QSPI interrupt enablement.

Parameters
[in]objThe QSPI object
[in]eventThe QSPI event type
[in]intrPriorityThe priority for NVIC interrupt events
[in]enableTrue to turn on interrupts, False to turn off