This section describes the programming interface of the FlexIO UART Peripheral driver. The FlexIO UART driver transfers data to and from external devices on the Universal Asynchronous Receiver/Transmitter (UART) serial bus with a single function call.
FlexIO UART device structures
The driver uses an instantiation of the flexio_uart_state_t structure to maintain the current state of a particular FlexIO-simulated UART module driver. This structure holds data that is used by the FlexIO-simulated UART peripheral driver to communicate between the transmit and receive transfer functions and the interrupt handler. The interrupt handler also uses this information to keep track of its progress. Because the driver itself does not statically allocate memory, the caller provides memory for the driver state structure during initialization by providing a structure.
FlexIO UART user configuration structures
The FlexIO-simulated UART driver uses instances of the user configuration structure flexio_uart_userconfig_t for the FlexIO-simulated UART driver. This enables configuration of the most common settings of the UART with a single function call. The FlexIO-simulated UART does not support the parity check and only supports one stop bit. Te user settings include: UART baud rate, the number of bits per data word, UART work mode(transmit, receive, or both) and the associated FlexIO timers, shifters, and pins for transmit and receive.
FlexIO UART Initialization
-
To initialize the FlexIO UART driver, call the FLEXIO_UART_DRV_Init() function and pass the instance number of the FlexIO peripheral, memory for the run-time state structure, and a pointer to the user configuration structure. For example, to use FlexIO0 pass a value of 0 to the initialization function.
-
Then, pass the memory for the run-time state structure.
-
Finally, pass a user configuration structure of the type flexio_uart_userconfig_t as shown here:
typedef struct flexio_uart_userconfig{
uint32_t baudRate;
flexio_uart_bit_count_per_char_t bitCounter;
flexio_uart_mode_t uartMode;
flexio_uart_hwconfig_t txConfig;
flexio_uart_hwconfig_t rxConfig;
}flexio_uart_userconfig_t;
Typically, the flexio_uart_userconfig instantiation is configured as 8-bit-char(8-n-1) with a 9600 bps baud rate. The flexio_uart_userconfig instantiation can be easily modified to configure the FlexIO UART peripheral driver either to a different baud rate, character transfer features or using different FlexIO hardware resource. This is an example code to set up a user FlexIO UART configuration instantiation:
flexio_uart_userconfig_t uartConfig;
uartConfig.baudRate = 9600;
uartConfig.uartMode = flexioUART_TxRx;
uartConfig.txConfig.pinIdx = 0;
uartConfig.txConfig.shifterIdx = 0;
uartConfig.txConfig.timerIdx = 0;
uartConfig.rxConfig.pinIdx = 1;
uartConfig.rxConfig.shifterIdx = 1;
uartConfig.rxConfig.timerIdx = 1;
This example shows how to call the FLEXIO_UART_DRV_Init() given the user configuration structure and the FlexIO instance 0.
uint32_t flexioInstance = 0;
flexio_uart_state_t uartState;
FLEXIO_UART_DRV_Init(flexioInstance, &uartState, &uartConfig);
FLEXIO UART Transfers
The driver implements transmit and receive functions to transfer buffers of data in blocking and non-blocking modes.
The non-blocking transmit and receive functions include the FLEXIO_UART_DRV_SendData() and FLEXIO_UART_DRV_ReceiveData() functions.
The blocking (async) transmit and receive functions include the FLEXIO_UART_DRV_SendDataBlocking() and FLEXIO_UART_DRV_ReceiveDataBlocking() functions.
Ensure that data is consistent when there is cache in memory and when using DMA to transfer data. In other words, when reading the data from memory, ensure that data from or to the memory device is not cached.
In all cases mentioned here, the functions are interrupt-driven.
This code example shows how to use the functions, assuming that the FlexIO simulated UART module has been initialized as described previously in the Initialization Section.
For blocking transfer functions transmit and receive:
uint8_t sourceBuff[26] ={0};
uint8_t readBuffer[10] = {0};
uint32_t byteCount = sizeof(sourceBuff);
uint32_t rxRemainingSize = sizeof(readBuffer);
FLEXIO_UART_DRV_SendDataBlocking(uartState, sourceBuff, byteCount, 1);
FLEXIO_UART_DRV_ReceiveDataBlocking(uartState, readBuffer, 1, timeoutValue);
For non-blocking (async) transfer functions transmit and receive:
uint8_t *pTxBuff;
uint8_t rxBuff[10];
uint32_t txBytesRemaining, rxBytesRemaining;
FLEXIO_UART_DRV_SendData(uartState, pTxBuff, txSize);
while (FLEXIO_UART_DRV_GetTransmitStatus(uartState, &txBytesRemaining) == kStatus_FlexIO_UART_TxBusy);
FLEXIO_UART_DRV_ReceiveData(uartState, rxBuff, rxSize);
while (FLEXIO_UART_DRV_GetReceiveStatus(uartState, &rxBytesRemaining) == kStatus_FlexIO_UART_RxBusy);
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaInit (uint32_t instance, flexio_uart_dmastate_t *uartDmaState, const flexio_uartdma_userconfig_t *uartDmaConfig) |
| Initializes a FlexIO-simulated UART device to work with DMA. More...
|
|
void | FLEXIO_UART_DRV_DmaDeinit (flexio_uart_dmastate_t *uartDmaState) |
| Shuts down the FlexIO UART. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaSendDataBlocking (flexio_uart_dmastate_t *uartDmaState, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout) |
| Sends (transmits) data out through the FlexIO-simulated UART-DMA module using a blocking method. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaSendData (flexio_uart_dmastate_t *uartDmaState, const uint8_t *txBuff, uint32_t txSize) |
| Sends (transmits) data through the FlexIO-simulated UART-DMA module using a non-blocking method. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaGetTransmitStatus (flexio_uart_dmastate_t *uartDmaState, uint32_t *bytesRemaining) |
| Returns whether the previous FlexIO-simulated UART-DMA transmit has finished. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaAbortSendingData (flexio_uart_dmastate_t *uartDmaState) |
| Terminates a non-blocking FlexIO-simulated UART-DMA transmission early. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaReceiveDataBlocking (flexio_uart_dmastate_t *uartDmaState, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout) |
| Gets (receives) data from the FlexIO-simulated UART-DMA module using a blocking method. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaReceiveData (flexio_uart_dmastate_t *uartDmaState, uint8_t *rxBuff, uint32_t rxSize) |
| Gets (receives) data from the FlexIO-simulated UART-DMA module using a non-blocking method. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaGetReceiveStatus (flexio_uart_dmastate_t *uartDmaState, uint32_t *bytesRemaining) |
| Returns whether the previous FlexIO-simulated UART-DMA receive is complete. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_DmaAbortReceivingData (flexio_uart_dmastate_t *uartDmaState) |
| Terminates a non-blocking FlexIO-simulated UART-DMA receive early. More...
|
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaInit (uint32_t instance, flexio_uart_edmastate_t *uartEdmaState, const flexio_uartedma_userconfig_t *uartEdmaConfig) |
| Initializes a FlexIO-simulated UART device to work with eDMA. More...
|
|
void | FLEXIO_UART_DRV_EdmaDeinit (flexio_uart_edmastate_t *uartEdmaState) |
| Shuts down the FlexIO UART. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaSendDataBlocking (flexio_uart_edmastate_t *uartEdmaState, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout) |
| Sends (transmits) data through the FlexIO-simulated UART eDMA module using a blocking method. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaSendData (flexio_uart_edmastate_t *uartEdmaState, const uint8_t *txBuff, uint32_t txSize) |
| Sends (transmits) data through the FlexIO-simulated UART eDMA module using a non-blocking method. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaGetTransmitStatus (flexio_uart_edmastate_t *uartEdmaState, uint32_t *bytesRemaining) |
| Returns whether the previous FlexIO-simulated UART eDMA transmit has finished. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaAbortSendingData (flexio_uart_edmastate_t *uartEdmaState) |
| Terminates a non-blocking FlexIO-simulated UART eDMA transmission early. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaReceiveDataBlocking (flexio_uart_edmastate_t *uartEdmaState, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout) |
| Gets (receives) data from the FlexIO-simulated UART eDMA module using a blocking method. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaReceiveData (flexio_uart_edmastate_t *uartEdmaState, uint8_t *rxBuff, uint32_t rxSize) |
| Gets (receives) data from the FlexIO-simulated UART eDMA module using a non-blocking method. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaGetReceiveStatus (flexio_uart_edmastate_t *uartEdmaState, uint32_t *bytesRemaining) |
| Returns whether the previous FlexIO-simulated UART eDMA receive is complete. More...
|
|
flexio_uart_status_t | FLEXIO_UART_DRV_EdmaAbortReceivingData (flexio_uart_edmastate_t *uartEdmaState) |
| Terminates a non-blocking FlexIO-simulated UART eDMA receive early. More...
|
|
struct flexio_uart_dmastate_t |
volatile bool flexio_uart_dmastate_t::isTxBusy |
volatile bool flexio_uart_dmastate_t::isRxBusy |
volatile bool flexio_uart_dmastate_t::isTxBlocking |
volatile bool flexio_uart_dmastate_t::isRxBlocking |
struct flexio_uartdma_userconfig_t |
Use an instance of this structure with the FLEXIO_UART_DRV_DmaInit()function. This enables configuration of the most common settings of the UART peripheral with a single function call. Settings include: UART baud rate, UART parity mode: disabled (default), or even or odd, the number of stop bits, and the number of bits per data word.
Data Fields |
uint32_t | baudRate |
| UART baud rate.
|
|
flexio_uart_bit_count_per_char_t | bitCountPerChar |
| number of bits, 5/6/7/8 bits configurable
|
|
flexio_uart_mode_t | uartMode |
| FlexIO UART working modes: Tx only, Rx only, or both.
|
|
flexio_uart_hwconfig_t | txConfig |
| FlexIO UART TX device hardware resource configuration.
|
|
flexio_uart_hwconfig_t | rxConfig |
| FlexIO UART RX device hardware resource configuration.
|
|
struct flexio_uartedma_userconfig_t |
Use an instance of this structure with the FLEXIO_UART_DRV_Init()function to enable configuration of the settings of the FlexIO UART peripheral with a single function call. Settings include: UART baud rate, the number of bits per data word, FlexIO UART mode, transmit hardware resource and receive hardware resource.
struct flexio_uart_edmastate_t |
This structure holds data that is used by the FlexIO UART 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 in the memory for the run-time state structure and the FlexIO UART driver fills out the members.
volatile bool flexio_uart_edmastate_t::isTxBlocking |
volatile bool flexio_uart_edmastate_t::isRxBlocking |
This function initializes the run-time state structure to keep track of the on-going transfers and the module to user-defined settings and default settings. It also configures the underlying FlexIO pin, shifter, and timer resource, and enables the FlexIO simulated UART module DMA interrupt. This example shows how to set up the flexio_uartdma_state_t and the flexio_uartdma_userconfig_t parameters and how to call the FLEXIO_UART_DRV_DmaInit function by passing in these parameters:
uartDmaConfig.
uartMode = flexioUART_TxRx;
- Parameters
-
instance | The FlexIO instance number. |
uartDmaState | A pointer to the global FlexIO UART driver state structure memory. The user passes in the memory for the run-time state structure. The FlexIO UART driver populates the members. This run-time state structure keeps track of the current transfer in progress. |
uartDmaConfig | The user configuration structure of type flexio_uartdma_userconfig_t. The user populates the members of this structure and passes the pointer of this structure to this function. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
This function disables the FlexIO-simulated UART-DMA trigger.
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
flexio_uart_status_t FLEXIO_UART_DRV_DmaSendDataBlocking |
( |
flexio_uart_dmastate_t * |
uartDmaState, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize, |
|
|
uint32_t |
timeout |
|
) |
| |
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
txBuff | A pointer to the source buffer containing 8-bit data chars to send. |
txSize | The number of bytes to send. |
timeout | A timeout value for RTOS abstraction sync control in milliseconds (ms). |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
flexio_uart_status_t FLEXIO_UART_DRV_DmaSendData |
( |
flexio_uart_dmastate_t * |
uartDmaState, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize |
|
) |
| |
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
txBuff | A pointer to the source buffer containing 8-bit data chars to send. |
txSize | The number of bytes to send. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
flexio_uart_status_t FLEXIO_UART_DRV_DmaGetTransmitStatus |
( |
flexio_uart_dmastate_t * |
uartDmaState, |
|
|
uint32_t * |
bytesRemaining |
|
) |
| |
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
bytesRemaining | A pointer to a value that is populated with the number of bytes that are remaining in the active transfer. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
- Return values
-
kStatus_FlexIO_UART_Success | The transmit has completed successfully. |
kStatus_FlexIO_UART_TxBusy | The transmit is still in progress. bytesTransmitted is filled with the number of bytes which are transmitted up to that point. |
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
- Return values
-
kStatus_FlexIO_UART_Success | The transmit was successful. |
kStatus_FlexIO_UART_NoTransmitInProgress | No transmission is currently in progress. |
flexio_uart_status_t FLEXIO_UART_DRV_DmaReceiveDataBlocking |
( |
flexio_uart_dmastate_t * |
uartDmaState, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize, |
|
|
uint32_t |
timeout |
|
) |
| |
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
rxBuff | A pointer to the buffer containing 8-bit read data chars received. |
rxSize | The number of bytes to receive. |
timeout | A timeout value for RTOS abstraction sync control in milliseconds (ms). |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
flexio_uart_status_t FLEXIO_UART_DRV_DmaReceiveData |
( |
flexio_uart_dmastate_t * |
uartDmaState, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize |
|
) |
| |
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
rxBuff | A pointer to the buffer containing 8-bit read data chars received. |
rxSize | The number of bytes to receive. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
flexio_uart_status_t FLEXIO_UART_DRV_DmaGetReceiveStatus |
( |
flexio_uart_dmastate_t * |
uartDmaState, |
|
|
uint32_t * |
bytesRemaining |
|
) |
| |
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
bytesRemaining | A pointer to a value that is populated with the number of bytes which still need to be received in the active transfer. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
- Return values
-
kStatus_FlexIO_UART_Success | The receive has completed successfully. |
kStatus_FlexIO_UART_RxBusy | The receive is still in progress. bytesReceived is filled with the number of bytes which are received up to that point. |
- Parameters
-
uartDmaState | The run-time structure of FlexIO-simulated UART. |
- Returns
- An error code or kStatus_UART_Success.
- Return values
-
kStatus_FlexIO_UART_Success | The receive was successful. |
kStatus_FlexIO_UART_NoTransmitInProgress | No receive is currently in progress. |
This function initializes the run-time state structure to keep track of the on-going transfers, initializes the module to user-defined settings and default settings, configures underlying FlexIO pin, shifter, and timer resource, and enables the FlexIO-simulated UART module eDMA interrupt. This example shows how to set up the flexio_uartedma_state_t and the flexio_uartedma_userconfig_t parameters and how to call the FLEXIO_UART_DRV_EdmaInit function by passing in these parameters:
uartEdmaConfig.baudRate = 9600;
uartEdmaConfig.uartMode = flexioUART_TxRx;
- Parameters
-
instance | The FlexIO instance number. |
uartEdmaState | A pointer to the global FlexIO UART driver state structure memory. The user passes in the memory for the run-time state structure. The FlexIO UART driver populates the members. This run-time state structure keeps track of the current transfer in progress. |
uartEdmaConfig | The user configuration structure of type flexio_uartedma_userconfig_t. The user populates the members of this structure and passes the pointer of this structure to this function. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
This function disables the FlexIO-simulated UART eDMA trigger.
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
flexio_uart_status_t FLEXIO_UART_DRV_EdmaSendDataBlocking |
( |
flexio_uart_edmastate_t * |
uartEdmaState, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize, |
|
|
uint32_t |
timeout |
|
) |
| |
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
txBuff | A pointer to the source buffer containing 8-bit data chars to send. |
txSize | The number of bytes to send. |
timeout | A timeout value for RTOS abstraction sync control in milliseconds (ms). |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
flexio_uart_status_t FLEXIO_UART_DRV_EdmaSendData |
( |
flexio_uart_edmastate_t * |
uartEdmaState, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize |
|
) |
| |
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
txBuff | A pointer to the source buffer containing 8-bit data chars to send. |
txSize | The number of bytes to send. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
flexio_uart_status_t FLEXIO_UART_DRV_EdmaGetTransmitStatus |
( |
flexio_uart_edmastate_t * |
uartEdmaState, |
|
|
uint32_t * |
bytesRemaining |
|
) |
| |
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
bytesRemaining | A pointer to a value that is populated with the number of bytes that are remaining in the active transfer. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
- Return values
-
kStatus_FlexIO_UART_Success | The transmit has completed successfully. |
kStatus_FlexIO_UART_TxBusy | The transmit is still in progress. bytesTransmitted is filled with the number of bytes which are transmitted up to that point. |
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
- Return values
-
kStatus_FlexIO_UART_Success | The transmit was successful. |
kStatus_FlexIO_UART_NoTransmitInProgress | No transmission is currently in progress. |
flexio_uart_status_t FLEXIO_UART_DRV_EdmaReceiveDataBlocking |
( |
flexio_uart_edmastate_t * |
uartEdmaState, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize, |
|
|
uint32_t |
timeout |
|
) |
| |
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
rxBuff | A pointer to the buffer containing 8-bit read data chars received. |
rxSize | The number of bytes to receive. |
timeout | A timeout value for RTOS abstraction sync control in milliseconds (ms). |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
flexio_uart_status_t FLEXIO_UART_DRV_EdmaReceiveData |
( |
flexio_uart_edmastate_t * |
uartEdmaState, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize |
|
) |
| |
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
rxBuff | A pointer to the buffer containing 8-bit read data chars received. |
rxSize | The number of bytes to receive. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
flexio_uart_status_t FLEXIO_UART_DRV_EdmaGetReceiveStatus |
( |
flexio_uart_edmastate_t * |
uartEdmaState, |
|
|
uint32_t * |
bytesRemaining |
|
) |
| |
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
bytesRemaining | A pointer to a value that is populated with the number of bytes which still need to be received in the active transfer. |
- Returns
- An error code or kStatus_FlexIO_UART_Success.
- Return values
-
kStatus_FlexIO_UART_Success | The receive has completed successfully. |
kStatus_FlexIO_UART_RxBusy | The receive is still in progress. bytesReceived is filled with the number of bytes which are received up to that point. |
- Parameters
-
uartEdmaState | The run-time structure of FlexIO-simulated UART. |
- Returns
- An error code or kStatus_UART_Success.
- Return values
-
kStatus_FlexIO_UART_Success | The receive was successful. |
kStatus_FlexIO_UART_NoTransmitInProgress | No receive is currently in progress. |