Serial Peripheral Interface - Peripheral Abstraction Layer.
The SPI PAL driver allows communication on an SPI bus. It was designed to be portable across all platforms and IPs which support SPI communication.
Unlike the other drivers, SPI PAL modules need to include a configuration file named spi_pal_cfg.h, which allows the user to specify which IPSs are used and how many resources are allocated for each of them (state structures). The following code example shows how to configure one instance for each available SPI IPs.
The following table contains the matching between platforms and available IPs
IP/MCU | S32K118 | S32K116 | S32K142 | S32K144 | S32K148 | MPC5748G | MPC5746C | MPC5744P |
---|---|---|---|---|---|---|---|---|
FLEXIO | YES | YES | YES | YES | YES | NO | NO | NO |
LPSPI | YES | YES | YES | YES | YES | NO | NO | NO |
DSPI/SPI | NO | NO | NO | NO | NO | YES | YES | YES |
In order to use the SPI driver it must be first initialized in either master or slave mode, using functions SPI_MasterInit() or SPI_SlaveInit(). Once initialized, it cannot be initialized again for the same SPI module instance until it is de-initialized, using SPI_SlaveDeinit() or SPI_MasterDeinit. Different SPI module instances can work independently of each other.
In each mode (master/slave) are available two types of transfers: blocking and non-blocking. The functions which initiate blocking transfers will configure the time out for transmission. If time expires SPI_MasterTransferBlocking() or SPI_SlaveTransferBlocking() will return error and the transmission will be aborted.
The configuration structure includes a special field named extension. It will be used only for SPI transfers over FLEXIO and should contain a pointer to extension_flexio_for_spi_t structure. The purpose of this structure is to configure which FLEXIO pins are used by the applications and their functionality (MISO, MOSI, SCK, SS). One FLEXIO hardware instance can implements spi, so if instType is SPI_INST_TYPE_FLEXIO instIdx can be 0 or 1.
If device name is from MPC574xP family it can't be used as master in DMA mode and PAL will automatically switch the functionality to interrupt mode.
Data Structures | |
struct | spi_master_t |
Defines the configuration structure for SPI master Implements : spi_master_t_Class. More... | |
struct | spi_slave_t |
Defines the configuration structure for SPI slave Implements: spi_slave_t_Class. More... | |
Enumerations | |
enum | spi_transfer_type_t { SPI_USING_DMA = 0U, SPI_USING_INTERRUPTS = 1U } |
Defines the mechanism to update the rx or tx buffers Implements : spi_transfer_type_t_Class. More... | |
enum | spi_polarity_t { SPI_ACTIVE_HIGH = 0U, SPI_ACTIVE_LOW = 1U } |
Defines the polarity of signals Implements : spi_polarity_t_Class. More... | |
enum | spi_clock_phase_t { READ_ON_ODD_EDGE = 0U, READ_ON_EVEN_EDGE = 1U } |
Defines the edges used for sampling and shifting Implements : spi_clock_phase_t_Class. More... | |
enum | spi_transfer_bit_order_t { SPI_TRANSFER_MSB_FIRST = 0U, SPI_TRANSFER_LSB_FIRST = 1U } |
Defines the bit order Implements : spi_transfer_bit_order_t_Class. More... | |
Functions | |
status_t | SPI_MasterInit (const spi_instance_t *const instance, const spi_master_t *config) |
Initializes the SPI module in master mode. More... | |
status_t | SPI_SlaveInit (const spi_instance_t *const instance, const spi_slave_t *config) |
Initializes the SPI module in slave mode. More... | |
status_t | SPI_SetSS (const spi_instance_t *const instance, uint8_t ss) |
Update the SS. More... | |
status_t | SPI_MasterTransfer (const spi_instance_t *const instance, const void *txBuffer, void *rxBuffer, uint16_t numberOfFrames) |
Initializes a non-blocking master transfer. More... | |
status_t | SPI_MasterTransferBlocking (const spi_instance_t *const instance, const void *txBuffer, void *rxBuffer, uint16_t numberOfFrames, uint16_t timeout) |
Initializes a blocking master transfer. More... | |
status_t | SPI_SlaveTransfer (const spi_instance_t *const instance, const void *txBuffer, void *rxBuffer, uint16_t numberOfFrames) |
Initializes a non-blocking slave transfer. More... | |
status_t | SPI_SlaveTransferBlocking (const spi_instance_t *const instance, const void *txBuffer, void *rxBuffer, uint16_t numberOfFrames, uint16_t timeout) |
Initializes a blocking slave transfer. More... | |
status_t | SPI_GetStatus (const spi_instance_t *const instance) |
Gets the status of the last transfer. More... | |
status_t | SPI_GetDefaultMasterConfig (spi_master_t *config) |
Gets the default configuration structure for master. More... | |
status_t | SPI_GetDefaultSlaveConfig (spi_slave_t *config) |
Gets the default configuration structure for slave. More... | |
status_t | SPI_MasterDeinit (const spi_instance_t *const instance) |
De-initializes the spi master module. More... | |
status_t | SPI_SlaveDeinit (const spi_instance_t *const instance) |
De-initializes the spi slave module. More... | |
status_t | SPI_MasterSetDelay (const spi_instance_t *const instance, uint32_t delayBetweenTransfers, uint32_t delaySCKtoPCS, uint32_t delayPCStoSCK) |
Configures the SPI_PAL master mode bus timing delay options. More... | |
enum spi_clock_phase_t |
enum spi_polarity_t |
enum spi_transfer_type_t |
status_t SPI_GetDefaultMasterConfig | ( | spi_master_t * | config | ) |
status_t SPI_GetDefaultSlaveConfig | ( | spi_slave_t * | config | ) |
status_t SPI_GetStatus | ( | const spi_instance_t *const | instance | ) |
Gets the status of the last transfer.
This function return the status of the last transfer. Using this function the user can check if the transfer is still in progress or if time-out event occurred.
[in] | instance | The name of the instance |
[in] | txBuffer | Pointer to tx buffer. |
[in] | rxBuffer | Pointer to rx buffer. |
[in] | numberOfFrames | Number of frames sent/received |
[in] | timeout | Transfer time-out in ms |
status_t SPI_MasterDeinit | ( | const spi_instance_t *const | instance | ) |
status_t SPI_MasterInit | ( | const spi_instance_t *const | instance, |
const spi_master_t * | config | ||
) |
Initializes the SPI module in master mode.
This function initializes and enables the requested SPI module in master mode, configuring the bus parameters.
[in] | instance | The name of the instance |
[in] | config | The configuration structure |
status_t SPI_MasterSetDelay | ( | const spi_instance_t *const | instance, |
uint32_t | delayBetweenTransfers, | ||
uint32_t | delaySCKtoPCS, | ||
uint32_t | delayPCStoSCK | ||
) |
Configures the SPI_PAL master mode bus timing delay options.
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 SPI_PAL module has been initialized for master mode. The timings are adjusted in terms of microseconds. The bus timing delays that can be adjusted are listed below:
SCK to PCS Delay: Adjustable delay option between the last edge of SCK to the de-assertion of the PCS signal.
PCS to SCK Delay: Adjustable delay option between the assertion of the PCS signal to the first SCK edge.
Delay between Transfers: 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.
status_t SPI_MasterTransfer | ( | const spi_instance_t *const | instance, |
const void * | txBuffer, | ||
void * | rxBuffer, | ||
uint16_t | numberOfFrames | ||
) |
Initializes a non-blocking master transfer.
This function initializes a non-blocking master transfer.
[in] | instance | The name of the instance |
[in] | txBuffer | Pointer to tx buffer. |
[in] | rxBuffer | Pointer to rx buffer. |
[in] | numberOfFrames | Number of frames sent/received |
status_t SPI_MasterTransferBlocking | ( | const spi_instance_t *const | instance, |
const void * | txBuffer, | ||
void * | rxBuffer, | ||
uint16_t | numberOfFrames, | ||
uint16_t | timeout | ||
) |
Initializes a blocking master transfer.
This function initializes a blocking master transfer.
[in] | instance | The name of the instance |
[in] | txBuffer | Pointer to tx buffer. |
[in] | rxBuffer | Pointer to rx buffer. |
[in] | numberOfFrames | Number of frames sent/received |
[in] | timeout | Transfer time-out in ms |
status_t SPI_SetSS | ( | const spi_instance_t *const | instance, |
uint8_t | ss | ||
) |
status_t SPI_SlaveDeinit | ( | const spi_instance_t *const | instance | ) |
status_t SPI_SlaveInit | ( | const spi_instance_t *const | instance, |
const spi_slave_t * | config | ||
) |
Initializes the SPI module in slave mode.
This function initializes and enables the requested SPI module in slave mode, configuring the bus parameters.
[in] | instance | The name of the instance |
[in] | config | The configuration structure |
status_t SPI_SlaveTransfer | ( | const spi_instance_t *const | instance, |
const void * | txBuffer, | ||
void * | rxBuffer, | ||
uint16_t | numberOfFrames | ||
) |
Initializes a non-blocking slave transfer.
This function initializes a non-blocking slave transfer.
[in] | instance | The name of the instance |
[in] | txBuffer | Pointer to tx buffer. |
[in] | rxBuffer | Pointer to rx buffer. |
[in] | numberOfFrames | Number of frames sent/received |
status_t SPI_SlaveTransferBlocking | ( | const spi_instance_t *const | instance, |
const void * | txBuffer, | ||
void * | rxBuffer, | ||
uint16_t | numberOfFrames, | ||
uint16_t | timeout | ||
) |
Initializes a blocking slave transfer.
This function initializes a blocking slave transfer.
[in] | instance | The name of the instance |
[in] | txBuffer | Pointer to tx buffer. |
[in] | rxBuffer | Pointer to rx buffer. |
[in] | numberOfFrames | Number of frames sent/received |
[in] | timeout | Transfer time-out in ms |