Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the DSPI master mode peripheral driver. The DSPI master mode peripheral driver transfers data to and from external devices on the DSPI bus in master mode. It supports transferring data buffers with a single function call.

DSPI Introduction

The driver is separated into two implementations: interrupt-driven and DMA-driven. The interrupt-driven driver uses interrupts to alert the CPU that the DSPI module needs to service the SPI data transmit and receive operations. The enhanced DMA (eDMA)-driven driver uses the eDMA module to transfer data between the buffers located in memory and the DSPI module transmit/receive buffers/FIFOs. In the subsequent sections the enhanced DMA-driven driver is referred to as the DMA-driven driver. The interrupt-driven and DMA-driven driver APIs are distinguished with the keyword "edma" in the source file name and by the keyword "Edma" in the API name. Each set of drivers have the same API functionality and are described in the following sections. Note that the DMA driven driver also uses interrupts to alert the CPU that the DMA has completed its transfer or that one final piece of data still needs to be received which is handled by the IRQ handler in the DMA driven driver. In both the interrupt and DMA drivers, the SPI module interrupts are enabled in the NVIC. In addition, the DMA driven-driver requests channels from the eDMA module. Also, these sections refer to either set of drivers as the "DSPI master driver" when discussing items that pertain to either driver. Note, when using the DMA driven DSPI driver, initialize the eDMA module. An example is shown in the Initialization section.

This is a step-by-step process to initialize and transfer the SPI data. For API specific examples, see the examples below. The example uses the interrupt-driven APIs and a blocking transfer to illustrate a high-level step-by-step usage. The usage of eDMA driver is similar to the interrupt-driven driver. Keep in mind that using interrupt and eDMA drivers in the same runtime application is not recommended because the SPI interrupt handler needs to be changed. The interrupt driver calls the DSPI_DRV_IRQHandler() function and the eDMA driver calls the DSPI_DRV_EdmaIRQHandler() function. See files fsl_dspi_irq.c and fsl_dspi_edma_irq.c for an example of these function calls.

// Initializes the DSPI
DSPI_DRV_MasterInit(masterInstance, &dspiMasterState, &userConfig);
// Configure the SPI bus
DSPI_DRV_MasterConfigureBus(masterInstance, &spiDevice, &calculatedBaudRate);
// Optional; Normally the user does not need to adjust delays, but depends on the slave device:
DSPI_DRV_MasterSetDelay(masterInstance, kDspiPcsToSck, delayInNanoSec, &calculatedDelay);
// Perform the transfer
DSPI_DRV_MasterTransferBlocking(masterInstance, NULL, s_dspiSourceBuffer,
s_dspiSinkBuffer, 32, 1000);
// Do other transfers. When done with the DSPI, de-initialize to shut it down.
DSPI_DRV_MasterDeinit(masterInstance);

Note that it is not recommended to mix interrupt and DMA driven drivers in the same application. However, should the user decide to do so, separately set up and initialize another instance for DMA operations. The user can also de-initialize the current interrupt-driven DSPI instance and re-initialize it for DMA operations. Note, that, because the DMA driven driver also uses interrupts, the user must direct the IRQ handler from the vector table to the desired driver's IRQ handler. See files fsl_dspi_irq.c and fsl_dspi_edma_irq.c for examples on how to re-direct the IRQ handlers from the vector table to the interrupt-driven and DMA-driven driver IRQ handlers. Such files need to be included in the application project to direct the DSPI interrupt vectors to the proper IRQ handlers. The fsl_dspi_shared_function.c and fsl_dspi_edma_shared_function.c files direct the interrupts from the vector table to the appropriate master or slave driver interrupt handler by checking the DSPI mode via the HAL function DSPI_HAL_IsMaster(baseAddr). Note that the interrupt driver calls the DSPI_DRV_IRQHandler() function and the eDMA driver calls the DSPI_DRV_EdmaIRQHandler() function. See files fsl_dspi_irq.c and fsl_dspi_edma_irq.c for an example of these function calls.

When using the DSPI driver with the eDMA some DSPI instances do not support separate DMA requests for transmit and receive channels. In those cases with a single shared DMA request for transmit and receive DMA channels, the driver links one channel to the other to still take advantage of DMA transfers. However, the drawback to using an instance with shared DMA requests limits the maximum amount of data the driver can transfer. This limit depends on the bits/frame setting.

For DSPI instances with separate transmit and receive DMA requests, the maximum number of bytes that can be transferred is: 8-bit setting: 32767 bytes 16-bit setting: 65534 bytes

For DSPI instances with a shared transmit and receive DMA request, the maximum number of bytes that can be transferred is: 8-bit setting: 511 bytes 16-bit setting: 1022 bytes

See the microcontroller-specific documentation to see which DSPI instance have separate or shared transmit and receive DMA requests. Additionally, see the microcontroller-specific feature header file to see which DSPI instance have separate or shared transmit and receive DMA requests.

DSPI Run-time state structures

The DSPI master driver uses a run-time state structure to track the ongoing data transfers. The state structure for the interrupt-driven driver is called the dspi_master_state_t. The structure for the DMA driven driver is called the dspi_edma_master_state_t. This structure holds data that the DSPI master peripheral driver uses to communicate between the transfer function and the interrupt handler and other driver functions. The interrupt handler in the interrupt driven also uses this information to keep track of its progress. The user is only required to pass the memory for the run-time state structure. The DSPI master driver populates the members.

DSPI User configuration structures

The DSPI master driver uses instances of the user configuration structure for the DSPI master driver. The user configuration structure for the interrupt-driven driver is called the dspi_master_user_config_t. The user configuration structure for the DMA driven driver is called the dspi_edma_master_user_config_t. This structure allows the user to configure the most common settings of the DSPI peripheral with a single function call. The user configuration structure is passed into the master driver initialization function (DSPI_DRV_MasterInit or DSPI_DRV_EdmaMasterInit). The user configuration structure consists of whichCtar (generally set this to kDspiCtar0), option for continuous clock and peripheral chip select, the desired peripheral chip select to use, and the polarity of the peripheral chip select settings. An example of this is provided in the Initialization section.

DSPI Device structures

The DSPI master driver uses instances of the dspi_device_t or dspi_edma_device_t structure to represent the SPI bus configuration required to communicate to an external device that is connected to the bus.

The device structure can be passed into the DSPI_DRV_MasterConfigureBus or DSPI_DRV_EdmaMasterConfigureBus functions to manually configure the bus for a particular device. For example, if there is only one device connected to the bus, the user might configure it only once. Alternatively, the device structure can be passed to the data transfer functions where the bus is reconfigured before the transfer is started. The device structure consists of bitsPerSec (baud rate in Hz) and the dataBusConfig structure which consists of bits per frame, clock polarity and phase, and data shift direction (MSB or LSB).

DSPI Initialization

To initialize the DSPI master driver, call the DSPI_DRV_MasterInit() or the DSPI_DRV_EdmaMasterInit functions and pass the instance number of the DSPI peripheral, the memory allocation for the run-time state structure used by the master driver to keep track of data transfers, and the user configuration (dspi_master_user_config_t or dspi_edma_master_user_config_t). For the DMA driven driver, the memory allocation for the stcdSrc2CmdDataLast structure needs to be passed. Note that the pointer to this structure needs to be aligned to a 32-byte boundary.

First call the DSPI master initialization to initialize the DSPI module. Then, call the DSPI master configuration bus to configure the module for the specific device on the SPI bus. For the interrupt-driven case, while the DSPI_DRV_MasterInit() function initializes the DSPI peripheral, the DSPI_DRV_MasterConfigureBus() function configures the SPI bus parameters such as bits/frame, clock characteristics, data shift direction, baud rate, and desired chip select. The DMA-driven case follows the same logic, except that it uses the EDMA API names. Both examples are provided below. The interrupt driven example is provided first followed by the DMA example.

This is an example code to initialize and configure the DSPI master interrupt-driven driver including setting up the user configuration and device structures:

// Set up and initialize the master //
uint32_t masterInstance = 1; // example using DSPI instance 1
dspi_master_state_t dspiMasterState; // simply allocate memory for this
uint32_t calculatedBaudRate;
// configure the members of the user configuration //
userConfig.isChipSelectContinuous = false;
userConfig.isSckContinuous = false;
userConfig.whichCtar = kDspiCtar0;
userConfig.whichPcs = kDspiPcs1;
// Initialize the DSPI module //
DSPI_DRV_MasterInit(masterInstance, &dspiMasterState, &userConfig);
// Define the bus configuration
dspi_device_t spiDevice;
spiDevice.dataBusConfig.bitsPerFrame = 16;
spiDevice.dataBusConfig.clkPhase = kDspiClockPhase_FirstEdge;
spiDevice.dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveHigh;
spiDevice.dataBusConfig.direction = kDspiMsbFirst;
spiDevice.bitsPerSec = 500000;
// Configure the SPI bus //
DSPI_DRV_MasterConfigureBus(masterInstance, &spiDevice, &calculatedBaudRate);

This is an example code to initialize and configure the DSPI master DMA-driven driver including setting up the user configuration and device structures:

// Declare 32-byte aligned software transfer control descriptor (eDMA requirement)
// This example uses IAR preprocessor pragma syntax. Other methods also include declaring
// a 64-byte region and then aligning the pointer within that region to a 32-byte boundary,
// but this would waste 32-bytes of memory
#pragma data_alignment=32
edma_software_tcd_t stcdTransferCntTest;
// First, initialize the eDMA peripheral driver.
// NOTE: THIS IS NOT PART OF THE DSPI DRIVER. THIS PART INITIALIZES THE EDMA DRIVER SO
// THAT THE DSPI EDMA DRIVER CAN WORK.
edma_state_t state; // <- The user allocates memory for this structure.
edma_user_config_t edmaUserConfig; // <- The user fills out members for this structure.
edmaUserConfig.notHaltOnError = false;
// Actual EDMA initialization
EDMA_DRV_Init(&state, &edmaUserConfig);
// Set up and initialize the master //
uint32_t masterInstance = 0; // example using DSPI instance 0
dspi_edma_master_state_t dspiMasterState; // simply allocate memory for this
uint32_t calculatedBaudRate;
// Configure the members of the user configuration //
userConfig.isChipSelectContinuous = false;
userConfig.isSckContinuous = false;
userConfig.whichCtar = kDspiCtar0;
userConfig.whichPcs = kDspiPcs1;
// Initialize the DSPI module //
DSPI_DRV_EdmaMasterInit(masterInstance, &dspiMasterState, &userConfig, &stcdTransferCntTest);
// Define the bus configuration
spiDevice.dataBusConfig.bitsPerFrame = 16;
spiDevice.dataBusConfig.clkPhase = kDspiClockPhase_FirstEdge;
spiDevice.dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveHigh;
spiDevice.dataBusConfig.direction = kDspiMsbFirst;
spiDevice.bitsPerSec = 500000;
// Configure the SPI bus //
DSPI_DRV_EdmaMasterConfigureBus(masterInstance, &spiDevice, &calculatedBaudRate);

The DSPI also offers an optional API to configure various bus timing delays. This function involves the DSPI module delay options to "fine tune" some of the signal timings and match the timing needs of a slower peripheral device. This is an optional function that can be called after the DSPI module is initialized for master mode. The bus timing delays that can be adjusted are listed here:

PCS to SCK Delay: Adjustable delay option between the assertion of the PCS signal to the first SCK edge.

After SCK Delay: Adjustable delay option between the last edge of SCK to the de-assertion of the PCS signal.

Delay after Transfer: Adjustable delay option between the de-assertion of the PCS signal for a frame to the assertion of the PCS signal for the next frame. Note that this is not adjustable for continuous clock mode because this delay is fixed at one SCK period.

This function takes in as a parameter the desired delay type and the delay value (in nanoseconds) and calculates the values needed for the prescaler and scaler. Returning the actual calculated delay as an exact delay match may not be possible. In this situation, the closest match is calculated without going below the desired delay value input. It is possible to input a very large delay value that exceeds the capability of the part, in which case the maximum supported delay is returned. In addition, the function returns an out-of-range status.

This is an example that shows how to use the set the bus timings delay function:

uint32_t delayInNanoSec = 200; // example, 200ns
uint32_t calculatedDelay;
// Interrupt example
// kDspiPcsToSck: PCS to SCK Delay option, delayInNanoSec is the user's passed in delay in ns
DSPI_DRV_MasterSetDelay(masterInstance, kDspiPcsToSck, delayInNanoSec, &calculatedDelay);
// eDMA example
// kDspiPcsToSck: PCS to SCK Delay option, delayInNanoSec is the user's passed in delay in ns
DSPI_DRV_EdmaMasterSetDelay(masterInstance, kDspiPcsToSck, delayInNanoSec, &calculatedDelay);

DSPI Transfers

The driver supports two different modes for transferring data: blocking and non-blocking (async). The blocking transfer function waits until the transfer is complete before returning. A timeout parameter is passed into the blocking function. A non-blocking (async) function returns immediately after starting the transfer. The user is required to get the transfer status during the transfer to ascertain when the transfer is complete. Additional functions provided to aid in non-blocking transfers are get transfer status and abort transfer. If there is a cache for memory, when using DMA to transfer data, ensure that the data is consistent. In other words, when reading the data from memory, application should ensure that the data to/from the memory device is current and is not not cached.

Blocking transfer function APIs (interrupt and DMA driven):

const dspi_device_t * restrict device,
const uint8_t * sendBuffer,
uint8_t * receiveBuffer,
size_t transferByteCount,
uint32_t timeout);
const dspi_edma_device_t * restrict device,
const uint8_t * sendBuffer,
uint8_t * receiveBuffer,
size_t transferByteCount,
uint32_t timeout);

Non-blocking function APIs and associated functions (interrupt and DMA-driven):

// Interrupt-driven transfer function
const dspi_device_t * restrict device,
const uint8_t * sendBuffer,
uint8_t * receiveBuffer,
size_t transferByteCount);
// Returns whether the previous transfer is completed (interrupt-driven )
dspi_status_t DSPI_DRV_MasterGetTransferStatus(uint32_t instance, uint32_t * framesTransferred);
// Terminates an asynchronous transfer early (interrupt-driven )
// DMA-driven transfer function
const dspi_edma_device_t * restrict device,
const uint8_t * sendBuffer,
uint8_t * receiveBuffer,
size_t transferByteCount);
// Returns whether the previous transfer is completed (DMA-driven)
dspi_status_t DSPI_DRV_EdmaMasterGetTransferStatus(uint32_t instance, uint32_t * framesTransferred);
// Terminates an asynchronous transfer early (DMA-driven)

Example of a blocking transfer (interrupt and DMA-driven). Note that the peripheral driver must be initialized first. See the Initialization Section for initialization information.

// Example blocking transfer function call (interrupt)
// Note: providing another device structure is optional and for this example, the assumption is that
// the DSPI_DRV_MasterConfigureBus was sufficient and NULL is passed for the device
// structure. Also, this example shows that 32 bytes are transferred with a timeout of 1000 µs.
DSPI_DRV_MasterTransferBlocking(masterInstance, NULL, s_dspiSourceBuffer,
s_dspiSinkBuffer, 32, 1000);
// Example blocking transfer function call (DMA)
// Note: providing another device structure is optional and for this example, the assumption is that
// the DSPI_DRV_MasterConfigureBus was sufficient and NULL is passed for the device
// structure. Also, this example shows that 32 bytes are transferred with a timeout of 1000 µs.
DSPI_DRV_EdmaMasterTransferBlocking(masterInstance, NULL, s_dspiSourceBuffer,
s_dspiSinkBuffer, 32, 1000);

Example of a non-blocking transfer (interrupt and DMA-driven). Note that the peripheral driver must be initialized first. See the Initialization Section for initialization information.

// Interrupt Example
uint32_t framesXfer;
// Example non-blocking transfer function call
// Note: providing another device structure is optional and for this example, the assumption is that
// the DSPI_DRV_MasterConfigureBus was sufficient and NULL is passed for the device
// structure. Also, this example shows that 32 bytes is transferred.
DSPI_DRV_MasterTransfer(masterInstance, NULL, s_dspiSourceBuffer, s_dspiSinkBuffer, 32);
// For non-blocking/async transfers, check back to get transfer status. For example,
// where framesXfer returns the number of frames transferred //
DSPI_DRV_MasterGetTransferStatus(masterInstance, &framesXfer);
// This is an example to terminate the on-going transfer:
// DMA Example
// Example non-blocking transfer function call
// Note: providing another device structure is optional and for this example, the assumption is that
// the DSPI_DRV_MasterConfigureBus was sufficient and NULL is passed for the device
// structure. Also, this example shows that 32 bytes is transferred.
DSPI_DRV_EdmaMasterTransfer(masterInstance, NULL, s_dspiSourceBuffer, s_dspiSinkBuffer, 32);
// For non-blocking/async transfers, check back to get transfer status. For example,
// where framesXfer returns the number of frames transferred //
DSPI_DRV_EdmaMasterGetTransferStatus(masterInstance, &framesXfer);
// This is an example to terminate the on-going transfer:

DSPI De-initialization

To deinitialize and shut down the DSPI module, call this function:

// interrupt-driven
void DSPI_DRV_MasterDeinit(masterInstance);
// DMA-driven
void DSPI_DRV_EdmaMasterDeinit(masterInstance);

Data Structures

struct  dspi_dma_device_t
 Data structure containing information about a device on the SPI bus with DMA. More...
 
struct  dspi_dma_master_state_t
 Runtime state structure for the DSPI master driver with DMA. More...
 
struct  dspi_dma_master_user_config_t
 The user configuration structure for the DSPI master driver with DMA. More...
 
struct  dspi_edma_device_t
 Data structure containing information about a device on the SPI bus with EDMA. More...
 
struct  dspi_edma_master_state_t
 Runtime state structure for the DSPI master driver with EDMA. More...
 
struct  dspi_edma_master_user_config_t
 The user configuration structure for the DSPI master driver with EDMA. More...
 
struct  dspi_device_t
 Data structure containing information about a device on the SPI bus. More...
 
struct  dspi_master_state_t
 Runtime state structure for the DSPI master driver. More...
 
struct  dspi_master_user_config_t
 The user configuration structure for the DSPI master driver. More...
 

Variables

SPI_Type *const g_dspiBase [SPI_INSTANCE_COUNT]
 Table of base pointers for SPI instances. More...
 
const IRQn_Type g_dspiIrqId [SPI_INSTANCE_COUNT]
 Table to save DSPI IRQ enumeration numbers defined in the CMSIS header file. More...
 
SPI_Type *const g_dspiBase [SPI_INSTANCE_COUNT]
 Table of base pointers for SPI instances. More...
 
const IRQn_Type g_dspiIrqId [SPI_INSTANCE_COUNT]
 Table to save DSPI IRQ enumeration numbers defined in the CMSIS header file. More...
 
SPI_Type *const g_dspiBase [SPI_INSTANCE_COUNT]
 Table of base pointers for SPI instances. More...
 
const IRQn_Type g_dspiIrqId [SPI_INSTANCE_COUNT]
 Table to save DSPI IRQ enumeration numbers defined in the CMSIS header file. More...
 

Initialization and shutdown

dspi_status_t DSPI_DRV_DmaMasterInit (uint32_t instance, dspi_dma_master_state_t *dspiDmaState, const dspi_dma_master_user_config_t *userConfig)
 Initializes a DSPI instance for master mode operation to work with DMA. More...
 
dspi_status_t DSPI_DRV_DmaMasterDeinit (uint32_t instance)
 Shuts down a DSPI instance with the DMA support. More...
 
dspi_status_t DSPI_DRV_DmaMasterSetDelay (uint32_t instance, dspi_delay_type_t whichDelay, uint32_t delayInNanoSec, uint32_t *calculatedDelay)
 Configures the DSPI master mode bus timing delay options with the DMA support. More...
 

Bus configuration

dspi_status_t DSPI_DRV_DmaMasterConfigureBus (uint32_t instance, const dspi_dma_device_t *device, uint32_t *calculatedBaudRate)
 Configures the DSPI port physical parameters to access a device on the bus with the DMA support. More...
 

Blocking transfers

dspi_status_t DSPI_DRV_DmaMasterTransferBlocking (uint32_t instance, const dspi_dma_device_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, size_t transferByteCount, uint32_t timeout)
 Performs a blocking SPI master mode transfer with the DMA support. More...
 

Non-blocking transfers

dspi_status_t DSPI_DRV_DmaMasterTransfer (uint32_t instance, const dspi_dma_device_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, size_t transferByteCount)
 Performs a non-blocking SPI master mode transfer with the DMA support. More...
 
dspi_status_t DSPI_DRV_DmaMasterGetTransferStatus (uint32_t instance, uint32_t *framesTransferred)
 Returns whether the previous transfer is completed with the DMA support. More...
 
dspi_status_t DSPI_DRV_DmaMasterAbortTransfer (uint32_t instance)
 Terminates an asynchronous transfer early with the DMA support. More...
 

Initialization and shutdown

dspi_status_t DSPI_DRV_EdmaMasterInit (uint32_t instance, dspi_edma_master_state_t *dspiEdmaState, const dspi_edma_master_user_config_t *userConfig, edma_software_tcd_t *stcdSrc2CmdDataLast)
 Initializes a DSPI instance for master mode operation to work with EDMA. More...
 
dspi_status_t DSPI_DRV_EdmaMasterDeinit (uint32_t instance)
 Shuts down a DSPI instance with the EDMA support. More...
 
dspi_status_t DSPI_DRV_EdmaMasterSetDelay (uint32_t instance, dspi_delay_type_t whichDelay, uint32_t delayInNanoSec, uint32_t *calculatedDelay)
 Configures the DSPI master mode bus timing delay options with the EDMA support. More...
 

Bus configuration

dspi_status_t DSPI_DRV_EdmaMasterConfigureBus (uint32_t instance, const dspi_edma_device_t *device, uint32_t *calculatedBaudRate)
 Configures the DSPI port physical parameters to access a device on the bus with the EDMA support. More...
 

Blocking transfers

dspi_status_t DSPI_DRV_EdmaMasterTransferBlocking (uint32_t instance, const dspi_edma_device_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, size_t transferByteCount, uint32_t timeout)
 Performs a blocking SPI master mode transfer with the EDMA support. More...
 

Non-blocking transfers

dspi_status_t DSPI_DRV_EdmaMasterTransfer (uint32_t instance, const dspi_edma_device_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, size_t transferByteCount)
 Performs a non-blocking SPI master mode transfer with the EDMA support. More...
 
dspi_status_t DSPI_DRV_EdmaMasterGetTransferStatus (uint32_t instance, uint32_t *framesTransferred)
 Returns whether the previous transfer is completed with the EDMA support. More...
 
dspi_status_t DSPI_DRV_EdmaMasterAbortTransfer (uint32_t instance)
 Terminates an asynchronous transfer early with the EDMA support. More...
 
void DSPI_DRV_EdmaMasterIRQHandler (uint32_t instance)
 Interrupt handler for DSPI master mode. More...
 

Initialization and shutdown

dspi_status_t DSPI_DRV_MasterInit (uint32_t instance, dspi_master_state_t *dspiState, const dspi_master_user_config_t *userConfig)
 Initializes a DSPI instance for master mode operation. More...
 
dspi_status_t DSPI_DRV_MasterDeinit (uint32_t instance)
 Shuts down a DSPI instance. More...
 
dspi_status_t DSPI_DRV_MasterSetDelay (uint32_t instance, dspi_delay_type_t whichDelay, uint32_t delayInNanoSec, uint32_t *calculatedDelay)
 Configures the DSPI master mode bus timing delay options. More...
 

Bus configuration

dspi_status_t DSPI_DRV_MasterConfigureBus (uint32_t instance, const dspi_device_t *device, uint32_t *calculatedBaudRate)
 Configures the DSPI port physical parameters to access a device on the bus. More...
 

Blocking transfers

dspi_status_t DSPI_DRV_MasterTransferBlocking (uint32_t instance, const dspi_device_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, size_t transferByteCount, uint32_t timeout)
 Performs a blocking SPI master mode transfer. More...
 

Non-blocking transfers

dspi_status_t DSPI_DRV_MasterTransfer (uint32_t instance, const dspi_device_t *device, const uint8_t *sendBuffer, uint8_t *receiveBuffer, size_t transferByteCount)
 Performs a non-blocking SPI master mode transfer. More...
 
dspi_status_t DSPI_DRV_MasterGetTransferStatus (uint32_t instance, uint32_t *framesTransferred)
 Returns whether the previous transfer is completed. More...
 
dspi_status_t DSPI_DRV_MasterAbortTransfer (uint32_t instance)
 Terminates an asynchronous transfer early. More...
 
void DSPI_DRV_MasterIRQHandler (uint32_t instance)
 Interrupt handler for DSPI master mode. More...
 

Data Structure Documentation

struct dspi_dma_device_t

The user must populate the members to set up the DSPI master with DMA and properly communicate with the SPI device.

Data Fields

uint32_t bitsPerSec
 Baud rate in bits per second. More...
 

Field Documentation

uint32_t dspi_dma_device_t::bitsPerSec
struct dspi_dma_master_state_t

This structure holds data used by the DSPI master Peripheral driver to communicate between the transfer function and the interrupt handler. The interrupt handler also uses this information to keep track of its progress. The user passes the memory for this run-time state structure. The DSPI master driver populates the members.

Data Fields

dspi_ctar_selection_t whichCtar
 Desired Clock and Transfer Attributes Register (CTAR)
 
uint32_t bitsPerFrame
 Desired number of bits per frame.
 
dspi_which_pcs_config_t whichPcs
 Desired Peripheral Chip Select (pcs)
 
bool isChipSelectContinuous
 Option to enable the continuous assertion of chip select between transfers.
 
uint32_t dspiSourceClock
 Module source clock.
 
volatile bool isTransferInProgress
 True if there is an active transfer. More...
 
volatile bool isTransferBlocking
 True if transfer is a blocking transaction. More...
 
semaphore_t irqSync
 Used to wait for ISR to complete its business. More...
 
dma_channel_t dmaTxDataChannel
 Structure definition for the DMA channel.
 
dma_channel_t dmaTxCmdChannel
 Structure definition for the DMA channel.
 
dma_channel_t dmaRxChannel
 Structure definition for the DMA channel.
 
bool extraByte
 Flag used for 16-bit transfers with odd byte count.
 
uint8_t * rxBuffer
 The buffer into which received bytes are placed. More...
 
uint32_t rxTransferByteCnt
 Number of bytes to receive. More...
 

Field Documentation

volatile bool dspi_dma_master_state_t::isTransferInProgress
volatile bool dspi_dma_master_state_t::isTransferBlocking
semaphore_t dspi_dma_master_state_t::irqSync
uint8_t* dspi_dma_master_state_t::rxBuffer
uint32_t dspi_dma_master_state_t::rxTransferByteCnt
struct dspi_dma_master_user_config_t

Use an instance of this structure with the DSPI_DRV_DmaMasterInit() function. This allows the user to configure the most common settings of the DSPI peripheral with a single function call.

Data Fields

dspi_ctar_selection_t whichCtar
 Desired Clock and Transfer Attributes Register(CTAR)
 
bool isSckContinuous
 Disable or Enable continuous SCK operation.
 
bool isChipSelectContinuous
 Option to enable the continuous assertion of chip select between transfers.
 
dspi_which_pcs_config_t whichPcs
 Desired Peripheral Chip Select (pcs)
 
dspi_pcs_polarity_config_t pcsPolarity
 Peripheral Chip Select (pcs) polarity setting. More...
 

Field Documentation

dspi_pcs_polarity_config_t dspi_dma_master_user_config_t::pcsPolarity
struct dspi_edma_device_t

The user must populate the members to set up the DSPI master with EDMA and properly communicate with the SPI device.

Data Fields

uint32_t bitsPerSec
 Baud rate in bits per second. More...
 

Field Documentation

uint32_t dspi_edma_device_t::bitsPerSec
struct dspi_edma_master_state_t

This structure holds data used by the DSPI master Peripheral driver to communicate between the transfer function and the interrupt handler. The interrupt handler also uses this information to keep track of its progress. The user passes the memory for this run-time state structure. The DSPI master driver populates the members.

Data Fields

dspi_ctar_selection_t whichCtar
 Desired Clock and Transfer Attributes Register (CTAR)
 
uint32_t bitsPerFrame
 Desired number of bits per frame.
 
dspi_which_pcs_config_t whichPcs
 Desired Peripheral Chip Select (pcs)
 
bool isChipSelectContinuous
 Option to enable the continuous assertion of chip select between transfers.
 
uint32_t dspiSourceClock
 Module source clock.
 
volatile bool isTransferInProgress
 True if there is an active transfer. More...
 
volatile bool isTransferBlocking
 True if transfer is a blocking transaction. More...
 
semaphore_t irqSync
 Used to wait for ISR to complete its business. More...
 
edma_chn_state_t dmaCmdData2Fifo
 Structure definition for the eDMA channel.
 
edma_chn_state_t dmaSrc2CmdData
 Structure definition for the eDMA channel.
 
edma_chn_state_t dmaFifo2Receive
 Structure definition for the eDMA channel.
 
edma_software_tcd_tstcdSrc2CmdDataLast
 Pointer to SW TCD in memory.
 
bool extraByte
 Flag used for 16-bit transfers with odd byte count.
 
uint8_t * rxBuffer
 The buffer into which received bytes are placed. More...
 
uint32_t rxTransferByteCnt
 Number of bytes to receive. More...
 

Field Documentation

volatile bool dspi_edma_master_state_t::isTransferInProgress
volatile bool dspi_edma_master_state_t::isTransferBlocking
semaphore_t dspi_edma_master_state_t::irqSync
uint8_t* dspi_edma_master_state_t::rxBuffer
uint32_t dspi_edma_master_state_t::rxTransferByteCnt
struct dspi_edma_master_user_config_t

Use an instance of this structure with the DSPI_DRV_EdmaMasterInit() function. This allows the user to configure the most common settings of the DSPI peripheral with a single function call.

Data Fields

dspi_ctar_selection_t whichCtar
 Desired Clock and Transfer Attributes Register(CTAR)
 
bool isSckContinuous
 Disable or Enable continuous SCK operation.
 
bool isChipSelectContinuous
 Option to enable the continuous assertion of chip select between transfers.
 
dspi_which_pcs_config_t whichPcs
 Desired Peripheral Chip Select (pcs)
 
dspi_pcs_polarity_config_t pcsPolarity
 Peripheral Chip Select (pcs) polarity setting. More...
 

Field Documentation

dspi_pcs_polarity_config_t dspi_edma_master_user_config_t::pcsPolarity
struct dspi_device_t

The user must populate these members to set up the DSPI master and properly communicate with the SPI device.

Data Fields

uint32_t bitsPerSec
 Baud rate in bits per second. More...
 

Field Documentation

uint32_t dspi_device_t::bitsPerSec
struct dspi_master_state_t

This structure holds data that is used by the DSPI master peripheral driver to communicate between the transfer function and the interrupt handler. The interrupt handler also uses this information to keep track of its progress. The user must pass the memory for this run-time state structure. The DSPI master driver populates the members.

Data Fields

dspi_ctar_selection_t whichCtar
 Desired Clock and Transfer Attributes Register (CTAR)
 
uint32_t bitsPerFrame
 Desired number of bits per frame.
 
dspi_which_pcs_config_t whichPcs
 Desired Peripheral Chip Select (pcs)
 
bool isChipSelectContinuous
 Option to enable the continuous assertion of chip select between transfers.
 
uint32_t dspiSourceClock
 Module source clock.
 
volatile bool isTransferInProgress
 True if there is an active transfer. More...
 
const uint8_t * sendBuffer
 The buffer from which transmitted bytes are taken. More...
 
uint8_t * receiveBuffer
 The buffer into which received bytes are placed. More...
 
volatile size_t remainingSendByteCount
 Number of bytes remaining to send. More...
 
volatile size_t remainingReceiveByteCount
 Number of bytes remaining to receive. More...
 
volatile bool isTransferBlocking
 True if transfer is a blocking transaction. More...
 
semaphore_t irqSync
 Used to wait for ISR to complete its business. More...
 
bool extraByte
 Flag used for 16-bit transfers with odd byte count.
 

Field Documentation

volatile bool dspi_master_state_t::isTransferInProgress
const uint8_t* dspi_master_state_t::sendBuffer
uint8_t* dspi_master_state_t::receiveBuffer
volatile size_t dspi_master_state_t::remainingSendByteCount
volatile size_t dspi_master_state_t::remainingReceiveByteCount
volatile bool dspi_master_state_t::isTransferBlocking
semaphore_t dspi_master_state_t::irqSync
struct dspi_master_user_config_t

Use an instance of this structure with the DSPI_DRV_MasterInit() function. This allows the user to configure the most common settings of the DSPI peripheral with a single function call.

Data Fields

dspi_ctar_selection_t whichCtar
 Desired Clock and Transfer Attributes Register(CTAR)
 
bool isSckContinuous
 Disable or Enable continuous SCK operation.
 
bool isChipSelectContinuous
 Option to enable the continuous assertion of chip select between transfers.
 
dspi_which_pcs_config_t whichPcs
 Desired Peripheral Chip Select (pcs)
 
dspi_pcs_polarity_config_t pcsPolarity
 Peripheral Chip Select (pcs) polarity setting.
 

Function Documentation

dspi_status_t DSPI_DRV_DmaMasterInit ( uint32_t  instance,
dspi_dma_master_state_t dspiDmaState,
const dspi_dma_master_user_config_t userConfig 
)

This function uses a DMA-driven method for transferring data. This function initializes the run-time state structure to track the ongoing transfers, ungates the clock to the DSPI module, resets the DSPI module, initializes the module to user-defined settings and default settings, configures the IRQ state structure, enables the module-level interrupt to the core, and enables the DSPI module. The CTAR parameter is special in that it allows the user to have different SPI devices connected to the same DSPI module instance in addition to different peripheral chip selects. Each CTAR contains the bus attributes associated with that particular SPI device. For most use cases, where only one SPI device is connected per DSPI module instance, use CTAR0. This is an example to set up and call the DSPI_DRV_DmaMasterInit function by passing in these parameters:

dspi_dma_master_state_t dspiDmaState; <- the user allocates memory for this structure
uint32_t calculatedBaudRate;
dspi_dma_master_user_config_t userConfig; <- the user populates members for this structure
userConfig.isChipSelectContinuous = false;
userConfig.isSckContinuous = false;
userConfig.whichCtar = kDspiCtar0;
userConfig.whichPcs = kDspiPcs0;
DSPI_DRV_DmaMasterInit(masterInstance, &dspiDmaState, &userConfig);
Parameters
instanceThe instance number of the DSPI peripheral.
dspiDmaStateThe pointer to the DSPI DMA master driver state structure. The user passes the memory for the run-time state structure. The DSPI master driver populates the members. The run-time state structure keeps track of the transfer in progress.
userConfigThe dspi_dma_master_user_config_t user configuration structure. The user populates the members of this structure and passes the pointer of the structure into the function.
stcdSrc2CmdDataLastThis is a pointer to a structure of the stcdSrc2CmdDataLast type. It needs to be aligned to a 32-byte boundary. Some compilers allow you to use a #pragma directive to align a variable to a desired boundary.
Returns
An error code or kStatus_DSPI_Success.
dspi_status_t DSPI_DRV_DmaMasterDeinit ( uint32_t  instance)

This function resets the DSPI peripheral, gates its clock, disables any used interrupts to the core, and releases any used DMA channels.

Parameters
instanceThe instance number of the DSPI peripheral.
Returns
kStatus_DSPI_Success indicating successful de-initialization
dspi_status_t DSPI_DRV_DmaMasterSetDelay ( uint32_t  instance,
dspi_delay_type_t  whichDelay,
uint32_t  delayInNanoSec,
uint32_t *  calculatedDelay 
)

This function uses the DSPI module delay options to "fine tune" some of the signal timings and match the timing needs of a slower peripheral device. This is an optional function that can be called after the DSPI module has been initialized for master mode. The bus timing delays that can be adjusted are listed below:

PCS to SCK Delay: Adjustable delay option between the assertion of the PCS signal to the first SCK edge.

After SCK Delay: Adjustable delay option between the last edge of SCK to the de-assertion of the PCS signal.

Delay after Transfer: Adjustable delay option between the de-assertion of the PCS signal for a frame to the assertion of the PCS signal for the next frame. Note that this is not adjustable for continuous clock mode because this delay is fixed at one SCK period.

Each of the above delay parameters use both a pre-scalar and scalar value to calculate the needed delay. This function takes in as a parameter the desired delay type and the delay value (in nanoseconds), calculates the values needed for the prescaler and scaler. Returning the actual calculated delay as an exact delay match may not be possible. In this case, the closest match is calculated without going below the desired delay value input. It is possible to input a very large delay value that exceeds the capability of the part, in which case the maximum supported delay is returned. In addition, the function returns an out-of-range status.

Parameters
instanceThe instance number of the DSPI peripheral.
whichDelayThe desired delay to configure, must be of type dspi_delay_type_t
delayInNanoSecThe desired delay value in nano-seconds.
calculatedDelayThe calculated delay that best matches the desired delay (in nano-seconds).
Returns
Either kStatus_DSPI_Success or kStatus_DSPI_OutOfRange if the desired delay exceeds the capability of the device.
dspi_status_t DSPI_DRV_DmaMasterConfigureBus ( uint32_t  instance,
const dspi_dma_device_t device,
uint32_t *  calculatedBaudRate 
)

The term "device" is used to indicate the SPI device for which the DSPI master is communicating. The user has two options to configure the device parameters: pass in the pointer to the device configuration structure to the desired transfer function (see DSPI_DRV_DmaMasterTransferBlocking or DSPI_DRV_DmaMasterTransfer) or pass it in to the DSPI_DRV_DmaMasterConfigureBus function. The user can pass in a device structure to the transfer function which contains the parameters for the bus (the transfer function then calls this function). However, the user has the option to call this function directly especially to get the calculated baud rate, at which point they may pass in NULL for the device structure in the transfer function (assuming they have called this configure bus function first). This is an example to set up the dspi_device_t structure to call the DSPI_DRV_DmaMasterConfigureBus function by passing in these parameters:

spiDevice.dataBusConfig.bitsPerFrame = 16;
spiDevice.dataBusConfig.clkPhase = kDspiClockPhase_FirstEdge;
spiDevice.dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveHigh;
spiDevice.dataBusConfig.direction = kDspiMsbFirst;
spiDevice.bitsPerSec = 50000;
DSPI_DRV_DmaMasterConfigureBus(instance, &spiDevice, &calculatedBaudRate);
Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration. The device parameters are the desired baud rate (in bits-per-sec), and the data format field which consists of bits-per-frame, clock polarity and phase, and data shift direction.
calculatedBaudRateThe calculated baud rate passed back to the user to determine if the calculated baud rate is close enough to meet the needs. The baud rate never exceeds the desired baud rate.
Returns
An error code or kStatus_DSPI_Success.
dspi_status_t DSPI_DRV_DmaMasterTransferBlocking ( uint32_t  instance,
const dspi_dma_device_t device,
const uint8_t *  sendBuffer,
uint8_t *  receiveBuffer,
size_t  transferByteCount,
uint32_t  timeout 
)

This function simultaneously sends and receives data on the SPI bus, because the SPI is naturally a full-duplex bus. The function does not return until the transfer is complete.

Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration in this transfer. You may pass NULL for this parameter, in which case the current bus configuration is used unmodified. The device can be configured separately by calling the DSPI_DRV_DmaMasterConfigureBus function.
sendBufferThe pointer to the data buffer of the data to send. You may pass NULL for this parameter and bytes with a value of 0 (zero) is sent.
receiveBufferPointer to the buffer where the received bytes are stored. If you pass NULL for this parameter, the received bytes are ignored.
transferByteCountThe number of bytes to send and receive.
timeoutA timeout for the transfer in milliseconds. If the transfer takes longer than this amount of time, the transfer is aborted and a kStatus_SPI_Timeout error returned.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_Busy Cannot perform transfer because a transfer is already in progress, or kStatus_DSPI_Timeout The transfer timed out and was aborted.
dspi_status_t DSPI_DRV_DmaMasterTransfer ( uint32_t  instance,
const dspi_dma_device_t device,
const uint8_t *  sendBuffer,
uint8_t *  receiveBuffer,
size_t  transferByteCount 
)

This function returns immediately. The user must check back whether the transfer is complete (using the DSPI_DRV_DmaMasterGetTransferStatus function). This function simultaneously sends and receives data on the SPI bus because the SPI is a full-duplex bus.

Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration in this transfer. You may pass NULL for this parameter, in which case the current bus configuration is used unmodified. The device can be configured separately by calling the DSPI_DRV_DmaMasterConfigureBus function.
sendBufferThe pointer to the data buffer of the data to send. You may pass NULL for this parameter, in which case bytes with a value of 0 (zero) are sent.
receiveBufferPointer to the buffer where the received bytes are stored. If you pass NULL for this parameter, the received bytes are ignored.
transferByteCountThe number of bytes to send and receive.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_Busy Cannot perform transfer because a transfer is already in progress.
dspi_status_t DSPI_DRV_DmaMasterGetTransferStatus ( uint32_t  instance,
uint32_t *  framesTransferred 
)

When performing an a-sync transfer, the user can call this function to ascertain the state of the current transfer: in progress (or busy) or complete (success). In addition, if the transfer is still in progress, the user can get the number of words that have been transferred up to now.

Parameters
instanceThe instance number of the DSPI peripheral.
framesTransferredPointer to value populated with the number of frames that have been sent during the active transfer. A frame is defined as the number of bits per frame.
Returns
kStatus_DSPI_Success The transfer has completed successfully, or kStatus_DSPI_Busy The transfer is still in progress. framesTransferred is filled with the number of words that have been transferred so far.
dspi_status_t DSPI_DRV_DmaMasterAbortTransfer ( uint32_t  instance)

During an a-sync transfer, the user has the option to terminate the transfer early if the transfer is still in progress.

Parameters
instanceThe instance number of the DSPI peripheral.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_NoTransferInProgress No transfer is currently in progress.
dspi_status_t DSPI_DRV_EdmaMasterInit ( uint32_t  instance,
dspi_edma_master_state_t dspiEdmaState,
const dspi_edma_master_user_config_t userConfig,
edma_software_tcd_t stcdSrc2CmdDataLast 
)

This function uses a DMA-driven method for transferring data. This function initializes the run-time state structure to track the ongoing transfers, ungates the clock to the DSPI module, resets the DSPI module, initializes the module to user-defined settings and default settings, configures the IRQ state structure, enables the module-level interrupt to the core, and enables the DSPI module. The CTAR parameter is special in that it allows the user to have different SPI devices connected to the same DSPI module instance in addition to different peripheral chip selects. Each CTAR contains the bus attributes associated with that particular SPI device. For most use cases, where only one SPI device is connected per DSPI module instance, use CTAR0. This is an example to set up and call the DSPI_DRV_EdmaMasterInit function by passing in these parameters:

dspi_edma_master_state_t dspiEdmaState; <- the user allocates memory for this structure
uint32_t calculatedBaudRate;
dspi_edma_master_user_config_t userConfig; <- the user populates members for this structure
userConfig.isChipSelectContinuous = false;
userConfig.isSckContinuous = false;
userConfig.whichCtar = kDspiCtar0;
userConfig.whichPcs = kDspiPcs0;
DSPI_DRV_EdmaMasterInit(masterInstance, &dspiEdmaState, &userConfig);
Parameters
instanceThe instance number of the DSPI peripheral.
dspiEdmaStateThe pointer to the DSPI EDMA master driver state structure. The user passes the memory for the run-time state structure. The DSPI master driver populates the members. The run-time state structure keeps track of the transfer in progress.
userConfigThe dspi_edma_master_user_config_t user configuration structure. The user populates the members of this structure and passes the pointer of the structure into the function.
stcdSrc2CmdDataLastThis is a pointer to a structure of the stcdSrc2CmdDataLast type. It needs to be aligned to a 32-byte boundary. Some compilers allow you to use a #pragma directive to align a variable to a desired boundary.
Returns
An error code or kStatus_DSPI_Success.
dspi_status_t DSPI_DRV_EdmaMasterDeinit ( uint32_t  instance)

This function resets the DSPI peripheral, gates its clock, disables any used interrupts to the core, and releases any used DMA channels.

Parameters
instanceThe instance number of the DSPI peripheral.
Returns
kStatus_DSPI_Success indicating successful de-initialization
dspi_status_t DSPI_DRV_EdmaMasterSetDelay ( uint32_t  instance,
dspi_delay_type_t  whichDelay,
uint32_t  delayInNanoSec,
uint32_t *  calculatedDelay 
)

This function uses the DSPI module delay options to "fine tune" some of the signal timings and match the timing needs of a slower peripheral device. This is an optional function that can be called after the DSPI module has been initialized for master mode. The bus timing delays that can be adjusted are listed below:

PCS to SCK Delay: Adjustable delay option between the assertion of the PCS signal to the first SCK edge.

After SCK Delay: Adjustable delay option between the last edge of SCK to the de-assertion of the PCS signal.

Delay after Transfer: Adjustable delay option between the de-assertion of the PCS signal for a frame to the assertion of the PCS signal for the next frame. Note that this is not adjustable for continuous clock mode because this delay is fixed at one SCK period.

Each of the above delay parameters uses both a pre-scalar and scalar value to calculate the needed delay. This function takes the desired delay type as a parameter and the delay value (in nanoseconds), calculates the values needed for the prescaler and scaler. Returning the actual calculated delay as an exact delay match may not be possible. In this situation, the closest match is calculated without going below the desired delay value input. It is possible to input a very large delay value that exceeds the capability of the part, in which case the maximum supported delay is returned. In addition, the function returns an out-of-range status.

Parameters
instanceThe instance number of the DSPI peripheral.
whichDelayThe desired delay to configure, must be of type dspi_delay_type_t
delayInNanoSecThe desired delay value in nanoseconds.
calculatedDelayThe calculated delay that best matches the desired delay (in nanoseconds).
Returns
Either kStatus_DSPI_Success or kStatus_DSPI_OutOfRange if the desired delay exceeds the capability of the device.
dspi_status_t DSPI_DRV_EdmaMasterConfigureBus ( uint32_t  instance,
const dspi_edma_device_t device,
uint32_t *  calculatedBaudRate 
)

The term "device" describes the SPI device for which the DSPI master is communicating. The user has two options to configure the device parameters: pass in the pointer to the device configuration structure to the desired transfer function (see DSPI_DRV_EdmaMasterTransferBlocking or DSPI_DRV_EdmaMasterTransfer) or pass it in to the DSPI_DRV_EdmaMasterConfigureBus function. The user can pass in a device structure to the transfer function which contains the parameters for the bus (the transfer function then calls this function). However, the user has the option to call this function directly to get the calculated baud rate, at which point, the user may pass in NULL for the device structure in the transfer function (assuming they have called this configure bus function first). This is an example to set up the dspi_device_t structure to call the DSPI_DRV_EdmaMasterConfigureBus function by passing in these parameters:

spiDevice.dataBusConfig.bitsPerFrame = 16;
spiDevice.dataBusConfig.clkPhase = kDspiClockPhase_FirstEdge;
spiDevice.dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveHigh;
spiDevice.dataBusConfig.direction = kDspiMsbFirst;
spiDevice.bitsPerSec = 50000;
DSPI_DRV_EdmaMasterConfigureBus(instance, &spiDevice, &calculatedBaudRate);
Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration. The device parameters are the desired baud rate (in bits-per-sec), and the data format field which consists of bits-per-frame, clock polarity and phase, and data shift direction.
calculatedBaudRateThe calculated baud rate passed back to the user to determine if the calculated baud rate is close enough to meet the needs. The baud rate never exceeds the desired baud rate.
Returns
An error code or kStatus_DSPI_Success.
dspi_status_t DSPI_DRV_EdmaMasterTransferBlocking ( uint32_t  instance,
const dspi_edma_device_t device,
const uint8_t *  sendBuffer,
uint8_t *  receiveBuffer,
size_t  transferByteCount,
uint32_t  timeout 
)

This function simultaneously sends and receives data on the SPI bus, because the SPI is naturally a full-duplex bus. The function does not return until the transfer is complete.

Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration in this transfer. You may pass NULL for this parameter, in which case the current bus configuration is used unmodified. The device can be configured separately by calling the DSPI_DRV_EdmaMasterConfigureBus function.
sendBufferThe pointer to the data buffer of the data to send. You may pass NULL for this parameter and bytes with a value of 0 (zero) is sent.
receiveBufferPointer to the buffer where the received bytes are stored. If you pass NULL for this parameter, the received bytes are ignored.
transferByteCountThe number of bytes to send and receive.
timeoutA timeout for the transfer in milliseconds. If the transfer takes longer than this amount of time, the transfer is aborted and a kStatus_SPI_Timeout error returned.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_Busy Cannot perform transfer because a transfer is already in progress, or kStatus_DSPI_Timeout The transfer timed out and was aborted.
dspi_status_t DSPI_DRV_EdmaMasterTransfer ( uint32_t  instance,
const dspi_edma_device_t device,
const uint8_t *  sendBuffer,
uint8_t *  receiveBuffer,
size_t  transferByteCount 
)

This function returns immediately. The user must check back whether the transfer is complete (using the DSPI_DRV_EdmaMasterGetTransferStatus function). This function simultaneously sends and receives data on the SPI bus because the SPI is a full-duplex bus.

Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration in this transfer. You may pass NULL for this parameter, in which case the current bus configuration is used unmodified. The device can be configured separately by calling the DSPI_DRV_EdmaMasterConfigureBus function.
sendBufferThe pointer to the data buffer of the data to send. You may pass NULL for this parameter, in which case bytes with a value of 0 (zero) are sent.
receiveBufferPointer to the buffer where the received bytes are stored. If you pass NULL for this parameter, the received bytes are ignored.
transferByteCountThe number of bytes to send and receive.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_Busy Cannot perform transfer because a transfer is already in progress.
dspi_status_t DSPI_DRV_EdmaMasterGetTransferStatus ( uint32_t  instance,
uint32_t *  framesTransferred 
)

When performing an a-sync transfer, the user can call this function to ascertain the state of the current transfer: in progress (or busy) or complete (success). In addition, if the transfer is still in progress, the user can get the number of words that have been transferred up to now.

Parameters
instanceThe instance number of the DSPI peripheral.
framesTransferredPointer to value populated with the number of frames that have been sent during the active transfer. A frame is defined as the number of bits per frame.
Returns
kStatus_DSPI_Success The transfer has completed successfully, or kStatus_DSPI_Busy The transfer is still in progress. framesTransferred is filled with the number of words that have been transferred so far.
dspi_status_t DSPI_DRV_EdmaMasterAbortTransfer ( uint32_t  instance)

During an a-sync transfer, the user has the option to terminate the transfer early if the transfer is still in progress.

Parameters
instanceThe instance number of the DSPI peripheral.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_NoTransferInProgress No transfer is currently in progress.
void DSPI_DRV_EdmaMasterIRQHandler ( uint32_t  instance)

This handler uses the buffers stored in the dspi_master_state_t structures to transfer data.

Parameters
instanceThe instance number of the DSPI peripheral.
dspi_status_t DSPI_DRV_MasterInit ( uint32_t  instance,
dspi_master_state_t dspiState,
const dspi_master_user_config_t userConfig 
)

This function uses a CPU interrupt driven method for transferring data. This function initializes the run-time state structure to track the ongoing transfers, un-gates the clock to the DSPI module, resets the DSPI module, initializes the module to user defined settings and default settings, configures the IRQ state structure, enables the module-level interrupt to the core, and enables the DSPI module. The CTAR parameter is special in that it allows the user to have different SPI devices connected to the same DSPI module instance in addition to different peripheral device selects. Each CTAR contains the bus attributes associated with that particular SPI device. For most use cases where only one SPI device is connected per DSPI module instance, use CTAR0. This is an example to set up the dspi_master_state_t and the dspi_master_user_config_t parameters and to call the DSPI_DRV_MasterInit function by passing in these parameters:

dspi_master_state_t dspiMasterState; <- the user allocates memory for this structure
uint32_t calculatedBaudRate;
dspi_master_user_config_t userConfig; <- the user populates members for this structure
userConfig.isChipSelectContinuous = false;
userConfig.isSckContinuous = false;
userConfig.whichCtar = kDspiCtar0;
userConfig.whichPcs = kDspiPcs0;
DSPI_DRV_MasterInit(masterInstance, &dspiMasterState, &userConfig);
Parameters
instanceThe instance number of the DSPI peripheral.
dspiStateThe pointer to the DSPI master driver state structure. The user passes the memory for this run-time state structure. The DSPI master driver populates the members. This run-time state structure keeps track of the transfer in progress.
userConfigThe dspi_master_user_config_t user configuration structure. The user populates the members of this structure and passes the pointer of this structure to the function.
Returns
An error code or kStatus_DSPI_Success.
dspi_status_t DSPI_DRV_MasterDeinit ( uint32_t  instance)

This function resets the DSPI peripheral, gates its clock, and disables the interrupt to the core.

Parameters
instanceThe instance number of the DSPI peripheral.
Returns
kStatus_DSPI_Success indicating successful de-initialization
dspi_status_t DSPI_DRV_MasterSetDelay ( uint32_t  instance,
dspi_delay_type_t  whichDelay,
uint32_t  delayInNanoSec,
uint32_t *  calculatedDelay 
)

This function involves the DSPI module's delay options to "fine tune" some of the signal timings and match the timing needs of a slower peripheral device. This is an optional function that can be called after the DSPI module has been initialized for master mode. The bus timing delays that can be adjusted are listed below:

PCS to SCK Delay: Adjustable delay option between the assertion of the PCS signal to the first SCK edge.

After SCK Delay: Adjustable delay option between the last edge of SCK to the de-assertion of the PCS signal.

Delay after Transfer: Adjustable delay option between the de-assertion of the PCS signal for a frame to the assertion of the PCS signal for the next frame. Note that this is not adjustable for continuous clock mode because this delay is fixed at one SCK period.

Each of the above delay parameters use both a pre-scalar and scalar value to calculate the needed delay. This function takes in as a parameter the desired delay type and the delay value (in nanoseconds), calculates the values needed for the prescaler and scaler. Returning the actual calculated delay as an exact delay match may not be possible. In this case, the closest match is calculated without going below the desired delay value input. It is possible to input a very large delay value that exceeds the capability of the part, in which case the maximum supported delay is returned. In addition, the function returns an out-of-range status.

Parameters
instanceThe instance number of the DSPI peripheral.
whichDelayThe desired delay to configure, must be of type dspi_delay_type_t
delayInNanoSecThe desired delay value in nanoseconds.
calculatedDelayThe calculated delay that best matches the desired delay (in nanoseconds).
Returns
Either kStatus_DSPI_Success or kStatus_DSPI_OutOfRange if the desired delay exceeds the capability of the device.
dspi_status_t DSPI_DRV_MasterConfigureBus ( uint32_t  instance,
const dspi_device_t device,
uint32_t *  calculatedBaudRate 
)

The term "device" is used to indicate the SPI device for which the DSPI master is communicating. The user has two options to configure the device parameters: either pass in the pointer to the device configuration structure to the desired transfer function (see DSPI_DRV_MasterTransferBlocking or DSPI_DRV_MasterTransfer) or pass it in to the DSPI_DRV_MasterConfigureBus function. The user can pass in a device structure to the transfer function which contains the parameters for the bus (the transfer function then calls this function). However, the user has the option to call this function directly especially to get the calculated baud rate, at which point they may pass in NULL for the device structure in the transfer function (assuming they have called this configure bus function first). This is an example to set up the dspi_device_t structure to call the DSPI_DRV_MasterConfigureBus function by passing in these parameters:

dspi_device_t spiDevice;
spiDevice.dataBusConfig.bitsPerFrame = 16;
spiDevice.dataBusConfig.clkPhase = kDspiClockPhase_FirstEdge;
spiDevice.dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveHigh;
spiDevice.dataBusConfig.direction = kDspiMsbFirst;
spiDevice.bitsPerSec = 50000;
DSPI_DRV_MasterConfigureBus(instance, &spiDevice, &calculatedBaudRate);
Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration. The device parameters are the desired baud rate (in bits-per-sec), and the data format field which consists of bits-per-frame, clock polarity and phase, and data shift direction.
calculatedBaudRateThe calculated baud rate passed back to the user to determine if the calculated baud rate is close enough to meet the needs. The baud rate never exceeds the desired baud rate.
Returns
An error code or kStatus_DSPI_Success.
dspi_status_t DSPI_DRV_MasterTransferBlocking ( uint32_t  instance,
const dspi_device_t device,
const uint8_t *  sendBuffer,
uint8_t *  receiveBuffer,
size_t  transferByteCount,
uint32_t  timeout 
)

This function simultaneously sends and receives data on the SPI bus, as SPI is naturally a full-duplex bus. The function does not return until the transfer is complete.

Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration in this transfer. You may pass NULL for this parameter, in which case the current bus configuration is used unmodified. The device can be configured separately by calling the DSPI_DRV_MasterConfigureBus function.
sendBufferThe pointer to the data buffer of the data to send. You may pass NULL for this parameter and bytes with a value of 0 (zero) is sent.
receiveBufferPointer to the buffer where the received bytes are stored. If you pass NULL for this parameter, the received bytes are ignored.
transferByteCountThe number of bytes to send and receive.
timeoutA timeout for the transfer in milliseconds. If the transfer takes longer than this amount of time, the transfer is aborted and a kStatus_SPI_Timeout error returned.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_Busy Cannot perform transfer because a transfer is already in progress, or kStatus_DSPI_Timeout The transfer timed out and was aborted.
dspi_status_t DSPI_DRV_MasterTransfer ( uint32_t  instance,
const dspi_device_t device,
const uint8_t *  sendBuffer,
uint8_t *  receiveBuffer,
size_t  transferByteCount 
)

This function returns immediately. The user needs to check whether the transfer is complete using the DSPI_DRV_MasterGetTransferStatus function. This function simultaneously sends and receives data on the SPI bus because the SPI is naturally a full-duplex bus.

Parameters
instanceThe instance number of the DSPI peripheral.
devicePointer to the device information structure. This structure contains the settings for the SPI bus configuration in this transfer. You may pass NULL for this parameter, in which case the current bus configuration is used unmodified. The device can be configured separately by calling the DSPI_DRV_MasterConfigureBus function.
sendBufferThe pointer to the data buffer of the data to send. You may pass NULL for this parameter, in which case bytes with a value of 0 (zero) are sent.
receiveBufferPointer to the buffer where the received bytes are stored. If you pass NULL for this parameter, the received bytes are ignored.
transferByteCountThe number of bytes to send and receive.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_Busy Cannot perform transfer because a transfer is already in progress.
dspi_status_t DSPI_DRV_MasterGetTransferStatus ( uint32_t  instance,
uint32_t *  framesTransferred 
)

When performing an a-sync transfer, the user can call this function to ascertain the state of the current transfer: in progress (or busy) or complete (success). In addition, if the transfer is still in progress, the user can get the number of words that have been transferred up to now.

Parameters
instanceThe instance number of the DSPI peripheral.
framesTransferredPointer to value that is filled in with the number of frames that have been sent in the active transfer. A frame is defined as the number of bits per frame.
Returns
kStatus_DSPI_Success The transfer has completed successfully, or kStatus_DSPI_Busy The transfer is still in progress. framesTransferred is filled with the number of words that have been transferred so far.
dspi_status_t DSPI_DRV_MasterAbortTransfer ( uint32_t  instance)

During an a-sync transfer, the user has the option to terminate the transfer early if the transfer is still in progress.

Parameters
instanceThe instance number of the DSPI peripheral.
Returns
kStatus_DSPI_Success The transfer was successful, or kStatus_DSPI_NoTransferInProgress No transfer is currently in progress.
void DSPI_DRV_MasterIRQHandler ( uint32_t  instance)

This handler uses the buffers stored in the dspi_master_state_t structs to transfer data.

Parameters
instanceThe instance number of the DSPI peripheral.

Variable Documentation

SPI_Type* const g_dspiBase[SPI_INSTANCE_COUNT]
const IRQn_Type g_dspiIrqId[SPI_INSTANCE_COUNT]
SPI_Type* const g_dspiBase[SPI_INSTANCE_COUNT]
const IRQn_Type g_dspiIrqId[SPI_INSTANCE_COUNT]
SPI_Type* const g_dspiBase[SPI_INSTANCE_COUNT]
const IRQn_Type g_dspiIrqId[SPI_INSTANCE_COUNT]