mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

QSPI Class Reference

A QSPI Driver, used for communicating with QSPI slave devices. More...

#include <QSPI.h>

Inherits NonCopyable< QSPI >, and NonCopyable< QSPI >.

Public Member Functions

 QSPI (PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel=NC, int mode=0)
 Create a QSPI master connected to the specified pins.
qspi_status_t configure_format (qspi_bus_width_t inst_width, qspi_bus_width_t address_width, qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width, int dummy_cycles)
 Configure the data transmission format.
qspi_status_t set_frequency (int hz=ONE_MHZ)
 Set the qspi bus clock frequency.
qspi_status_t read (int address, char *rx_buffer, size_t *rx_length)
 Read from QSPI peripheral with the preset read_instruction and alt_value.
qspi_status_t write (int address, const char *tx_buffer, size_t *tx_length)
 Write to QSPI peripheral using custom write instruction.
qspi_status_t read (int instruction, int alt, int address, char *rx_buffer, size_t *rx_length)
 Read from QSPI peripheral using custom read instruction, alt values.
qspi_status_t write (int instruction, int alt, int address, const char *tx_buffer, size_t *tx_length)
 Write to QSPI peripheral using custom write instruction, alt values.
qspi_status_t command_transfer (int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length)
 Perform a transaction to write to an address(a control register) and get the status results.
 QSPI (PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel=NC, int mode=0)
 Create a QSPI master connected to the specified pins.
qspi_status_t configure_format (qspi_bus_width_t inst_width, qspi_bus_width_t address_width, qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width, int dummy_cycles)
 Configure the data transmission format.
qspi_status_t set_frequency (int hz=ONE_MHZ)
 Set the qspi bus clock frequency.
qspi_status_t read (int address, char *rx_buffer, size_t *rx_length)
 Read from QSPI peripheral with the preset read_instruction and alt_value.
qspi_status_t write (int address, const char *tx_buffer, size_t *tx_length)
 Write to QSPI peripheral using custom write instruction.
qspi_status_t read (int instruction, int alt, int address, char *rx_buffer, size_t *rx_length)
 Read from QSPI peripheral using custom read instruction, alt values.
qspi_status_t write (int instruction, int alt, int address, const char *tx_buffer, size_t *tx_length)
 Write to QSPI peripheral using custom write instruction, alt values.
qspi_status_t command_transfer (int instruction, int address, const char *tx_buffer, size_t tx_length, const char *rx_buffer, size_t rx_length)
 Perform a transaction to write to an address(a control register) and get the status results.

Protected Member Functions

virtual void lock (void)
 Acquire exclusive access to this SPI bus.
virtual void unlock (void)
 Release exclusive access to this SPI bus.
virtual void lock (void)
 Acquire exclusive access to this SPI bus.
virtual void unlock (void)
 Release exclusive access to this SPI bus.

Private Member Functions

 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.
 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.

Detailed Description

A QSPI Driver, used for communicating with QSPI slave devices.

The default format is set to Quad-SPI(1-1-1), and a clock frequency of 1MHz Most QSPI devices will also require Chip Select which is indicated by ssel.

Note:
Synchronization level: Thread safe

Example:

 // Write 4 byte array to a QSPI slave, and read the response, note that each device will have its specific read/write/alt values defined

 #include "mbed.h"

 #define CMD_WRITE 0x02
 #define CMD_READ  0x03
 #define ADDRESS   0x1000

 // hardware ssel (where applicable)
 QSPI qspi_device(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN); // io0, io1, io2, io3, sclk, ssel


 int main() {
     char tx_buf[] = { 0x11, 0x22, 0x33, 0x44 };
     char rx_buf[4];
     int buf_len = sizeof(tx_buf);

     qspi_status_t result = qspi_device.write(CMD_WRITE, 0, ADDRESS, tx_buf, &buf_len);
     if (result != QSPI_STATUS_OK) {
        printf("Write failed");
     }
     result = qspi_device.read(CMD_READ, 0, ADDRESS, rx_buf, &buf_len);
     if (result != QSPI_STATUS_OK) {
        printf("Read failed");
     }

 }

Definition at line 74 of file cmsis/BUILD/mbed/drivers/QSPI.h.


Constructor & Destructor Documentation

QSPI ( PinName  io0,
PinName  io1,
PinName  io2,
PinName  io3,
PinName  sclk,
PinName  ssel = NC,
int  mode = 0 
)

Create a QSPI master connected to the specified pins.

io0-io3 is used to specify the Pins used for Quad SPI mode

Parameters:
io01st IO pin used for sending/receiving data during data phase of a transaction
io12nd IO pin used for sending/receiving data during data phase of a transaction
io23rd IO pin used for sending/receiving data during data phase of a transaction
io34th IO pin used for sending/receiving data during data phase of a transaction
sclkQSPI Clock pin
sselQSPI chip select pin
modeClock polarity and phase mode (0 - 3) of SPI (Default: Mode=0 uses CPOL=0, CPHA=0, Mode=1 uses CPOL=1, CPHA=1)

Definition at line 29 of file QSPI.cpp.

QSPI ( PinName  io0,
PinName  io1,
PinName  io2,
PinName  io3,
PinName  sclk,
PinName  ssel = NC,
int  mode = 0 
)

Create a QSPI master connected to the specified pins.

io0-io3 is used to specify the Pins used for Quad SPI mode

Parameters:
io01st IO pin used for sending/receiving data during data phase of a transaction
io12nd IO pin used for sending/receiving data during data phase of a transaction
io23rd IO pin used for sending/receiving data during data phase of a transaction
io34th IO pin used for sending/receiving data during data phase of a transaction
sclkQSPI Clock pin
sselQSPI chip select pin
modeClock polarity and phase mode (0 - 3) of SPI (Default: Mode=0 uses CPOL=0, CPHA=0, Mode=1 uses CPOL=1, CPHA=1)

Member Function Documentation

qspi_status_t command_transfer ( int  instruction,
int  address,
const char *  tx_buffer,
size_t  tx_length,
const char *  rx_buffer,
size_t  rx_length 
)

Perform a transaction to write to an address(a control register) and get the status results.

Parameters:
instructionInstruction value to be used in instruction phase
addressSome instruction might require address. Use -1 if no address
tx_bufferBuffer containing data to be sent to peripheral
tx_lengthPointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written
rx_bufferBuffer for data to be read from the peripheral
rx_lengthPointer to a variable containing the length of rx_buffer, and on return this variable will be updated with the actual number of bytes read
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
qspi_status_t command_transfer ( int  instruction,
int  address,
const char *  tx_buffer,
size_t  tx_length,
const char *  rx_buffer,
size_t  rx_length 
)

Perform a transaction to write to an address(a control register) and get the status results.

Parameters:
instructionInstruction value to be used in instruction phase
addressSome instruction might require address. Use -1 if no address
tx_bufferBuffer containing data to be sent to peripheral
tx_lengthPointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written
rx_bufferBuffer for data to be read from the peripheral
rx_lengthPointer to a variable containing the length of rx_buffer, and on return this variable will be updated with the actual number of bytes read
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.

Definition at line 191 of file QSPI.cpp.

qspi_status_t configure_format ( qspi_bus_width_t  inst_width,
qspi_bus_width_t  address_width,
qspi_address_size_t  address_size,
qspi_bus_width_t  alt_width,
qspi_alt_size_t  alt_size,
qspi_bus_width_t  data_width,
int  dummy_cycles 
)

Configure the data transmission format.

Parameters:
inst_widthBus width used by instruction phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
address_widthBus width used by address phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
address_sizeSize in bits used by address phase(Valid values are QSPI_CFG_ADDR_SIZE_8, QSPI_CFG_ADDR_SIZE_16, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_ADDR_SIZE_32)
alt_widthBus width used by alt phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
alt_sizeSize in bits used by alt phase(Valid values are QSPI_CFG_ALT_SIZE_8, QSPI_CFG_ALT_SIZE_16, QSPI_CFG_ALT_SIZE_24, QSPI_CFG_ALT_SIZE_32)
data_widthBus width used by data phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
dummy_cyclesNumber of dummy clock cycles to be used after alt phase
qspi_status_t configure_format ( qspi_bus_width_t  inst_width,
qspi_bus_width_t  address_width,
qspi_address_size_t  address_size,
qspi_bus_width_t  alt_width,
qspi_alt_size_t  alt_size,
qspi_bus_width_t  data_width,
int  dummy_cycles 
)

Configure the data transmission format.

Parameters:
inst_widthBus width used by instruction phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
address_widthBus width used by address phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
address_sizeSize in bits used by address phase(Valid values are QSPI_CFG_ADDR_SIZE_8, QSPI_CFG_ADDR_SIZE_16, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_ADDR_SIZE_32)
alt_widthBus width used by alt phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
alt_sizeSize in bits used by alt phase(Valid values are QSPI_CFG_ALT_SIZE_8, QSPI_CFG_ALT_SIZE_16, QSPI_CFG_ALT_SIZE_24, QSPI_CFG_ALT_SIZE_32)
data_widthBus width used by data phase(Valid values are QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_QUAD)
dummy_cyclesNumber of dummy clock cycles to be used after alt phase

Definition at line 53 of file QSPI.cpp.

virtual void lock ( void   ) [protected, virtual]

Acquire exclusive access to this SPI bus.

void lock ( void   ) [protected, virtual]

Acquire exclusive access to this SPI bus.

Definition at line 209 of file QSPI.cpp.

qspi_status_t read ( int  instruction,
int  alt,
int  address,
char *  rx_buffer,
size_t *  rx_length 
)

Read from QSPI peripheral using custom read instruction, alt values.

Parameters:
instructionInstruction value to be used in instruction phase
altAlt value to be used in Alternate-byte phase. Use -1 for ignoring Alternate-byte phase
addressAddress to be accessed in QSPI peripheral
rx_bufferBuffer for data to be read from the peripheral
rx_lengthPointer to a variable containing the length of rx_buffer, and on return this variable will be updated with the actual number of bytes read
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.

Definition at line 143 of file QSPI.cpp.

qspi_status_t read ( int  instruction,
int  alt,
int  address,
char *  rx_buffer,
size_t *  rx_length 
)

Read from QSPI peripheral using custom read instruction, alt values.

Parameters:
instructionInstruction value to be used in instruction phase
altAlt value to be used in Alternate-byte phase. Use -1 for ignoring Alternate-byte phase
addressAddress to be accessed in QSPI peripheral
rx_bufferBuffer for data to be read from the peripheral
rx_lengthPointer to a variable containing the length of rx_buffer, and on return this variable will be updated with the actual number of bytes read
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
qspi_status_t read ( int  address,
char *  rx_buffer,
size_t *  rx_length 
)

Read from QSPI peripheral with the preset read_instruction and alt_value.

Parameters:
addressAddress to be accessed in QSPI peripheral
rx_bufferBuffer for data to be read from the peripheral
rx_lengthPointer to a variable containing the length of rx_buffer, and on return this variable will be updated with the actual number of bytes read
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
qspi_status_t read ( int  address,
char *  rx_buffer,
size_t *  rx_length 
)

Read from QSPI peripheral with the preset read_instruction and alt_value.

Parameters:
addressAddress to be accessed in QSPI peripheral
rx_bufferBuffer for data to be read from the peripheral
rx_lengthPointer to a variable containing the length of rx_buffer, and on return this variable will be updated with the actual number of bytes read
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.

Definition at line 95 of file QSPI.cpp.

qspi_status_t set_frequency ( int  hz = ONE_MHZ )

Set the qspi bus clock frequency.

Parameters:
hzSCLK frequency in hz (default = 1MHz)
Returns:
Returns QSPI_STATUS_SUCCESS on successful, fails if the interface is already init-ed

Definition at line 71 of file QSPI.cpp.

qspi_status_t set_frequency ( int  hz = ONE_MHZ )

Set the qspi bus clock frequency.

Parameters:
hzSCLK frequency in hz (default = 1MHz)
Returns:
Returns QSPI_STATUS_SUCCESS on successful, fails if the interface is already init-ed
virtual void unlock ( void   ) [protected, virtual]

Release exclusive access to this SPI bus.

void unlock ( void   ) [protected, virtual]

Release exclusive access to this SPI bus.

Definition at line 214 of file QSPI.cpp.

qspi_status_t write ( int  address,
const char *  tx_buffer,
size_t *  tx_length 
)

Write to QSPI peripheral using custom write instruction.

Parameters:
addressAddress to be accessed in QSPI peripheral
tx_bufferBuffer containing data to be sent to peripheral
tx_lengthPointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
qspi_status_t write ( int  instruction,
int  alt,
int  address,
const char *  tx_buffer,
size_t *  tx_length 
)

Write to QSPI peripheral using custom write instruction, alt values.

Parameters:
instructionInstruction value to be used in instruction phase
altAlt value to be used in Alternate-byte phase. Use -1 for ignoring Alternate-byte phase
addressAddress to be accessed in QSPI peripheral
tx_bufferBuffer containing data to be sent to peripheral
tx_lengthPointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.

Definition at line 167 of file QSPI.cpp.

qspi_status_t write ( int  instruction,
int  alt,
int  address,
const char *  tx_buffer,
size_t *  tx_length 
)

Write to QSPI peripheral using custom write instruction, alt values.

Parameters:
instructionInstruction value to be used in instruction phase
altAlt value to be used in Alternate-byte phase. Use -1 for ignoring Alternate-byte phase
addressAddress to be accessed in QSPI peripheral
tx_bufferBuffer containing data to be sent to peripheral
tx_lengthPointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
qspi_status_t write ( int  address,
const char *  tx_buffer,
size_t *  tx_length 
)

Write to QSPI peripheral using custom write instruction.

Parameters:
addressAddress to be accessed in QSPI peripheral
tx_bufferBuffer containing data to be sent to peripheral
tx_lengthPointer to a variable containing the length of data to be transmitted, and on return this variable will be updated with the actual number of bytes written
Returns:
Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.

Definition at line 119 of file QSPI.cpp.