All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
FlexIO SPI Driver
FlexIO: FlexIO Driver

## Overview

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

FlexIO SPI driver includes functional APIs and transactional APIs.

Functional APIs are feature/property 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 are transaction 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. Notice that FlexIO SPI slave driver only supports discontinuous PCS access, which is a limitation. The FlexIO SPI slave driver could support continuous PCS, but the slave can't adapt discontinuous and continuous PCS automatically. User can change the timer disable mode in FLEXIO_SPI_SlaveInit manually, from kFLEXIO_TimerDisableOnTimerCompare to kFLEXIO_TimerDisableNever to enable 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;
FLEXIO_SPI_Type spiDev;
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)
{
//...
flexio_spi_transfer_t xfer = {0};
flexio_spi_master_config_t userConfig;
FLEXIO_SPI_MasterGetDefaultConfig(&userConfig);
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;
xfer.flags = kFLEXIO_SPI_8bitMsb;
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 using a DMA method

dma_handle_t g_spiTxDmaHandle;
dma_handle_t g_spiRxDmaHandle;
flexio_spi_master_handle_t g_spiHandle;
FLEXIO_SPI_Type spiDev;
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)
{
flexio_spi_transfer_t xfer = {0};
flexio_spi_master_config_t userConfig;
FLEXIO_SPI_MasterGetDefaultConfig(&userConfig);
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;
/*Initializes the DMA for the example.*/
DMAMGR_Init();
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. */
DMAMGR_RequestChannel((dma_request_source_t)dma_request_source_tx, 0, &txHandle);
DMAMGR_RequestChannel((dma_request_source_t)dma_request_source_rx, 1, &rxHandle);
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;
xfer.flags = kFLEXIO_SPI_8bitMsb;
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)
{
}
// ...
}

## Modules

| FlexIO DMA SPI Driver
| FlexIO eDMA SPI Driver

## 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...

## 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 | _flexio_spi_status { 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) }
| 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, 1, 0))
| FlexIO SPI driver version 2.1.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 and 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)
| Gates the FlexIO clock. 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...
void | 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...
void | 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...
void | 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, 1, 0))

#define FLEXIO_SPI_DUMMYDATA (0xFFFFU)

## Typedef Documentation

typedef flexio_spi_master_handle_t flexio_spi_slave_handle_t

## Enumeration Type Documentation

enum _flexio_spi_status

Enumerator
kStatus_FLEXIO_SPI_Busy | FlexIO SPI is busy.
kStatus_FLEXIO_SPI_Idle | SPI is idle.
kStatus_FLEXIO_SPI_Error | FlexIO SPI error.

enum flexio_spi_clock_phase_t

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.

enum flexio_spi_shift_direction_t

Enumerator
kFLEXIO_SPI_MsbFirst | Data transfers start with most significant bit.
kFLEXIO_SPI_LsbFirst | Data transfers start with least significant bit.

enum flexio_spi_data_bitcount_mode_t

Enumerator
kFLEXIO_SPI_8BitMode | 8-bit data transmission mode.
kFLEXIO_SPI_16BitMode | 16-bit data transmission mode.

enum _flexio_spi_interrupt_enable

Enumerator
kFLEXIO_SPI_TxEmptyInterruptEnable | Transmit buffer empty interrupt enable.
kFLEXIO_SPI_RxFullInterruptEnable | Receive buffer full interrupt enable.

enum _flexio_spi_status_flags

Enumerator
kFLEXIO_SPI_TxBufferEmptyFlag | Transmit buffer empty flag.
kFLEXIO_SPI_RxBufferFullFlag | Receive buffer full flag.

enum _flexio_spi_dma_enable

Enumerator
kFLEXIO_SPI_TxDmaEnable | Tx DMA request source.
kFLEXIO_SPI_RxDmaEnable | Rx DMA request source.
kFLEXIO_SPI_DmaAllEnable | All DMA request source.

enum _flexio_spi_transfer_flags

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
  FlexIO SPI master only support CPOL = 0, which means clock inactive low.

Example

FLEXIO_SPI_Type spiDev = {
.flexioBase = FLEXIO,
.SDOPinIndex = 0,
.SDIPinIndex = 1,
.SCKPinIndex = 2,
.CSnPinIndex = 3,
.shifterIndex = {0,1},
.timerIndex = {0,1}
};
flexio_spi_master_config_t config = {
.enableMaster = true,
.enableInDoze = false,
.enableInDebug = true,
.enableFastAccess = false,
.baudRate_Bps = 500000,
.phase = kFLEXIO_SPI_ClockPhaseFirstEdge,
.direction = kFLEXIO_SPI_MsbFirst,
.dataMode = kFLEXIO_SPI_8BitMode
};
FLEXIO_SPI_MasterInit(&spiDev, &config, srcClock_Hz);

Parameters

  base | Pointer to the FLEXIO_SPI_Type structure.
  masterConfig | Pointer to the flexio_spi_master_config_t structure.
  srcClock_Hz | FlexIO source clock in Hz.

void FLEXIO_SPI_MasterDeinit | ( | FLEXIO_SPI_Type * | base | ) |

Parameters

  base | Pointer 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:

flexio_spi_master_config_t masterConfig;
FLEXIO_SPI_MasterGetDefaultConfig(&masterConfig);

Parameters

  masterConfig | Pointer 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
  Only one timer is needed in the FlexIO SPI slave. As a result, the second timer index is ignored. FlexIO SPI slave only support CPOL = 0, which means clock inactive low. Example
  FLEXIO_SPI_Type spiDev = {
  .flexioBase = FLEXIO,
  .SDOPinIndex = 0,
  .SDIPinIndex = 1,
  .SCKPinIndex = 2,
  .CSnPinIndex = 3,
  .shifterIndex = {0,1},
  .timerIndex = {0}
  };
  flexio_spi_slave_config_t config = {
  .enableSlave = true,
  .enableInDoze = false,
  .enableInDebug = true,
  .enableFastAccess = false,
  .phase = kFLEXIO_SPI_ClockPhaseFirstEdge,
  .direction = kFLEXIO_SPI_MsbFirst,
  .dataMode = kFLEXIO_SPI_8BitMode
  };
  FLEXIO_SPI_SlaveInit(&spiDev, &config);

Parameters

  base | Pointer to the FLEXIO_SPI_Type structure.
  slaveConfig | Pointer to the flexio_spi_slave_config_t structure.

void FLEXIO_SPI_SlaveDeinit | ( | FLEXIO_SPI_Type * | base | ) |

Parameters

  base | Pointer 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:

flexio_spi_slave_config_t slaveConfig;
FLEXIO_SPI_SlaveGetDefaultConfig(&slaveConfig);

Parameters

  slaveConfig | Pointer to the flexio_spi_slave_config_t structure.

uint32_t FLEXIO_SPI_GetStatusFlags | ( | FLEXIO_SPI_Type * | base | ) |

Parameters

  base | Pointer 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

  base | Pointer to the FLEXIO_SPI_Type structure.

  mask

  status 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

  base | Pointer to the FLEXIO_SPI_Type structure.

  mask

  interrupt 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

  base | Pointer to the FLEXIO_SPI_Type structure.

  mask

  interrupt 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  mask | SPI DMA source.
  enable | True 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  direction | Shift 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  direction | Shift 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

  base | Pointer to the FLEXIO_SPI_Type.
  enable | True to enable, false to disable.

void FLEXIO_SPI_MasterSetBaudRate | ( | FLEXIO_SPI_Type * | base,
|  | uint32_t | baudRate_Bps,
|  | uint32_t | srcClockHz
| ) |  |

Parameters

  base | Pointer to the FLEXIO_SPI_Type structure.
  baudRate_Bps | Baud Rate needed in Hz.
  srcClockHz | SPI 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  direction | Shift direction of MSB first or LSB first.
  data | 8 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  direction | Shift direction of MSB first or LSB first.

Returns
  8 bit/16 bit data received.

void 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  direction | Shift direction of MSB first or LSB first.
  buffer | The data bytes to send.
  size | The number of data bytes to send.

void 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  direction | Shift direction of MSB first or LSB first.
  buffer | The buffer to store the received bytes.
  size | The number of data bytes to be received.
  direction | Shift direction of MSB first or LSB first.

void 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

  base | pointer to FLEXIO_SPI_Type structure
  xfer | FlexIO SPI transfer structure, see flexio_spi_transfer_t.

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

  base | Pointer to the FLEXIO_SPI_Type structure.
  handle | Pointer to the flexio_spi_master_handle_t structure to store the transfer state.
  callback | The callback function.
  userData | The parameter of the callback function.

Return values

  kStatus_Success | Successfully create the handle.
  kStatus_OutOfRange | The 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  handle | Pointer to the flexio_spi_master_handle_t structure to store the transfer state.
  xfer | FlexIO SPI transfer structure. See flexio_spi_transfer_t.

Return values

  kStatus_Success | Successfully start a transfer.
  kStatus_InvalidArgument | Input argument is invalid.
  kStatus_FLEXIO_SPI_Busy | SPI is not idle, is running another transfer.

void FLEXIO_SPI_MasterTransferAbort | ( | FLEXIO_SPI_Type * | base,
|  | flexio_spi_master_handle_t * | handle
| ) |  |

Parameters

  base | Pointer to the FLEXIO_SPI_Type structure.
  handle | Pointer 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  handle | Pointer to the flexio_spi_master_handle_t structure to store the transfer state.
  count | Number of bytes transferred so far by the non-blocking transaction.

Return values

  kStatus_InvalidArgument | count is Invalid.
  kStatus_Success | Successfully return the count.

void FLEXIO_SPI_MasterTransferHandleIRQ | ( | void * | spiType,
|  | void * | spiHandle
| ) |  |

Parameters

  spiType | Pointer to the FLEXIO_SPI_Type structure.
  spiHandle | Pointer 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  handle | Pointer to the flexio_spi_slave_handle_t structure to store the transfer state.
  callback | The callback function.
  userData | The parameter of the callback function.

Return values

  kStatus_Success | Successfully create the handle.
  kStatus_OutOfRange | The 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

  handle | Pointer to the flexio_spi_slave_handle_t structure to store the transfer state.
  base | Pointer to the FLEXIO_SPI_Type structure.
  xfer | FlexIO SPI transfer structure. See flexio_spi_transfer_t.

Return values

  kStatus_Success | Successfully start a transfer.
  kStatus_InvalidArgument | Input argument is invalid.
  kStatus_FLEXIO_SPI_Busy | SPI 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  handle | Pointer 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

  base | Pointer to the FLEXIO_SPI_Type structure.
  handle | Pointer to the flexio_spi_slave_handle_t structure to store the transfer state.
  count | Number of bytes transferred so far by the non-blocking transaction.

Return values

  kStatus_InvalidArgument | count is Invalid.
  kStatus_Success | Successfully return the count.

void FLEXIO_SPI_SlaveTransferHandleIRQ | ( | void * | spiType,
|  | void * | spiHandle
| ) |  |

Parameters

  spiType | Pointer to the FLEXIO_SPI_Type structure.
  spiHandle | Pointer to the flexio_spi_slave_handle_t structure to store the transfer state.