Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
OSPI Class Reference

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

#include <OSPI.h>

Inheritance diagram for OSPI:
NonCopyable< OSPI >

Public Member Functions

 OSPI (PinName io0, PinName io1, PinName io2, PinName io3, PinName io4, PinName io5, PinName io6, PinName io7, PinName sclk, PinName ssel=NC, PinName dqs=NC, int mode=0)
 Create a OSPI master connected to the specified pins. More...
 
 OSPI (const ospi_pinmap_t &pinmap, int mode=0)
 Create a OSPI master connected to the specified pins. More...
 
ospi_status_t configure_format (ospi_bus_width_t inst_width, ospi_inst_size_t inst_size, ospi_bus_width_t address_width, ospi_address_size_t address_size, ospi_bus_width_t alt_width, ospi_alt_size_t alt_size, ospi_bus_width_t data_width, int dummy_cycles)
 Configure the data transmission format. More...
 
ospi_status_t set_frequency (int hz=1000000)
 Set the ospi bus clock frequency. More...
 
ospi_status_t read (int address, char *rx_buffer, size_t *rx_length)
 Read from OSPI peripheral with the preset read_instruction and alt_value. More...
 
ospi_status_t write (int address, const char *tx_buffer, size_t *tx_length)
 Write to OSPI peripheral using custom write instruction. More...
 
ospi_status_t read (ospi_inst_t instruction, int alt, int address, char *rx_buffer, size_t *rx_length)
 Read from OSPI peripheral using custom read instruction, alt values. More...
 
ospi_status_t write (ospi_inst_t instruction, int alt, int address, const char *tx_buffer, size_t *tx_length)
 Write to OSPI peripheral using custom write instruction, alt values. More...
 
ospi_status_t command_transfer (ospi_inst_t 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. More...
 

Detailed Description

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

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

Note
Synchronization level: Thread safe

Example:

// Write 4 byte array to a OSPI 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)
OSPI ospi_device(OSPI_FLASH1_IO0, OSPI_FLASH1_IO1, OSPI_FLASH1_IO2, OSPI_FLASH1_IO3, OSPI_FLASH1_IO4, OSPI_FLASH1_IO5, OSPI_FLASH1_IO6,
OSPI_FLASH1_SCK, OSPI_FLASH1_CSN, OSPI_FLASH1_DQS); // io0, io1, io2, io3, io4, io5, io6, io7, sclk, ssel, dqs
int main() {
char tx_buf[] = { 0x11, 0x22, 0x33, 0x44 };
char rx_buf[4];
int buf_len = sizeof(tx_buf);
ospi_status_t result = ospi_device.write(CMD_WRITE, 0, ADDRESS, tx_buf, &buf_len);
if (result != OSPI_STATUS_OK) {
printf("Write failed");
}
result = ospi_device.read(CMD_READ, 0, ADDRESS, rx_buf, &buf_len);
if (result != OSPI_STATUS_OK) {
printf("Read failed");
}
}

Definition at line 87 of file OSPI.h.

Constructor & Destructor Documentation

OSPI ( PinName  io0,
PinName  io1,
PinName  io2,
PinName  io3,
PinName  io4,
PinName  io5,
PinName  io6,
PinName  io7,
PinName  sclk,
PinName  ssel = NC,
PinName  dqs = NC,
int  mode = 0 
)

Create a OSPI 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
io45th IO pin used for sending/receiving data during data phase of a transaction
io56th IO pin used for sending/receiving data during data phase of a transaction
io67th IO pin used for sending/receiving data during data phase of a transaction
io78th IO pin used for sending/receiving data during data phase of a transaction
sclkOSPI Clock pin
sselOSPI chip select pin
dqsOSPI dqs 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)
OSPI ( const ospi_pinmap_t &  pinmap,
int  mode = 0 
)

Create a OSPI master connected to the specified pins.

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

Parameters
pinmapreference to structure which holds static pinmap
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

ospi_status_t command_transfer ( ospi_inst_t  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. Use OSPI_NO_INST to skip the 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 OSPI_STATUS_SUCCESS on successful reads and OSPI_STATUS_ERROR on failed reads.
ospi_status_t configure_format ( ospi_bus_width_t  inst_width,
ospi_inst_size_t  inst_size,
ospi_bus_width_t  address_width,
ospi_address_size_t  address_size,
ospi_bus_width_t  alt_width,
ospi_alt_size_t  alt_size,
ospi_bus_width_t  data_width,
int  dummy_cycles 
)

Configure the data transmission format.

Parameters
inst_widthBus width used by instruction phase(Valid values are OSPI_CFG_BUS_SINGLE, OSPI_CFG_BUS_DUAL, OSPI_CFG_BUS_QUAD)
inst_sizeSize in bits used by instruction phase
address_widthBus width used by address phase(Valid values are OSPI_CFG_BUS_SINGLE, OSPI_CFG_BUS_DUAL, OSPI_CFG_BUS_QUAD)
address_sizeSize in bits used by address phase(Valid values are OSPI_CFG_ADDR_SIZE_8, OSPI_CFG_ADDR_SIZE_16, OSPI_CFG_ADDR_SIZE_24, OSPI_CFG_ADDR_SIZE_32)
alt_widthBus width used by alt phase(Valid values are OSPI_CFG_BUS_SINGLE, OSPI_CFG_BUS_DUAL, OSPI_CFG_BUS_QUAD)
alt_sizeSize in bits used by alt phase (must be a multiple of the number of bus lines indicated in alt_width)
data_widthBus width used by data phase(Valid values are OSPI_CFG_BUS_SINGLE, OSPI_CFG_BUS_DUAL, OSPI_CFG_BUS_QUAD)
dummy_cyclesNumber of dummy clock cycles to be used after alt phase
ospi_status_t read ( int  address,
char *  rx_buffer,
size_t *  rx_length 
)

Read from OSPI peripheral with the preset read_instruction and alt_value.

Parameters
addressAddress to be accessed in OSPI 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 OSPI_STATUS_SUCCESS on successful reads and OSPI_STATUS_ERROR on failed reads.
ospi_status_t read ( ospi_inst_t  instruction,
int  alt,
int  address,
char *  rx_buffer,
size_t *  rx_length 
)

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

Parameters
instructionInstruction value to be used in instruction phase. Use OSPI_NO_INST to skip the instruction phase
altAlt value to be used in Alternate-byte phase. Use -1 for ignoring Alternate-byte phase
addressAddress to be accessed in OSPI 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 OSPI_STATUS_SUCCESS on successful reads and OSPI_STATUS_ERROR on failed reads.
ospi_status_t set_frequency ( int  hz = 1000000)

Set the ospi bus clock frequency.

Parameters
hzSCLK frequency in hz (default = 1MHz)
Returns
Returns OSPI_STATUS_SUCCESS on successful, fails if the interface is already init-ed
ospi_status_t write ( int  address,
const char *  tx_buffer,
size_t *  tx_length 
)

Write to OSPI peripheral using custom write instruction.

Parameters
addressAddress to be accessed in OSPI 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 OSPI_STATUS_SUCCESS on successful reads and OSPI_STATUS_ERROR on failed reads.
ospi_status_t write ( ospi_inst_t  instruction,
int  alt,
int  address,
const char *  tx_buffer,
size_t *  tx_length 
)

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

Parameters
instructionInstruction value to be used in instruction phase. Use OSPI_NO_INST to skip the instruction phase
altAlt value to be used in Alternate-byte phase. Use -1 for ignoring Alternate-byte phase
addressAddress to be accessed in OSPI 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 OSPI_STATUS_SUCCESS on successful reads and OSPI_STATUS_ERROR on failed reads.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.