S32 SDK
FlexIO UART Driver

Detailed Description

UART communication over FlexIO module (FLEXIO_UART)

The FLEXIO_UART Driver allows UART communication using the FlexIO module in the S32144K processor.

Features

Functionality

Initialization

Before using any Flexio driver the device must first be initialized using function FLEXIO_DRV_InitDevice. Then the FLEXIO_UART Driver must be initialized, using function FLEXIO_UART_DRV_Init(). It is possible to use more driver instances on the same FlexIO device, as long as sufficient resources are available. Different driver instances on the same FlexIO device can function independently of each other. When it is no longer needed, the driver can be de-initialized, using FLEXIO_UART_DRV_Deinit(). This will release the hardware resources, allowing other driver instances to be initialized.

Choosing transmit/receive mode

To initialize the UART driver in transmit / receive mode the direction field of the configuration structure must be set to FLEXIO_UART_DIRECTION_TX / FLEXIO_UART_DIRECTION_RX when calling FLEXIO_UART_DRV_Init(). Once configured for one direction the driver must be used only for the chosen direction until it is de-initialized. One driver instance can only work in one direction at a time, but more driver instances can be created on the same device, up to the number of shifters present on the device (for example on S32K144 up to 4 driver instances can run in parallel on one device).

Setting the baud rate and bit count

The baud rate and bit count are provided at initialization time through the master configuration structure, but they can be changed at runtime by using function FLEXIO_UART_DRV_SetConfig(). Note that due to module limitation not any baud rate can be achieved. The driver will set a baud rate as close as possible to the requested baud rate, but there may still be substantial differences, for example if requesting a high baud rate while using a low-frequency FlexIO clock. The application should call FLEXIO_UART_DRV_GetBaudRate() to check what baud rate was actually set.

Transmitting / Receiving

To send or receive data to/from the currently configured slave address, use functions FLEXIO_UART_DRV_SendData() or FLEXIO_UART_DRV_ReceiveData() (or their blocking counterparts). Continuous send/receive can be realized by registering a user callback function. When the driver completes the transmission or reception of the current buffer, it will invoke the user callback with an appropriate event. The callback function can the use FLEXIO_UART_DRV_SetTxBuffer() orFLEXIO_UART_DRV_SetRxBuffer() to provide a new buffer.

Blocking operations will return only when the transfer is completed, either successfully or with error. Non-blocking operations will initiate the transfer and return STATUS_SUCCESS, but the module is still busy with the transfer and another transfer can't be initiated until the current transfer is complete. The application will be notified through the user callback when the transfer completes, or it can check the status of the current transfer by calling FLEXIO_UART_DRV_GetStatus(). If the transfer is still ongoing this function will return STATUS_BUSY. If the transfer is completed, the function will return either STATUS_SUCCESS or an error code, depending on the outcome of the last transfer.

The driver supports interrupt, DMA and polling mode. In polling mode the function FLEXIO_UART_DRV_GetStatus() ensures the progress of the transfer by checking and handling transmit and receive events reported by the FlexIO module. The application should ensure that this function is called often enough (at least once per transferred byte) to avoid Tx underflows or Rx overflows. In DMA mode the DMA channel that will be used by the driver is received through the configuration structure. The channel must be initialized by the application before the flexio_uart driver is initialized. The flexio_uart driver will only set the DMA request source.

Important Notes

Data Structures

struct  flexio_uart_user_config_t
 Driver configuration structure. More...
 
struct  flexio_uart_state_t
 Driver internal context structure. More...
 

Enumerations

enum  flexio_uart_driver_direction_t { FLEXIO_UART_DIRECTION_TX = 0x01U, FLEXIO_UART_DIRECTION_RX = 0x00U }
 flexio_uart driver direction (tx or rx) More...
 

FLEXIO_UART Driver

status_t FLEXIO_UART_DRV_Init (uint32_t instance, const flexio_uart_user_config_t *userConfigPtr, flexio_uart_state_t *state)
 Initialize the FLEXIO_UART driver. More...
 
status_t FLEXIO_UART_DRV_Deinit (flexio_uart_state_t *state)
 De-initialize the FLEXIO_UART driver. More...
 
status_t FLEXIO_UART_DRV_SetConfig (flexio_uart_state_t *state, uint32_t baudRate, uint8_t bitCount)
 Set the baud rate and bit width for any subsequent UART communication. More...
 
status_t FLEXIO_UART_DRV_GetBaudRate (flexio_uart_state_t *state, uint32_t *baudRate)
 Get the currently configured baud rate. More...
 
status_t FLEXIO_UART_DRV_SendDataBlocking (flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout)
 Perform a blocking UART transmission. More...
 
status_t FLEXIO_UART_DRV_SendData (flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize)
 Perform a non-blocking UART transmission. More...
 
status_t FLEXIO_UART_DRV_ReceiveDataBlocking (flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout)
 Perform a blocking UART reception. More...
 
status_t FLEXIO_UART_DRV_ReceiveData (flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize)
 Perform a non-blocking UART reception. More...
 
status_t FLEXIO_UART_DRV_GetStatus (flexio_uart_state_t *state, uint32_t *bytesRemaining)
 Get the status of the current non-blocking UART transfer. More...
 
status_t FLEXIO_UART_DRV_TransferAbort (flexio_uart_state_t *state)
 Aborts a non-blocking UART transfer. More...
 
status_t FLEXIO_UART_DRV_SetRxBuffer (flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize)
 Provide a buffer for receiving data. More...
 
status_t FLEXIO_UART_DRV_SetTxBuffer (flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize)
 Provide a buffer for transmitting data. More...
 

Enumeration Type Documentation

flexio_uart driver direction (tx or rx)

This structure describes the direction configuration options for the flexio_uart driver. Implements : flexio_uart_driver_direction_t_Class

Enumerator
FLEXIO_UART_DIRECTION_TX 

Tx UART driver

FLEXIO_UART_DIRECTION_RX 

Rx UART driver

Definition at line 45 of file flexio_uart_driver.h.

Function Documentation

status_t FLEXIO_UART_DRV_Deinit ( flexio_uart_state_t state)

De-initialize the FLEXIO_UART driver.

This function de-initializes the FLEXIO_UART driver. The driver can't be used again until reinitialized. The context structure is no longer needed by the driver and can be freed after calling this function.

Parameters
statePointer to the FLEXIO_UART driver context structure.
Returns
Error or success status returned by API

Definition at line 1050 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_GetBaudRate ( flexio_uart_state_t state,
uint32_t *  baudRate 
)

Get the currently configured baud rate.

This function returns the currently configured UART baud rate.

Parameters
statePointer to the FLEXIO_UART driver context structure.
baudRatethe current baud rate in hertz
Returns
Error or success status returned by API

Definition at line 1129 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_GetStatus ( flexio_uart_state_t state,
uint32_t *  bytesRemaining 
)

Get the status of the current non-blocking UART transfer.

This function returns the current status of a non-blocking UART transfer. A return code of STATUS_BUSY means the transfer is still in progress. Otherwise the function returns a status reflecting the outcome of the last transfer. When the driver is initialized in polling mode this function also advances the transfer by checking and handling the transmit and receive events, so it must be called frequently to avoid overflows or underflows.

Parameters
statePointer to the FLEXIO_UART driver context structure.
bytesRemainingthe remaining number of bytes to be transferred
Returns
Error or success status returned by API

Definition at line 1366 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_Init ( uint32_t  instance,
const flexio_uart_user_config_t userConfigPtr,
flexio_uart_state_t state 
)

Initialize the FLEXIO_UART driver.

This function initializes the FLEXIO_UART driver.

Parameters
instanceFLEXIO peripheral instance number
userConfigPtrPointer to the FLEXIO_UART user configuration structure. The function reads configuration data from this structure and initializes the driver accordingly. The application may free this structure after the function returns.
statePointer to the FLEXIO_UART driver context structure. The driver uses this memory area for its internal logic. The application must make no assumptions about the content of this structure, and must not free this memory until the driver is de-initialized using FLEXIO_UART_DRV_Deinit().
Returns
Error or success status returned by API

Definition at line 945 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_ReceiveData ( flexio_uart_state_t state,
uint8_t *  rxBuff,
uint32_t  rxSize 
)

Perform a non-blocking UART reception.

This function receives a block of data and returns immediately. The rest of the transmission is handled by the interrupt service routine (if the driver is initialized in interrupt mode) or by the FLEXIO_UART_DRV_GetReceiveStatus() function (if the driver is initialized in polling mode).

Parameters
statePointer to the FLEXIO_UART driver context structure.
rxBuffpointer to the receive buffer
rxSizelength in bytes of the data to be received
Returns
Error or success status returned by API

Definition at line 1259 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_ReceiveDataBlocking ( flexio_uart_state_t state,
uint8_t *  rxBuff,
uint32_t  rxSize,
uint32_t  timeout 
)

Perform a blocking UART reception.

This function receives a block of data and only returns when the transmission is complete.

Parameters
statePointer to the FLEXIO_UART driver context structure.
rxBuffpointer to the receive buffer
rxSizelength in bytes of the data to be received
timeouttimeout for the transfer in milliseconds
Returns
Error or success status returned by API

Definition at line 1315 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_SendData ( flexio_uart_state_t state,
const uint8_t *  txBuff,
uint32_t  txSize 
)

Perform a non-blocking UART transmission.

This function sends a block of data and returns immediately. The rest of the transmission is handled by the interrupt service routine (if the driver is initialized in interrupt mode) or by the FLEXIO_UART_DRV_GetTransmitStatus() function (if the driver is initialized in polling mode).

Parameters
statePointer to the FLEXIO_UART driver context structure.
txBuffpointer to the data to be transferred
txSizelength in bytes of the data to be transferred
Returns
Error or success status returned by API

Definition at line 1168 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_SendDataBlocking ( flexio_uart_state_t state,
const uint8_t *  txBuff,
uint32_t  txSize,
uint32_t  timeout 
)

Perform a blocking UART transmission.

This function sends a block of data and only returns when the transmission is complete.

Parameters
statePointer to the FLEXIO_UART driver context structure.
txBuffpointer to the data to be transferred
txSizelength in bytes of the data to be transferred
timeouttimeout for the transfer in milliseconds
Returns
Error or success status returned by API

Definition at line 1226 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_SetConfig ( flexio_uart_state_t state,
uint32_t  baudRate,
uint8_t  bitCount 
)

Set the baud rate and bit width for any subsequent UART communication.

This function sets the baud rate and bit width for the UART driver. Note that due to module limitation not any baud rate can be achieved. The driver will set a baud rate as close as possible to the requested baud rate, but there may still be substantial differences, for example if requesting a high baud rate while using a low-frequency FlexIO clock. The application should call FLEXIO_UART_DRV_GetBaudRate() after FLEXIO_UART_DRV_SetConfig() to check what baud rate was actually set.

Parameters
statePointer to the FLEXIO_UART driver context structure.
baudRatethe desired baud rate in hertz
bitCountnumber of bits per word
Returns
Error or success status returned by API

Definition at line 1074 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_SetRxBuffer ( flexio_uart_state_t state,
uint8_t *  rxBuff,
uint32_t  rxSize 
)

Provide a buffer for receiving data.

This function can be used to provide a new buffer for receiving data to the driver. It can be called from the user callback when event STATUS_UART_RX_OVERRUN is reported. This way the reception will continue without interruption.

Parameters
statePointer to the FLEXIO_UART driver context structure.
rxBuffpointer to the buffer where to store received data
rxSizelength in bytes of the data to be transferred
Returns
Error or success status returned by API

Definition at line 1399 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_SetTxBuffer ( flexio_uart_state_t state,
const uint8_t *  txBuff,
uint32_t  txSize 
)

Provide a buffer for transmitting data.

This function can be used to provide a new buffer for transmitting data to the driver. It can be called from the user callback when event STATUS_UART_TX_UNDERRUN is reported. This way the transmission will continue without interruption.

Parameters
statePointer to the FLEXIO_UART driver context structure.
txBuffpointer to the buffer containing transmit data
txSizelength in bytes of the data to be transferred
Returns
Error or success status returned by API

Definition at line 1421 of file flexio_uart_driver.c.

status_t FLEXIO_UART_DRV_TransferAbort ( flexio_uart_state_t state)

Aborts a non-blocking UART transfer.

This function aborts a non-blocking UART transfer.

Parameters
statePointer to the FLEXIO_UART driver context structure.
Returns
Error or success status returned by API

Definition at line 1348 of file flexio_uart_driver.c.