MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
FlexIO SPI Driver

Overview

The MCUXpresso SDK provides a peripheral driver for an SPI function using the Flexible I/O module of MCUXpresso SDK devices.

FlexIO SPI driver includes functional APIs and transactional APIs.

Functional APIs target low-level APIs. Functional APIs can be used for FlexIO SPI initialization/configuration/operation for optimization/customization purpose. Using the functional API requires the knowledge of the FlexIO SPI peripheral and how to organize functional APIs to meet the application requirements. All functional API use the FLEXIO_SPI_Type *base as the first parameter. FlexIO SPI functional operation groups provide the functional API set.

Transactional APIs target high-level APIs. Transactional APIs can be used to enable the peripheral and also in the application if the code size and performance of transactional APIs can satisfy requirements. If the code size and performance are critical requirements, see the transactional API implementation and write custom code. All transactional APIs use the flexio_spi_master_handle_t/flexio_spi_slave_handle_t as the second parameter. Initialize the handle by calling the FLEXIO_SPI_MasterTransferCreateHandle() or FLEXIO_SPI_SlaveTransferCreateHandle() API.

Transactional APIs support asynchronous transfer. This means that the functions FLEXIO_SPI_MasterTransferNonBlocking()/FLEXIO_SPI_SlaveTransferNonBlocking() set up an interrupt for data transfer. When the transfer is complete, the upper layer is notified through a callback function with the kStatus_FLEXIO_SPI_Idle status.

Note that the FlexIO SPI slave driver only supports discontinuous PCS access, which is a limitation. The FlexIO SPI slave driver can support continuous PCS, but the slave cannot adapt discontinuous and continuous PCS automatically. Users can change the timer disable mode in FLEXIO_SPI_SlaveInit manually, from kFLEXIO_TimerDisableOnTimerCompare to kFLEXIO_TimerDisableNever to enable a discontinuous PCS access. Only CPHA = 0 is supported.

Typical use case

FlexIO SPI send/receive using an interrupt method

flexio_spi_master_handle_t g_spiHandle;
volatile bool txFinished;
static uint8_t srcBuff[BUFFER_SIZE];
static uint8_t destBuff[BUFFER_SIZE];
void FLEXIO_SPI_MasterUserCallback(FLEXIO_SPI_Type *base, flexio_spi_master_handle_t *handle, status_t status, void *userData)
{
userData = userData;
if (kStatus_FLEXIO_SPI_Idle == status)
{
txFinished = true;
}
}
void main(void)
{
//...
userConfig.baudRate_Bps = 500000U;
spiDev.flexioBase = BOARD_FLEXIO_BASE;
spiDev.SDOPinIndex = FLEXIO_SPI_MOSI_PIN;
spiDev.SDIPinIndex = FLEXIO_SPI_MISO_PIN;
spiDev.SCKPinIndex = FLEXIO_SPI_SCK_PIN;
spiDev.CSnPinIndex = FLEXIO_SPI_CSn_PIN;
spiDev.shifterIndex[0] = 0U;
spiDev.shifterIndex[1] = 1U;
spiDev.timerIndex[0] = 0U;
spiDev.timerIndex[1] = 1U;
FLEXIO_SPI_MasterInit(&spiDev, &userConfig, FLEXIO_CLOCK_FREQUENCY);
xfer.txData = srcBuff;
xfer.rxData = destBuff;
xfer.dataSize = BUFFER_SIZE;
FLEXIO_SPI_MasterTransferCreateHandle(&spiDev, &g_spiHandle, FLEXIO_SPI_MasterUserCallback, NULL);
FLEXIO_SPI_MasterTransferNonBlocking(&spiDev, &g_spiHandle, &xfer);
// Send finished.
while (!txFinished)
{
}
// ...
}

FlexIO_SPI Send/Receive in DMA way

dma_handle_t g_spiTxDmaHandle;
dma_handle_t g_spiRxDmaHandle;
flexio_spi_master_handle_t g_spiHandle;
volatile bool txFinished;
static uint8_t srcBuff[BUFFER_SIZE];
static uint8_t destBuff[BUFFER_SIZE];
void FLEXIO_SPI_MasterUserCallback(FLEXIO_SPI_Type *base, flexio_spi_master_dma_handle_t *handle, status_t status, void *userData)
{
userData = userData;
if (kStatus_FLEXIO_SPI_Idle == status)
{
txFinished = true;
}
}
void main(void)
{
userConfig.baudRate_Bps = 500000U;
spiDev.flexioBase = BOARD_FLEXIO_BASE;
spiDev.SDOPinIndex = FLEXIO_SPI_MOSI_PIN;
spiDev.SDIPinIndex = FLEXIO_SPI_MISO_PIN;
spiDev.SCKPinIndex = FLEXIO_SPI_SCK_PIN;
spiDev.CSnPinIndex = FLEXIO_SPI_CSn_PIN;
spiDev.shifterIndex[0] = 0U;
spiDev.shifterIndex[1] = 1U;
spiDev.timerIndex[0] = 0U;
spiDev.timerIndex[1] = 1U;
/* Init DMAMUX. */
DMAMUX_Init(EXAMPLE_FLEXIO_SPI_DMAMUX_BASEADDR)
/* Init the DMA/EDMA module */
#if defined(FSL_FEATURE_SOC_DMA_COUNT) && FSL_FEATURE_SOC_DMA_COUNT > 0U
DMA_Init(EXAMPLE_FLEXIO_SPI_DMA_BASEADDR);
DMA_CreateHandle(&txHandle, EXAMPLE_FLEXIO_SPI_DMA_BASEADDR, FLEXIO_SPI_TX_DMA_CHANNEL);
DMA_CreateHandle(&rxHandle, EXAMPLE_FLEXIO_SPI_DMA_BASEADDR, FLEXIO_SPI_RX_DMA_CHANNEL);
#endif /* FSL_FEATURE_SOC_DMA_COUNT */
#if defined(FSL_FEATURE_SOC_EDMA_COUNT) && FSL_FEATURE_SOC_EDMA_COUNT > 0U
edma_config_t edmaConfig;
EDMA_GetDefaultConfig(&edmaConfig);
EDMA_Init(EXAMPLE_FLEXIO_SPI_DMA_BASEADDR, &edmaConfig);
EDMA_CreateHandle(&txHandle, EXAMPLE_FLEXIO_SPI_DMA_BASEADDR, FLEXIO_SPI_TX_DMA_CHANNEL);
EDMA_CreateHandle(&rxHandle, EXAMPLE_FLEXIO_SPI_DMA_BASEADDR, FLEXIO_SPI_RX_DMA_CHANNEL);
#endif /* FSL_FEATURE_SOC_EDMA_COUNT */
dma_request_source_tx = (dma_request_source_t)(FLEXIO_DMA_REQUEST_BASE + spiDev.shifterIndex[0]);
dma_request_source_rx = (dma_request_source_t)(FLEXIO_DMA_REQUEST_BASE + spiDev.shifterIndex[1]);
/* Requests DMA channels for transmit and receive. */
DMAMUX_SetSource(EXAMPLE_FLEXIO_SPI_DMAMUX_BASEADDR, FLEXIO_SPI_TX_DMA_CHANNEL, (dma_request_source_t)dma_request_source_tx);
DMAMUX_SetSource(EXAMPLE_FLEXIO_SPI_DMAMUX_BASEADDR, FLEXIO_SPI_RX_DMA_CHANNEL, (dma_request_source_t)dma_request_source_rx);
DMAMUX_EnableChannel(EXAMPLE_FLEXIO_SPI_DMAMUX_BASEADDR, FLEXIO_SPI_TX_DMA_CHANNEL);
DMAMUX_EnableChannel(EXAMPLE_FLEXIO_SPI_DMAMUX_BASEADDR, FLEXIO_SPI_RX_DMA_CHANNEL);
FLEXIO_SPI_MasterInit(&spiDev, &userConfig, FLEXIO_CLOCK_FREQUENCY);
/* Initializes the buffer. */
for (i = 0; i < BUFFER_SIZE; i++)
{
srcBuff[i] = i;
}
/* Sends to the slave. */
xfer.txData = srcBuff;
xfer.rxData = destBuff;
xfer.dataSize = BUFFER_SIZE;
FLEXIO_SPI_MasterTransferCreateHandleDMA(&spiDev, &g_spiHandle, FLEXIO_SPI_MasterUserCallback, NULL, &g_spiTxDmaHandle, &g_spiRxDmaHandle);
FLEXIO_SPI_MasterTransferDMA(&spiDev, &g_spiHandle, &xfer);
// Send finished.
while (!txFinished)
{
}
// ...
}

Data Structures

struct  FLEXIO_SPI_Type
 Define FlexIO SPI access structure typedef. More...
 
struct  flexio_spi_master_config_t
 Define FlexIO SPI master configuration structure. More...
 
struct  flexio_spi_slave_config_t
 Define FlexIO SPI slave configuration structure. More...
 
struct  flexio_spi_transfer_t
 Define FlexIO SPI transfer structure. More...
 
struct  flexio_spi_master_handle_t
 Define FlexIO SPI handle structure. More...
 

Macros

#define FLEXIO_SPI_DUMMYDATA   (0xFFFFU)
 FlexIO SPI dummy transfer data, the data is sent while txData is NULL. More...
 
#define SPI_RETRY_TIMES   0U /* Define to zero means keep waiting until the flag is assert/deassert. */
 Retry times for waiting flag. More...
 

Typedefs

typedef flexio_spi_master_handle_t flexio_spi_slave_handle_t
 Slave handle is the same with master handle. More...
 
typedef void(* flexio_spi_master_transfer_callback_t )(FLEXIO_SPI_Type *base, flexio_spi_master_handle_t *handle, status_t status, void *userData)
 FlexIO SPI master callback for finished transmit.
 
typedef void(* flexio_spi_slave_transfer_callback_t )(FLEXIO_SPI_Type *base, flexio_spi_slave_handle_t *handle, status_t status, void *userData)
 FlexIO SPI slave callback for finished transmit.
 

Enumerations

enum  {
  kStatus_FLEXIO_SPI_Busy = MAKE_STATUS(kStatusGroup_FLEXIO_SPI, 1),
  kStatus_FLEXIO_SPI_Idle = MAKE_STATUS(kStatusGroup_FLEXIO_SPI, 2),
  kStatus_FLEXIO_SPI_Error = MAKE_STATUS(kStatusGroup_FLEXIO_SPI, 3),
  kStatus_FLEXIO_SPI_Timeout
}
 Error codes for the FlexIO SPI driver. More...
 
enum  flexio_spi_clock_phase_t {
  kFLEXIO_SPI_ClockPhaseFirstEdge = 0x0U,
  kFLEXIO_SPI_ClockPhaseSecondEdge = 0x1U
}
 FlexIO SPI clock phase configuration. More...
 
enum  flexio_spi_shift_direction_t {
  kFLEXIO_SPI_MsbFirst = 0,
  kFLEXIO_SPI_LsbFirst = 1
}
 FlexIO SPI data shifter direction options. More...
 
enum  flexio_spi_data_bitcount_mode_t {
  kFLEXIO_SPI_8BitMode = 0x08U,
  kFLEXIO_SPI_16BitMode = 0x10U
}
 FlexIO SPI data length mode options. More...
 
enum  _flexio_spi_interrupt_enable {
  kFLEXIO_SPI_TxEmptyInterruptEnable = 0x1U,
  kFLEXIO_SPI_RxFullInterruptEnable = 0x2U
}
 Define FlexIO SPI interrupt mask. More...
 
enum  _flexio_spi_status_flags {
  kFLEXIO_SPI_TxBufferEmptyFlag = 0x1U,
  kFLEXIO_SPI_RxBufferFullFlag = 0x2U
}
 Define FlexIO SPI status mask. More...
 
enum  _flexio_spi_dma_enable {
  kFLEXIO_SPI_TxDmaEnable = 0x1U,
  kFLEXIO_SPI_RxDmaEnable = 0x2U,
  kFLEXIO_SPI_DmaAllEnable = 0x3U
}
 Define FlexIO SPI DMA mask. More...
 
enum  _flexio_spi_transfer_flags {
  kFLEXIO_SPI_8bitMsb = 0x1U,
  kFLEXIO_SPI_8bitLsb = 0x2U,
  kFLEXIO_SPI_16bitMsb = 0x9U,
  kFLEXIO_SPI_16bitLsb = 0xaU
}
 Define FlexIO SPI transfer flags. More...
 

Driver version

#define FSL_FLEXIO_SPI_DRIVER_VERSION   (MAKE_VERSION(2, 2, 0))
 FlexIO SPI driver version 2.2.0. More...
 

FlexIO SPI Configuration

void FLEXIO_SPI_MasterInit (FLEXIO_SPI_Type *base, flexio_spi_master_config_t *masterConfig, uint32_t srcClock_Hz)
 Ungates the FlexIO clock, resets the FlexIO module, configures the FlexIO SPI master hardware, and configures the FlexIO SPI with FlexIO SPI master configuration. More...
 
void FLEXIO_SPI_MasterDeinit (FLEXIO_SPI_Type *base)
 Resets the FlexIO SPI timer and shifter config. More...
 
void FLEXIO_SPI_MasterGetDefaultConfig (flexio_spi_master_config_t *masterConfig)
 Gets the default configuration to configure the FlexIO SPI master. More...
 
void FLEXIO_SPI_SlaveInit (FLEXIO_SPI_Type *base, flexio_spi_slave_config_t *slaveConfig)
 Ungates the FlexIO clock, resets the FlexIO module, configures the FlexIO SPI slave hardware configuration, and configures the FlexIO SPI with FlexIO SPI slave configuration. More...
 
void FLEXIO_SPI_SlaveDeinit (FLEXIO_SPI_Type *base)
 Gates the FlexIO clock. More...
 
void FLEXIO_SPI_SlaveGetDefaultConfig (flexio_spi_slave_config_t *slaveConfig)
 Gets the default configuration to configure the FlexIO SPI slave. More...
 

Status

uint32_t FLEXIO_SPI_GetStatusFlags (FLEXIO_SPI_Type *base)
 Gets FlexIO SPI status flags. More...
 
void FLEXIO_SPI_ClearStatusFlags (FLEXIO_SPI_Type *base, uint32_t mask)
 Clears FlexIO SPI status flags. More...
 

Interrupts

void FLEXIO_SPI_EnableInterrupts (FLEXIO_SPI_Type *base, uint32_t mask)
 Enables the FlexIO SPI interrupt. More...
 
void FLEXIO_SPI_DisableInterrupts (FLEXIO_SPI_Type *base, uint32_t mask)
 Disables the FlexIO SPI interrupt. More...
 

DMA Control

void FLEXIO_SPI_EnableDMA (FLEXIO_SPI_Type *base, uint32_t mask, bool enable)
 Enables/disables the FlexIO SPI transmit DMA. More...
 
static uint32_t FLEXIO_SPI_GetTxDataRegisterAddress (FLEXIO_SPI_Type *base, flexio_spi_shift_direction_t direction)
 Gets the FlexIO SPI transmit data register address for MSB first transfer. More...
 
static uint32_t FLEXIO_SPI_GetRxDataRegisterAddress (FLEXIO_SPI_Type *base, flexio_spi_shift_direction_t direction)
 Gets the FlexIO SPI receive data register address for the MSB first transfer. More...
 

Bus Operations

static void FLEXIO_SPI_Enable (FLEXIO_SPI_Type *base, bool enable)
 Enables/disables the FlexIO SPI module operation. More...
 
void FLEXIO_SPI_MasterSetBaudRate (FLEXIO_SPI_Type *base, uint32_t baudRate_Bps, uint32_t srcClockHz)
 Sets baud rate for the FlexIO SPI transfer, which is only used for the master. More...
 
static void FLEXIO_SPI_WriteData (FLEXIO_SPI_Type *base, flexio_spi_shift_direction_t direction, uint16_t data)
 Writes one byte of data, which is sent using the MSB method. More...
 
static uint16_t FLEXIO_SPI_ReadData (FLEXIO_SPI_Type *base, flexio_spi_shift_direction_t direction)
 Reads 8 bit/16 bit data. More...
 
status_t FLEXIO_SPI_WriteBlocking (FLEXIO_SPI_Type *base, flexio_spi_shift_direction_t direction, const uint8_t *buffer, size_t size)
 Sends a buffer of data bytes. More...
 
status_t FLEXIO_SPI_ReadBlocking (FLEXIO_SPI_Type *base, flexio_spi_shift_direction_t direction, uint8_t *buffer, size_t size)
 Receives a buffer of bytes. More...
 
status_t FLEXIO_SPI_MasterTransferBlocking (FLEXIO_SPI_Type *base, flexio_spi_transfer_t *xfer)
 Receives a buffer of bytes. More...
 

Transactional

status_t FLEXIO_SPI_MasterTransferCreateHandle (FLEXIO_SPI_Type *base, flexio_spi_master_handle_t *handle, flexio_spi_master_transfer_callback_t callback, void *userData)
 Initializes the FlexIO SPI Master handle, which is used in transactional functions. More...
 
status_t FLEXIO_SPI_MasterTransferNonBlocking (FLEXIO_SPI_Type *base, flexio_spi_master_handle_t *handle, flexio_spi_transfer_t *xfer)
 Master transfer data using IRQ. More...
 
void FLEXIO_SPI_MasterTransferAbort (FLEXIO_SPI_Type *base, flexio_spi_master_handle_t *handle)
 Aborts the master data transfer, which used IRQ. More...
 
status_t FLEXIO_SPI_MasterTransferGetCount (FLEXIO_SPI_Type *base, flexio_spi_master_handle_t *handle, size_t *count)
 Gets the data transfer status which used IRQ. More...
 
void FLEXIO_SPI_MasterTransferHandleIRQ (void *spiType, void *spiHandle)
 FlexIO SPI master IRQ handler function. More...
 
status_t FLEXIO_SPI_SlaveTransferCreateHandle (FLEXIO_SPI_Type *base, flexio_spi_slave_handle_t *handle, flexio_spi_slave_transfer_callback_t callback, void *userData)
 Initializes the FlexIO SPI Slave handle, which is used in transactional functions. More...
 
status_t FLEXIO_SPI_SlaveTransferNonBlocking (FLEXIO_SPI_Type *base, flexio_spi_slave_handle_t *handle, flexio_spi_transfer_t *xfer)
 Slave transfer data using IRQ. More...
 
static void FLEXIO_SPI_SlaveTransferAbort (FLEXIO_SPI_Type *base, flexio_spi_slave_handle_t *handle)
 Aborts the slave data transfer which used IRQ, share same API with master. More...
 
static status_t FLEXIO_SPI_SlaveTransferGetCount (FLEXIO_SPI_Type *base, flexio_spi_slave_handle_t *handle, size_t *count)
 Gets the data transfer status which used IRQ, share same API with master. More...
 
void FLEXIO_SPI_SlaveTransferHandleIRQ (void *spiType, void *spiHandle)
 FlexIO SPI slave IRQ handler function. More...
 

Data Structure Documentation

struct FLEXIO_SPI_Type

Data Fields

FLEXIO_Type * flexioBase
 FlexIO base pointer. More...
 
uint8_t SDOPinIndex
 Pin select for data output. More...
 
uint8_t SDIPinIndex
 Pin select for data input. More...
 
uint8_t SCKPinIndex
 Pin select for clock. More...
 
uint8_t CSnPinIndex
 Pin select for enable. More...
 
uint8_t shifterIndex [2]
 Shifter index used in FlexIO SPI. More...
 
uint8_t timerIndex [2]
 Timer index used in FlexIO SPI. More...
 

Field Documentation

FLEXIO_Type* FLEXIO_SPI_Type::flexioBase
uint8_t FLEXIO_SPI_Type::SDOPinIndex
uint8_t FLEXIO_SPI_Type::SDIPinIndex
uint8_t FLEXIO_SPI_Type::SCKPinIndex
uint8_t FLEXIO_SPI_Type::CSnPinIndex
uint8_t FLEXIO_SPI_Type::shifterIndex[2]
uint8_t FLEXIO_SPI_Type::timerIndex[2]
struct flexio_spi_master_config_t

Data Fields

bool enableMaster
 Enable/disable FlexIO SPI master after configuration. More...
 
bool enableInDoze
 Enable/disable FlexIO operation in doze mode. More...
 
bool enableInDebug
 Enable/disable FlexIO operation in debug mode. More...
 
bool enableFastAccess
 
 Enable/disable fast access to FlexIO registers,

fast access requires the FlexIO clock to be at least twice the frequency of the bus clock. More...

 
uint32_t baudRate_Bps
 Baud rate in Bps. More...
 
flexio_spi_clock_phase_t phase
 Clock phase. More...
 
flexio_spi_data_bitcount_mode_t dataMode
 8bit or 16bit mode. More...
 

Field Documentation

bool flexio_spi_master_config_t::enableMaster
bool flexio_spi_master_config_t::enableInDoze
bool flexio_spi_master_config_t::enableInDebug
bool flexio_spi_master_config_t::enableFastAccess
uint32_t flexio_spi_master_config_t::baudRate_Bps
flexio_spi_clock_phase_t flexio_spi_master_config_t::phase
flexio_spi_data_bitcount_mode_t flexio_spi_master_config_t::dataMode
struct flexio_spi_slave_config_t

Data Fields

bool enableSlave
 Enable/disable FlexIO SPI slave after configuration. More...
 
bool enableInDoze
 Enable/disable FlexIO operation in doze mode. More...
 
bool enableInDebug
 Enable/disable FlexIO operation in debug mode. More...
 
bool enableFastAccess
 
 Enable/disable fast access to FlexIO registers,

fast access requires the FlexIO clock to be at least twice the frequency of the bus clock. More...

 
flexio_spi_clock_phase_t phase
 Clock phase. More...
 
flexio_spi_data_bitcount_mode_t dataMode
 8bit or 16bit mode. More...
 

Field Documentation

bool flexio_spi_slave_config_t::enableSlave
bool flexio_spi_slave_config_t::enableInDoze
bool flexio_spi_slave_config_t::enableInDebug
bool flexio_spi_slave_config_t::enableFastAccess
flexio_spi_clock_phase_t flexio_spi_slave_config_t::phase
flexio_spi_data_bitcount_mode_t flexio_spi_slave_config_t::dataMode
struct flexio_spi_transfer_t

Data Fields

uint8_t * txData
 Send buffer. More...
 
uint8_t * rxData
 Receive buffer. More...
 
size_t dataSize
 Transfer bytes. More...
 
uint8_t flags
 FlexIO SPI control flag, MSB first or LSB first. More...
 

Field Documentation

uint8_t* flexio_spi_transfer_t::txData
uint8_t* flexio_spi_transfer_t::rxData
size_t flexio_spi_transfer_t::dataSize
uint8_t flexio_spi_transfer_t::flags
struct _flexio_spi_master_handle

typedef for flexio_spi_master_handle_t in advance.

Data Fields

uint8_t * txData
 Transfer buffer. More...
 
uint8_t * rxData
 Receive buffer. More...
 
size_t transferSize
 Total bytes to be transferred. More...
 
volatile size_t txRemainingBytes
 Send data remaining in bytes. More...
 
volatile size_t rxRemainingBytes
 Receive data remaining in bytes. More...
 
volatile uint32_t state
 FlexIO SPI internal state. More...
 
uint8_t bytePerFrame
 SPI mode, 2bytes or 1byte in a frame.
 
flexio_spi_shift_direction_t direction
 Shift direction. More...
 
flexio_spi_master_transfer_callback_t callback
 FlexIO SPI callback. More...
 
void * userData
 Callback parameter. More...
 

Field Documentation

uint8_t* flexio_spi_master_handle_t::txData
uint8_t* flexio_spi_master_handle_t::rxData
size_t flexio_spi_master_handle_t::transferSize
volatile size_t flexio_spi_master_handle_t::txRemainingBytes
volatile size_t flexio_spi_master_handle_t::rxRemainingBytes
volatile uint32_t flexio_spi_master_handle_t::state
flexio_spi_shift_direction_t flexio_spi_master_handle_t::direction
flexio_spi_master_transfer_callback_t flexio_spi_master_handle_t::callback
void* flexio_spi_master_handle_t::userData

Macro Definition Documentation

#define FSL_FLEXIO_SPI_DRIVER_VERSION   (MAKE_VERSION(2, 2, 0))
#define FLEXIO_SPI_DUMMYDATA   (0xFFFFU)
#define SPI_RETRY_TIMES   0U /* Define to zero means keep waiting until the flag is assert/deassert. */

Typedef Documentation

typedef flexio_spi_master_handle_t flexio_spi_slave_handle_t

Enumeration Type Documentation

anonymous enum
Enumerator
kStatus_FLEXIO_SPI_Busy 

FlexIO SPI is busy.

kStatus_FLEXIO_SPI_Idle 

SPI is idle.

kStatus_FLEXIO_SPI_Error 

FlexIO SPI error.

kStatus_FLEXIO_SPI_Timeout 

FlexIO SPI timeout polling status flags.

Enumerator
kFLEXIO_SPI_ClockPhaseFirstEdge 

First edge on SPSCK occurs at the middle of the first cycle of a data transfer.

kFLEXIO_SPI_ClockPhaseSecondEdge 

First edge on SPSCK occurs at the start of the first cycle of a data transfer.

Enumerator
kFLEXIO_SPI_MsbFirst 

Data transfers start with most significant bit.

kFLEXIO_SPI_LsbFirst 

Data transfers start with least significant bit.

Enumerator
kFLEXIO_SPI_8BitMode 

8-bit data transmission mode.

kFLEXIO_SPI_16BitMode 

16-bit data transmission mode.

Enumerator
kFLEXIO_SPI_TxEmptyInterruptEnable 

Transmit buffer empty interrupt enable.

kFLEXIO_SPI_RxFullInterruptEnable 

Receive buffer full interrupt enable.

Enumerator
kFLEXIO_SPI_TxBufferEmptyFlag 

Transmit buffer empty flag.

kFLEXIO_SPI_RxBufferFullFlag 

Receive buffer full flag.

Enumerator
kFLEXIO_SPI_TxDmaEnable 

Tx DMA request source.

kFLEXIO_SPI_RxDmaEnable 

Rx DMA request source.

kFLEXIO_SPI_DmaAllEnable 

All DMA request source.

Enumerator
kFLEXIO_SPI_8bitMsb 

FlexIO SPI 8-bit MSB first.

kFLEXIO_SPI_8bitLsb 

FlexIO SPI 8-bit LSB first.

kFLEXIO_SPI_16bitMsb 

FlexIO SPI 16-bit MSB first.

kFLEXIO_SPI_16bitLsb 

FlexIO SPI 16-bit LSB first.

Function Documentation

void FLEXIO_SPI_MasterInit ( FLEXIO_SPI_Type base,
flexio_spi_master_config_t masterConfig,
uint32_t  srcClock_Hz 
)

The configuration structure can be filled by the user, or be set with default values by the FLEXIO_SPI_MasterGetDefaultConfig().

Note
1.FlexIO SPI master only support CPOL = 0, which means clock inactive low. 2.For FlexIO SPI master, the input valid time is 1.5 clock cycles, for slave the output valid time is 2.5 clock cycles. So if FlexIO SPI master communicates with other spi IPs, the maximum baud rate is FlexIO clock frequency divided by 2*2=4. If FlexIO SPI master communicates with FlexIO SPI slave, the maximum baud rate is FlexIO clock frequency divided by (1.5+2.5)*2=8.

Example

FLEXIO_SPI_Type spiDev = {
.flexioBase = FLEXIO,
.SDOPinIndex = 0,
.SDIPinIndex = 1,
.SCKPinIndex = 2,
.CSnPinIndex = 3,
.shifterIndex = {0,1},
.timerIndex = {0,1}
};
.enableMaster = true,
.enableInDoze = false,
.enableInDebug = true,
.enableFastAccess = false,
.baudRate_Bps = 500000,
.direction = kFLEXIO_SPI_MsbFirst,
};
FLEXIO_SPI_MasterInit(&spiDev, &config, srcClock_Hz);
Parameters
basePointer to the FLEXIO_SPI_Type structure.
masterConfigPointer to the flexio_spi_master_config_t structure.
srcClock_HzFlexIO source clock in Hz.
void FLEXIO_SPI_MasterDeinit ( FLEXIO_SPI_Type base)
Parameters
basePointer to the FLEXIO_SPI_Type.
void FLEXIO_SPI_MasterGetDefaultConfig ( flexio_spi_master_config_t masterConfig)

The configuration can be used directly by calling the FLEXIO_SPI_MasterConfigure(). Example:

Parameters
masterConfigPointer to the flexio_spi_master_config_t structure.
void FLEXIO_SPI_SlaveInit ( FLEXIO_SPI_Type base,
flexio_spi_slave_config_t slaveConfig 
)

The configuration structure can be filled by the user, or be set with default values by the FLEXIO_SPI_SlaveGetDefaultConfig().

Note
1.Only one timer is needed in the FlexIO SPI slave. As a result, the second timer index is ignored. 2.FlexIO SPI slave only support CPOL = 0, which means clock inactive low. 3.For FlexIO SPI master, the input valid time is 1.5 clock cycles, for slave the output valid time is 2.5 clock cycles. So if FlexIO SPI slave communicates with other spi IPs, the maximum baud rate is FlexIO clock frequency divided by 3*2=6. If FlexIO SPI slave communicates with FlexIO SPI master, the maximum baud rate is FlexIO clock frequency divided by (1.5+2.5)*2=8. Example
FLEXIO_SPI_Type spiDev = {
.flexioBase = FLEXIO,
.SDOPinIndex = 0,
.SDIPinIndex = 1,
.SCKPinIndex = 2,
.CSnPinIndex = 3,
.shifterIndex = {0,1},
.timerIndex = {0}
};
.enableSlave = true,
.enableInDoze = false,
.enableInDebug = true,
.enableFastAccess = false,
.direction = kFLEXIO_SPI_MsbFirst,
};
FLEXIO_SPI_SlaveInit(&spiDev, &config);
Parameters
basePointer to the FLEXIO_SPI_Type structure.
slaveConfigPointer to the flexio_spi_slave_config_t structure.
void FLEXIO_SPI_SlaveDeinit ( FLEXIO_SPI_Type base)
Parameters
basePointer to the FLEXIO_SPI_Type.
void FLEXIO_SPI_SlaveGetDefaultConfig ( flexio_spi_slave_config_t slaveConfig)

The configuration can be used directly for calling the FLEXIO_SPI_SlaveConfigure(). Example:

Parameters
slaveConfigPointer to the flexio_spi_slave_config_t structure.
uint32_t FLEXIO_SPI_GetStatusFlags ( FLEXIO_SPI_Type base)
Parameters
basePointer to the FLEXIO_SPI_Type structure.
Returns
status flag; Use the status flag to AND the following flag mask and get the status.
  • kFLEXIO_SPI_TxEmptyFlag
  • kFLEXIO_SPI_RxEmptyFlag
void FLEXIO_SPI_ClearStatusFlags ( FLEXIO_SPI_Type base,
uint32_t  mask 
)
Parameters
basePointer to the FLEXIO_SPI_Type structure.
maskstatus flag The parameter can be any combination of the following values:
  • kFLEXIO_SPI_TxEmptyFlag
  • kFLEXIO_SPI_RxEmptyFlag
void FLEXIO_SPI_EnableInterrupts ( FLEXIO_SPI_Type base,
uint32_t  mask 
)

This function enables the FlexIO SPI interrupt.

Parameters
basePointer to the FLEXIO_SPI_Type structure.
maskinterrupt source. The parameter can be any combination of the following values:
  • kFLEXIO_SPI_RxFullInterruptEnable
  • kFLEXIO_SPI_TxEmptyInterruptEnable
void FLEXIO_SPI_DisableInterrupts ( FLEXIO_SPI_Type base,
uint32_t  mask 
)

This function disables the FlexIO SPI interrupt.

Parameters
basePointer to the FLEXIO_SPI_Type structure.
maskinterrupt source The parameter can be any combination of the following values:
  • kFLEXIO_SPI_RxFullInterruptEnable
  • kFLEXIO_SPI_TxEmptyInterruptEnable
void FLEXIO_SPI_EnableDMA ( FLEXIO_SPI_Type base,
uint32_t  mask,
bool  enable 
)

This function enables/disables the FlexIO SPI Tx DMA, which means that asserting the kFLEXIO_SPI_TxEmptyFlag does/doesn't trigger the DMA request.

Parameters
basePointer to the FLEXIO_SPI_Type structure.
maskSPI DMA source.
enableTrue means enable DMA, false means disable DMA.
static uint32_t FLEXIO_SPI_GetTxDataRegisterAddress ( FLEXIO_SPI_Type base,
flexio_spi_shift_direction_t  direction 
)
inlinestatic

This function returns the SPI data register address, which is mainly used by DMA/eDMA.

Parameters
basePointer to the FLEXIO_SPI_Type structure.
directionShift direction of MSB first or LSB first.
Returns
FlexIO SPI transmit data register address.
static uint32_t FLEXIO_SPI_GetRxDataRegisterAddress ( FLEXIO_SPI_Type base,
flexio_spi_shift_direction_t  direction 
)
inlinestatic

This function returns the SPI data register address, which is mainly used by DMA/eDMA.

Parameters
basePointer to the FLEXIO_SPI_Type structure.
directionShift direction of MSB first or LSB first.
Returns
FlexIO SPI receive data register address.
static void FLEXIO_SPI_Enable ( FLEXIO_SPI_Type base,
bool  enable 
)
inlinestatic
Parameters
basePointer to the FLEXIO_SPI_Type.
enableTrue to enable, false does not have any effect.
void FLEXIO_SPI_MasterSetBaudRate ( FLEXIO_SPI_Type base,
uint32_t  baudRate_Bps,
uint32_t  srcClockHz 
)
Parameters
basePointer to the FLEXIO_SPI_Type structure.
baudRate_BpsBaud Rate needed in Hz.
srcClockHzSPI source clock frequency in Hz.
static void FLEXIO_SPI_WriteData ( FLEXIO_SPI_Type base,
flexio_spi_shift_direction_t  direction,
uint16_t  data 
)
inlinestatic
Note
This is a non-blocking API, which returns directly after the data is put into the data register but the data transfer is not finished on the bus. Ensure that the TxEmptyFlag is asserted before calling this API.
Parameters
basePointer to the FLEXIO_SPI_Type structure.
directionShift direction of MSB first or LSB first.
data8 bit/16 bit data.
static uint16_t FLEXIO_SPI_ReadData ( FLEXIO_SPI_Type base,
flexio_spi_shift_direction_t  direction 
)
inlinestatic
Note
This is a non-blocking API, which returns directly after the data is read from the data register. Ensure that the RxFullFlag is asserted before calling this API.
Parameters
basePointer to the FLEXIO_SPI_Type structure.
directionShift direction of MSB first or LSB first.
Returns
8 bit/16 bit data received.
status_t FLEXIO_SPI_WriteBlocking ( FLEXIO_SPI_Type base,
flexio_spi_shift_direction_t  direction,
const uint8_t *  buffer,
size_t  size 
)
Note
This function blocks using the polling method until all bytes have been sent.
Parameters
basePointer to the FLEXIO_SPI_Type structure.
directionShift direction of MSB first or LSB first.
bufferThe data bytes to send.
sizeThe number of data bytes to send.
Return values
kStatus_SuccessSuccessfully create the handle.
kStatus_FLEXIO_SPI_TimeoutThe transfer timed out and was aborted.
status_t FLEXIO_SPI_ReadBlocking ( FLEXIO_SPI_Type base,
flexio_spi_shift_direction_t  direction,
uint8_t *  buffer,
size_t  size 
)
Note
This function blocks using the polling method until all bytes have been received.
Parameters
basePointer to the FLEXIO_SPI_Type structure.
directionShift direction of MSB first or LSB first.
bufferThe buffer to store the received bytes.
sizeThe number of data bytes to be received.
directionShift direction of MSB first or LSB first.
Return values
kStatus_SuccessSuccessfully create the handle.
kStatus_FLEXIO_SPI_TimeoutThe transfer timed out and was aborted.
status_t FLEXIO_SPI_MasterTransferBlocking ( FLEXIO_SPI_Type base,
flexio_spi_transfer_t xfer 
)
Note
This function blocks via polling until all bytes have been received.
Parameters
basepointer to FLEXIO_SPI_Type structure
xferFlexIO SPI transfer structure, see flexio_spi_transfer_t.
Return values
kStatus_SuccessSuccessfully create the handle.
kStatus_FLEXIO_SPI_TimeoutThe transfer timed out and was aborted.
status_t FLEXIO_SPI_MasterTransferCreateHandle ( FLEXIO_SPI_Type base,
flexio_spi_master_handle_t *  handle,
flexio_spi_master_transfer_callback_t  callback,
void *  userData 
)
Parameters
basePointer to the FLEXIO_SPI_Type structure.
handlePointer to the flexio_spi_master_handle_t structure to store the transfer state.
callbackThe callback function.
userDataThe parameter of the callback function.
Return values
kStatus_SuccessSuccessfully create the handle.
kStatus_OutOfRangeThe FlexIO type/handle/ISR table out of range.
status_t FLEXIO_SPI_MasterTransferNonBlocking ( FLEXIO_SPI_Type base,
flexio_spi_master_handle_t *  handle,
flexio_spi_transfer_t xfer 
)

This function sends data using IRQ. This is a non-blocking function, which returns right away. When all data is sent out/received, the callback function is called.

Parameters
basePointer to the FLEXIO_SPI_Type structure.
handlePointer to the flexio_spi_master_handle_t structure to store the transfer state.
xferFlexIO SPI transfer structure. See flexio_spi_transfer_t.
Return values
kStatus_SuccessSuccessfully start a transfer.
kStatus_InvalidArgumentInput argument is invalid.
kStatus_FLEXIO_SPI_BusySPI is not idle, is running another transfer.
void FLEXIO_SPI_MasterTransferAbort ( FLEXIO_SPI_Type base,
flexio_spi_master_handle_t *  handle 
)
Parameters
basePointer to the FLEXIO_SPI_Type structure.
handlePointer to the flexio_spi_master_handle_t structure to store the transfer state.
status_t FLEXIO_SPI_MasterTransferGetCount ( FLEXIO_SPI_Type base,
flexio_spi_master_handle_t *  handle,
size_t *  count 
)
Parameters
basePointer to the FLEXIO_SPI_Type structure.
handlePointer to the flexio_spi_master_handle_t structure to store the transfer state.
countNumber of bytes transferred so far by the non-blocking transaction.
Return values
kStatus_InvalidArgumentcount is Invalid.
kStatus_SuccessSuccessfully return the count.
void FLEXIO_SPI_MasterTransferHandleIRQ ( void *  spiType,
void *  spiHandle 
)
Parameters
spiTypePointer to the FLEXIO_SPI_Type structure.
spiHandlePointer to the flexio_spi_master_handle_t structure to store the transfer state.
status_t FLEXIO_SPI_SlaveTransferCreateHandle ( FLEXIO_SPI_Type base,
flexio_spi_slave_handle_t handle,
flexio_spi_slave_transfer_callback_t  callback,
void *  userData 
)
Parameters
basePointer to the FLEXIO_SPI_Type structure.
handlePointer to the flexio_spi_slave_handle_t structure to store the transfer state.
callbackThe callback function.
userDataThe parameter of the callback function.
Return values
kStatus_SuccessSuccessfully create the handle.
kStatus_OutOfRangeThe FlexIO type/handle/ISR table out of range.
status_t FLEXIO_SPI_SlaveTransferNonBlocking ( FLEXIO_SPI_Type base,
flexio_spi_slave_handle_t handle,
flexio_spi_transfer_t xfer 
)

This function sends data using IRQ. This is a non-blocking function, which returns right away. When all data is sent out/received, the callback function is called.

Parameters
handlePointer to the flexio_spi_slave_handle_t structure to store the transfer state.
basePointer to the FLEXIO_SPI_Type structure.
xferFlexIO SPI transfer structure. See flexio_spi_transfer_t.
Return values
kStatus_SuccessSuccessfully start a transfer.
kStatus_InvalidArgumentInput argument is invalid.
kStatus_FLEXIO_SPI_BusySPI is not idle; it is running another transfer.
static void FLEXIO_SPI_SlaveTransferAbort ( FLEXIO_SPI_Type base,
flexio_spi_slave_handle_t handle 
)
inlinestatic
Parameters
basePointer to the FLEXIO_SPI_Type structure.
handlePointer to the flexio_spi_slave_handle_t structure to store the transfer state.
static status_t FLEXIO_SPI_SlaveTransferGetCount ( FLEXIO_SPI_Type base,
flexio_spi_slave_handle_t handle,
size_t *  count 
)
inlinestatic
Parameters
basePointer to the FLEXIO_SPI_Type structure.
handlePointer to the flexio_spi_slave_handle_t structure to store the transfer state.
countNumber of bytes transferred so far by the non-blocking transaction.
Return values
kStatus_InvalidArgumentcount is Invalid.
kStatus_SuccessSuccessfully return the count.
void FLEXIO_SPI_SlaveTransferHandleIRQ ( void *  spiType,
void *  spiHandle 
)
Parameters
spiTypePointer to the FLEXIO_SPI_Type structure.
spiHandlePointer to the flexio_spi_slave_handle_t structure to store the transfer state.