MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
FlexIO UART Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the Universal Asynchronous Receiver/Transmitter (UART) function using the Flexible I/O.

FlexIO UART driver includes functional APIs and transactional APIs. Functional APIs target low-level APIs. Functional APIs can be used for the FlexIO UART initialization/configuration/operation for optimization/customization purpose. Using the functional APIs requires the knowledge of the FlexIO UART peripheral and how to organize functional APIs to meet the application requirements. All functional API use the FLEXIO_UART_Type * as the first parameter. FlexIO UART functional operation groups provide the functional APIs set.

Transactional APIs target high-level APIs. Transactional APIs can be used to enable the peripheral and also in the application if the code size and performance of transactional APIs satisfy requirements. If the code size and performance are critical requirements, see the transactional API implementation and write custom code. All transactional APIs use the flexio_uart_handle_t as the second parameter. Initialize the handle by calling the FLEXIO_UART_TransferCreateHandle() API.

Transactional APIs support asynchronous transfer. This means that the functions FLEXIO_UART_SendNonBlocking() and FLEXIO_UART_ReceiveNonBlocking() set up an interrupt for data transfer. When the transfer is complete, the upper layer is notified through a callback function with the kStatus_FLEXIO_UART_TxIdle and kStatus_FLEXIO_UART_RxIdle status.

Transactional receive APIs support the ring buffer. Prepare the memory for the ring buffer and pass in the start address and size through calling the FLEXIO_UART_InstallRingBuffer(). When the ring buffer is enabled, the received data is saved to the ring buffer in the background. The function FLEXIO_UART_ReceiveNonBlocking() first gets data the from the ring buffer. If ring buffer does not have enough data, the function returns the data to the ring buffer and saves the received data to user memory. When all data is received, the upper layer is informed through a callback with the statuskStatus_FLEXIO_UART_RxIdle status.

If the receive ring buffer is full, the upper layer is informed through a callback with status kStatus_FLEXIO_UART_RxRingBufferOverrun. In the callback function, the upper layer reads data from the ring buffer. If not, the oldest data is overwritten by the new data.

The ring buffer size is specified when calling the FLEXIO_UART_InstallRingBuffer. Note that one byte is reserved for the ring buffer maintenance. Create a handle as follows.

FLEXIO_UART_InstallRingBuffer(&uartDev, &handle, &ringBuffer, 32);

In this example, the buffer size is 32. However, only 31 bytes are used for saving data.

Typical use case

FlexIO UART send/receive using a polling method

uint8_t ch;
flexio_uart_user_config user_config;
user_config.baudRate_Bps = 115200U;
user_config.enableUart = true;
uartDev.flexioBase = BOARD_FLEXIO_BASE;
uartDev.TxPinIndex = FLEXIO_UART_TX_PIN;
uartDev.RxPinIndex = FLEXIO_UART_RX_PIN;
uartDev.shifterIndex[0] = 0U;
uartDev.shifterIndex[1] = 1U;
uartDev.timerIndex[0] = 0U;
uartDev.timerIndex[1] = 1U;
result = FLEXIO_UART_Init(&uartDev, &user_config, 48000000U);
//Check if configuration is correct.
if(result != kStatus_Success)
{
return;
}
FLEXIO_UART_WriteBlocking(&uartDev, txbuff, sizeof(txbuff));
while(1)
{
FLEXIO_UART_ReadBlocking(&uartDev, &ch, 1);
FLEXIO_UART_WriteBlocking(&uartDev, &ch, 1);
}

FlexIO UART send/receive using an interrupt method

flexio_uart_handle_t g_uartHandle;
volatile bool txFinished;
volatile bool rxFinished;
uint8_t sendData[] = ['H', 'e', 'l', 'l', 'o'];
uint8_t receiveData[32];
void FLEXIO_UART_UserCallback(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, status_t status, void *userData)
{
userData = userData;
{
txFinished = true;
}
{
rxFinished = true;
}
}
void main(void)
{
//...
user_config.baudRate_Bps = 115200U;
user_config.enableUart = true;
uartDev.flexioBase = BOARD_FLEXIO_BASE;
uartDev.TxPinIndex = FLEXIO_UART_TX_PIN;
uartDev.RxPinIndex = FLEXIO_UART_RX_PIN;
uartDev.shifterIndex[0] = 0U;
uartDev.shifterIndex[1] = 1U;
uartDev.timerIndex[0] = 0U;
uartDev.timerIndex[1] = 1U;
result = FLEXIO_UART_Init(&uartDev, &user_config, 120000000U);
//Check if configuration is correct.
if(result != kStatus_Success)
{
return;
}
FLEXIO_UART_TransferCreateHandle(&uartDev, &g_uartHandle, FLEXIO_UART_UserCallback, NULL);
// Prepares to send.
sendXfer.data = sendData;
sendXfer.dataSize = sizeof(sendData)/sizeof(sendData[0]);
txFinished = false;
// Sends out.
FLEXIO_UART_SendNonBlocking(&uartDev, &g_uartHandle, &sendXfer);
// Send finished.
while (!txFinished)
{
}
// Prepares to receive.
receiveXfer.data = receiveData;
receiveXfer.dataSize = sizeof(receiveData)/sizeof(receiveData[0]);
rxFinished = false;
// Receives.
FLEXIO_UART_ReceiveNonBlocking(&uartDev, &g_uartHandle, &receiveXfer, NULL);
// Receive finished.
while (!rxFinished)
{
}
// ...
}

FlexIO UART receive using the ringbuffer feature

#define RING_BUFFER_SIZE 64
#define RX_DATA_SIZE 32
flexio_uart_handle_t g_uartHandle;
volatile bool txFinished;
volatile bool rxFinished;
uint8_t receiveData[RX_DATA_SIZE];
uint8_t ringBuffer[RING_BUFFER_SIZE];
void FLEXIO_UART_UserCallback(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, status_t status, void *userData)
{
userData = userData;
{
rxFinished = true;
}
}
void main(void)
{
size_t bytesRead;
//...
user_config.baudRate_Bps = 115200U;
user_config.enableUart = true;
uartDev.flexioBase = BOARD_FLEXIO_BASE;
uartDev.TxPinIndex = FLEXIO_UART_TX_PIN;
uartDev.RxPinIndex = FLEXIO_UART_RX_PIN;
uartDev.shifterIndex[0] = 0U;
uartDev.shifterIndex[1] = 1U;
uartDev.timerIndex[0] = 0U;
uartDev.timerIndex[1] = 1U;
result = FLEXIO_UART_Init(&uartDev, &user_config, 48000000U);
//Check if configuration is correct.
if(result != kStatus_Success)
{
return;
}
FLEXIO_UART_TransferCreateHandle(&uartDev, &g_uartHandle, FLEXIO_UART_UserCallback, NULL);
FLEXIO_UART_InstallRingBuffer(&uartDev, &g_uartHandle, ringBuffer, RING_BUFFER_SIZE);
// Receive is working in the background to the ring buffer.
// Prepares to receive.
receiveXfer.data = receiveData;
receiveXfer.dataSize = RX_DATA_SIZE;
rxFinished = false;
// Receives.
FLEXIO_UART_ReceiveNonBlocking(&uartDev, &g_uartHandle, &receiveXfer, &bytesRead);
if (bytesRead = RX_DATA_SIZE) /* Have read enough data. */
{
;
}
else
{
if (bytesRead) /* Received some data, process first. */
{
;
}
// Receive finished.
while (!rxFinished)
{
}
}
// ...
}

FlexIO UART send/receive using a DMA method

flexio_uart_handle_t g_uartHandle;
dma_handle_t g_uartTxDmaHandle;
dma_handle_t g_uartRxDmaHandle;
flexio_uart_config_t user_config;
volatile bool txFinished;
volatile bool rxFinished;
uint8_t sendData[] = ['H', 'e', 'l', 'l', 'o'];
uint8_t receiveData[32];
void FLEXIO_UART_UserCallback(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, status_t status, void *userData)
{
userData = userData;
{
txFinished = true;
}
{
rxFinished = true;
}
}
void main(void)
{
//...
user_config.baudRate_Bps = 115200U;
user_config.enableUart = true;
uartDev.flexioBase = BOARD_FLEXIO_BASE;
uartDev.TxPinIndex = FLEXIO_UART_TX_PIN;
uartDev.RxPinIndex = FLEXIO_UART_RX_PIN;
uartDev.shifterIndex[0] = 0U;
uartDev.shifterIndex[1] = 1U;
uartDev.timerIndex[0] = 0U;
uartDev.timerIndex[1] = 1U;
result = FLEXIO_UART_Init(&uartDev, &user_config, 48000000U);
//Check if configuration is correct.
if(result != kStatus_Success)
{
return;
}
/* Init DMAMUX. */
DMAMUX_Init(EXAMPLE_FLEXIO_UART_DMAMUX_BASEADDR)
/* Init the DMA/EDMA module */
#if defined(FSL_FEATURE_SOC_DMA_COUNT) && FSL_FEATURE_SOC_DMA_COUNT > 0U
DMA_Init(EXAMPLE_FLEXIO_UART_DMA_BASEADDR);
DMA_CreateHandle(&g_uartTxDmaHandle, EXAMPLE_FLEXIO_UART_DMA_BASEADDR, FLEXIO_UART_TX_DMA_CHANNEL);
DMA_CreateHandle(&g_uartRxDmaHandle, EXAMPLE_FLEXIO_UART_DMA_BASEADDR, FLEXIO_UART_RX_DMA_CHANNEL);
#endif /* FSL_FEATURE_SOC_DMA_COUNT */
#if defined(FSL_FEATURE_SOC_EDMA_COUNT) && FSL_FEATURE_SOC_EDMA_COUNT > 0U
edma_config_t edmaConfig;
EDMA_GetDefaultConfig(&edmaConfig);
EDMA_Init(EXAMPLE_FLEXIO_UART_DMA_BASEADDR, &edmaConfig);
EDMA_CreateHandle(&g_uartTxDmaHandle, EXAMPLE_FLEXIO_UART_DMA_BASEADDR, FLEXIO_UART_TX_DMA_CHANNEL);
EDMA_CreateHandle(&g_uartRxDmaHandle, EXAMPLE_FLEXIO_UART_DMA_BASEADDR, FLEXIO_UART_RX_DMA_CHANNEL);
#endif /* FSL_FEATURE_SOC_EDMA_COUNT */
dma_request_source_tx = (dma_request_source_t)(FLEXIO_DMA_REQUEST_BASE + uartDev.shifterIndex[0]);
dma_request_source_rx = (dma_request_source_t)(FLEXIO_DMA_REQUEST_BASE + uartDev.shifterIndex[1]);
/* Requests DMA channels for transmit and receive. */
DMAMUX_SetSource(EXAMPLE_FLEXIO_UART_DMAMUX_BASEADDR, FLEXIO_UART_TX_DMA_CHANNEL, (dma_request_source_t)dma_request_source_tx);
DMAMUX_SetSource(EXAMPLE_FLEXIO_UART_DMAMUX_BASEADDR, FLEXIO_UART_RX_DMA_CHANNEL, (dma_request_source_t)dma_request_source_rx);
DMAMUX_EnableChannel(EXAMPLE_FLEXIO_UART_DMAMUX_BASEADDR, FLEXIO_UART_TX_DMA_CHANNEL);
DMAMUX_EnableChannel(EXAMPLE_FLEXIO_UART_DMAMUX_BASEADDR, FLEXIO_UART_RX_DMA_CHANNEL);
FLEXIO_UART_TransferCreateHandleDMA(&uartDev, &g_uartHandle, FLEXIO_UART_UserCallback, NULL, &g_uartTxDmaHandle, &g_uartRxDmaHandle);
// Prepares to send.
sendXfer.data = sendData
sendXfer.dataSize = sizeof(sendData)/sizeof(sendData[0]);
txFinished = false;
// Sends out.
FLEXIO_UART_SendDMA(&uartDev, &g_uartHandle, &sendXfer);
// Send finished.
while (!txFinished)
{
}
// Prepares to receive.
receiveXfer.data = receiveData;
receiveXfer.dataSize = sizeof(receiveData)/sizeof(receiveData[0]);
rxFinished = false;
// Receives.
FLEXIO_UART_ReceiveDMA(&uartDev, &g_uartHandle, &receiveXfer, NULL);
// Receive finished.
while (!rxFinished)
{
}
// ...
}

Modules

 FlexIO eDMA UART Driver
 

Data Structures

struct  FLEXIO_UART_Type
 Define FlexIO UART access structure typedef. More...
 
struct  flexio_uart_config_t
 Define FlexIO UART user configuration structure. More...
 
struct  flexio_uart_transfer_t
 Define FlexIO UART transfer structure. More...
 
struct  flexio_uart_handle_t
 Define FLEXIO UART handle structure. More...
 

Macros

#define UART_RETRY_TIMES   0U /* Defining to zero means to keep waiting for the flag until it is assert/deassert. */
 Retry times for waiting flag. More...
 

Typedefs

typedef void(* flexio_uart_transfer_callback_t )(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, status_t status, void *userData)
 FlexIO UART transfer callback function. More...
 

Enumerations

enum  {
  kStatus_FLEXIO_UART_TxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 0),
  kStatus_FLEXIO_UART_RxBusy = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 1),
  kStatus_FLEXIO_UART_TxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 2),
  kStatus_FLEXIO_UART_RxIdle = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 3),
  kStatus_FLEXIO_UART_ERROR = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 4),
  kStatus_FLEXIO_UART_RxRingBufferOverrun,
  kStatus_FLEXIO_UART_RxHardwareOverrun = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 6),
  kStatus_FLEXIO_UART_Timeout = MAKE_STATUS(kStatusGroup_FLEXIO_UART, 7)
}
 Error codes for the UART driver. More...
 
enum  flexio_uart_bit_count_per_char_t {
  kFLEXIO_UART_7BitsPerChar = 7U,
  kFLEXIO_UART_8BitsPerChar = 8U,
  kFLEXIO_UART_9BitsPerChar = 9U
}
 FlexIO UART bit count per char. More...
 
enum  _flexio_uart_interrupt_enable {
  kFLEXIO_UART_TxDataRegEmptyInterruptEnable = 0x1U,
  kFLEXIO_UART_RxDataRegFullInterruptEnable = 0x2U
}
 Define FlexIO UART interrupt mask. More...
 
enum  _flexio_uart_status_flags {
  kFLEXIO_UART_TxDataRegEmptyFlag = 0x1U,
  kFLEXIO_UART_RxDataRegFullFlag = 0x2U,
  kFLEXIO_UART_RxOverRunFlag = 0x4U
}
 Define FlexIO UART status mask. More...
 

Driver version

#define FSL_FLEXIO_UART_DRIVER_VERSION   (MAKE_VERSION(2, 2, 0))
 FlexIO UART driver version 2.2.0. More...
 

Initialization and deinitialization

status_t FLEXIO_UART_Init (FLEXIO_UART_Type *base, const flexio_uart_config_t *userConfig, uint32_t srcClock_Hz)
 Ungates the FlexIO clock, resets the FlexIO module, configures FlexIO UART hardware, and configures the FlexIO UART with FlexIO UART configuration. More...
 
void FLEXIO_UART_Deinit (FLEXIO_UART_Type *base)
 Resets the FlexIO UART shifter and timer config. More...
 
void FLEXIO_UART_GetDefaultConfig (flexio_uart_config_t *userConfig)
 Gets the default configuration to configure the FlexIO UART. More...
 

Status

uint32_t FLEXIO_UART_GetStatusFlags (FLEXIO_UART_Type *base)
 Gets the FlexIO UART status flags. More...
 
void FLEXIO_UART_ClearStatusFlags (FLEXIO_UART_Type *base, uint32_t mask)
 Gets the FlexIO UART status flags. More...
 

Interrupts

void FLEXIO_UART_EnableInterrupts (FLEXIO_UART_Type *base, uint32_t mask)
 Enables the FlexIO UART interrupt. More...
 
void FLEXIO_UART_DisableInterrupts (FLEXIO_UART_Type *base, uint32_t mask)
 Disables the FlexIO UART interrupt. More...
 

DMA Control

static uint32_t FLEXIO_UART_GetTxDataRegisterAddress (FLEXIO_UART_Type *base)
 Gets the FlexIO UARt transmit data register address. More...
 
static uint32_t FLEXIO_UART_GetRxDataRegisterAddress (FLEXIO_UART_Type *base)
 Gets the FlexIO UART receive data register address. More...
 
static void FLEXIO_UART_EnableTxDMA (FLEXIO_UART_Type *base, bool enable)
 Enables/disables the FlexIO UART transmit DMA. More...
 
static void FLEXIO_UART_EnableRxDMA (FLEXIO_UART_Type *base, bool enable)
 Enables/disables the FlexIO UART receive DMA. More...
 

Bus Operations

static void FLEXIO_UART_Enable (FLEXIO_UART_Type *base, bool enable)
 Enables/disables the FlexIO UART module operation. More...
 
static void FLEXIO_UART_WriteByte (FLEXIO_UART_Type *base, const uint8_t *buffer)
 Writes one byte of data. More...
 
static void FLEXIO_UART_ReadByte (FLEXIO_UART_Type *base, uint8_t *buffer)
 Reads one byte of data. More...
 
status_t FLEXIO_UART_WriteBlocking (FLEXIO_UART_Type *base, const uint8_t *txData, size_t txSize)
 Sends a buffer of data bytes. More...
 
status_t FLEXIO_UART_ReadBlocking (FLEXIO_UART_Type *base, uint8_t *rxData, size_t rxSize)
 Receives a buffer of bytes. More...
 

Transactional

status_t FLEXIO_UART_TransferCreateHandle (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, flexio_uart_transfer_callback_t callback, void *userData)
 Initializes the UART handle. More...
 
void FLEXIO_UART_TransferStartRingBuffer (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize)
 Sets up the RX ring buffer. More...
 
void FLEXIO_UART_TransferStopRingBuffer (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle)
 Aborts the background transfer and uninstalls the ring buffer. More...
 
status_t FLEXIO_UART_TransferSendNonBlocking (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, flexio_uart_transfer_t *xfer)
 Transmits a buffer of data using the interrupt method. More...
 
void FLEXIO_UART_TransferAbortSend (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle)
 Aborts the interrupt-driven data transmit. More...
 
status_t FLEXIO_UART_TransferGetSendCount (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, size_t *count)
 Gets the number of bytes sent. More...
 
status_t FLEXIO_UART_TransferReceiveNonBlocking (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, flexio_uart_transfer_t *xfer, size_t *receivedBytes)
 Receives a buffer of data using the interrupt method. More...
 
void FLEXIO_UART_TransferAbortReceive (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle)
 Aborts the receive data which was using IRQ. More...
 
status_t FLEXIO_UART_TransferGetReceiveCount (FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, size_t *count)
 Gets the number of bytes received. More...
 
void FLEXIO_UART_TransferHandleIRQ (void *uartType, void *uartHandle)
 FlexIO UART IRQ handler function. More...
 

Data Structure Documentation

struct FLEXIO_UART_Type

Data Fields

FLEXIO_Type * flexioBase
 FlexIO base pointer. More...
 
uint8_t TxPinIndex
 Pin select for UART_Tx. More...
 
uint8_t RxPinIndex
 Pin select for UART_Rx. More...
 
uint8_t shifterIndex [2]
 Shifter index used in FlexIO UART. More...
 
uint8_t timerIndex [2]
 Timer index used in FlexIO UART. More...
 

Field Documentation

FLEXIO_Type* FLEXIO_UART_Type::flexioBase
uint8_t FLEXIO_UART_Type::TxPinIndex
uint8_t FLEXIO_UART_Type::RxPinIndex
uint8_t FLEXIO_UART_Type::shifterIndex[2]
uint8_t FLEXIO_UART_Type::timerIndex[2]
struct flexio_uart_config_t

Data Fields

bool enableUart
 Enable/disable FlexIO UART TX & RX. More...
 
bool enableInDoze
 Enable/disable FlexIO operation in doze mode.
 
bool enableInDebug
 Enable/disable FlexIO operation in debug mode.
 
bool enableFastAccess
 
Enable/disable fast access to FlexIO registers,

fast access requires the FlexIO clock to be at least twice the frequency of the bus clock. More...

 
uint32_t baudRate_Bps
 Baud rate in Bps. More...
 
flexio_uart_bit_count_per_char_t bitCountPerChar
 number of bits, 7/8/9 -bit
 

Field Documentation

bool flexio_uart_config_t::enableUart
bool flexio_uart_config_t::enableFastAccess
uint32_t flexio_uart_config_t::baudRate_Bps
struct flexio_uart_transfer_t

Data Fields

uint8_t * data
 Transfer buffer.
 
size_t dataSize
 Transfer size.
 
struct _flexio_uart_handle

Data Fields

uint8_t *volatile txData
 Address of remaining data to send. More...
 
volatile size_t txDataSize
 Size of the remaining data to send. More...
 
uint8_t *volatile rxData
 Address of remaining data to receive. More...
 
volatile size_t rxDataSize
 Size of the remaining data to receive. More...
 
size_t txDataSizeAll
 Total bytes to be sent. More...
 
size_t rxDataSizeAll
 Total bytes to be received. More...
 
uint8_t * rxRingBuffer
 Start address of the receiver ring buffer. More...
 
size_t rxRingBufferSize
 Size of the ring buffer. More...
 
volatile uint16_t rxRingBufferHead
 Index for the driver to store received data into ring buffer. More...
 
volatile uint16_t rxRingBufferTail
 Index for the user to get data from the ring buffer. More...
 
flexio_uart_transfer_callback_t callback
 Callback function. More...
 
void * userData
 UART callback function parameter. More...
 
volatile uint8_t txState
 TX transfer state. More...
 
volatile uint8_t rxState
 RX transfer state.
 

Field Documentation

uint8_t* volatile flexio_uart_handle_t::txData
volatile size_t flexio_uart_handle_t::txDataSize
uint8_t* volatile flexio_uart_handle_t::rxData
volatile size_t flexio_uart_handle_t::rxDataSize
size_t flexio_uart_handle_t::txDataSizeAll
size_t flexio_uart_handle_t::rxDataSizeAll
uint8_t* flexio_uart_handle_t::rxRingBuffer
size_t flexio_uart_handle_t::rxRingBufferSize
volatile uint16_t flexio_uart_handle_t::rxRingBufferHead
volatile uint16_t flexio_uart_handle_t::rxRingBufferTail
flexio_uart_transfer_callback_t flexio_uart_handle_t::callback
void* flexio_uart_handle_t::userData
volatile uint8_t flexio_uart_handle_t::txState

Macro Definition Documentation

#define FSL_FLEXIO_UART_DRIVER_VERSION   (MAKE_VERSION(2, 2, 0))
#define UART_RETRY_TIMES   0U /* Defining to zero means to keep waiting for the flag until it is assert/deassert. */

Typedef Documentation

typedef void(* flexio_uart_transfer_callback_t)(FLEXIO_UART_Type *base, flexio_uart_handle_t *handle, status_t status, void *userData)

Enumeration Type Documentation

anonymous enum
Enumerator
kStatus_FLEXIO_UART_TxBusy 

Transmitter is busy.

kStatus_FLEXIO_UART_RxBusy 

Receiver is busy.

kStatus_FLEXIO_UART_TxIdle 

UART transmitter is idle.

kStatus_FLEXIO_UART_RxIdle 

UART receiver is idle.

kStatus_FLEXIO_UART_ERROR 

ERROR happens on UART.

kStatus_FLEXIO_UART_RxRingBufferOverrun 

UART RX software ring buffer overrun.

kStatus_FLEXIO_UART_RxHardwareOverrun 

UART RX receiver overrun.

kStatus_FLEXIO_UART_Timeout 

UART times out.

Enumerator
kFLEXIO_UART_7BitsPerChar 

7-bit data characters

kFLEXIO_UART_8BitsPerChar 

8-bit data characters

kFLEXIO_UART_9BitsPerChar 

9-bit data characters

Enumerator
kFLEXIO_UART_TxDataRegEmptyInterruptEnable 

Transmit buffer empty interrupt enable.

kFLEXIO_UART_RxDataRegFullInterruptEnable 

Receive buffer full interrupt enable.

Enumerator
kFLEXIO_UART_TxDataRegEmptyFlag 

Transmit buffer empty flag.

kFLEXIO_UART_RxDataRegFullFlag 

Receive buffer full flag.

kFLEXIO_UART_RxOverRunFlag 

Receive buffer over run flag.

Function Documentation

status_t FLEXIO_UART_Init ( FLEXIO_UART_Type base,
const flexio_uart_config_t userConfig,
uint32_t  srcClock_Hz 
)

The configuration structure can be filled by the user or be set with default values by FLEXIO_UART_GetDefaultConfig().

Example

.flexioBase = FLEXIO,
.TxPinIndex = 0,
.RxPinIndex = 1,
.shifterIndex = {0,1},
.timerIndex = {0,1}
};
.enableInDoze = false,
.enableInDebug = true,
.enableFastAccess = false,
.baudRate_Bps = 115200U,
.bitCountPerChar = 8
};
FLEXIO_UART_Init(base, &config, srcClock_Hz);
Parameters
basePointer to the FLEXIO_UART_Type structure.
userConfigPointer to the flexio_uart_config_t structure.
srcClock_HzFlexIO source clock in Hz.
Return values
kStatus_SuccessConfiguration success
kStatus_InvalidArgumentBuadrate configuration out of range
void FLEXIO_UART_Deinit ( FLEXIO_UART_Type base)
Note
After calling this API, call the FLEXO_UART_Init to use the FlexIO UART module.
Parameters
basePointer to FLEXIO_UART_Type structure
void FLEXIO_UART_GetDefaultConfig ( flexio_uart_config_t userConfig)

The configuration can be used directly for calling the FLEXIO_UART_Init(). Example:

Parameters
userConfigPointer to the flexio_uart_config_t structure.
uint32_t FLEXIO_UART_GetStatusFlags ( FLEXIO_UART_Type base)
Parameters
basePointer to the FLEXIO_UART_Type structure.
Returns
FlexIO UART status flags.
void FLEXIO_UART_ClearStatusFlags ( FLEXIO_UART_Type base,
uint32_t  mask 
)
Parameters
basePointer to the FLEXIO_UART_Type structure.
maskStatus flag. The parameter can be any combination of the following values:
  • kFLEXIO_UART_TxDataRegEmptyFlag
  • kFLEXIO_UART_RxEmptyFlag
  • kFLEXIO_UART_RxOverRunFlag
void FLEXIO_UART_EnableInterrupts ( FLEXIO_UART_Type base,
uint32_t  mask 
)

This function enables the FlexIO UART interrupt.

Parameters
basePointer to the FLEXIO_UART_Type structure.
maskInterrupt source.
void FLEXIO_UART_DisableInterrupts ( FLEXIO_UART_Type base,
uint32_t  mask 
)

This function disables the FlexIO UART interrupt.

Parameters
basePointer to the FLEXIO_UART_Type structure.
maskInterrupt source.
static uint32_t FLEXIO_UART_GetTxDataRegisterAddress ( FLEXIO_UART_Type base)
inlinestatic

This function returns the UART data register address, which is mainly used by DMA/eDMA.

Parameters
basePointer to the FLEXIO_UART_Type structure.
Returns
FlexIO UART transmit data register address.
static uint32_t FLEXIO_UART_GetRxDataRegisterAddress ( FLEXIO_UART_Type base)
inlinestatic

This function returns the UART data register address, which is mainly used by DMA/eDMA.

Parameters
basePointer to the FLEXIO_UART_Type structure.
Returns
FlexIO UART receive data register address.
static void FLEXIO_UART_EnableTxDMA ( FLEXIO_UART_Type base,
bool  enable 
)
inlinestatic

This function enables/disables the FlexIO UART Tx DMA, which means asserting the kFLEXIO_UART_TxDataRegEmptyFlag does/doesn't trigger the DMA request.

Parameters
basePointer to the FLEXIO_UART_Type structure.
enableTrue to enable, false to disable.
static void FLEXIO_UART_EnableRxDMA ( FLEXIO_UART_Type base,
bool  enable 
)
inlinestatic

This function enables/disables the FlexIO UART Rx DMA, which means asserting kFLEXIO_UART_RxDataRegFullFlag does/doesn't trigger the DMA request.

Parameters
basePointer to the FLEXIO_UART_Type structure.
enableTrue to enable, false to disable.
static void FLEXIO_UART_Enable ( FLEXIO_UART_Type base,
bool  enable 
)
inlinestatic
Parameters
basePointer to the FLEXIO_UART_Type.
enableTrue to enable, false does not have any effect.
static void FLEXIO_UART_WriteByte ( FLEXIO_UART_Type base,
const uint8_t *  buffer 
)
inlinestatic
Note
This is a non-blocking API, which returns directly after the data is put into the data register. Ensure that the TxEmptyFlag is asserted before calling this API.
Parameters
basePointer to the FLEXIO_UART_Type structure.
bufferThe data bytes to send.
static void FLEXIO_UART_ReadByte ( FLEXIO_UART_Type base,
uint8_t *  buffer 
)
inlinestatic
Note
This is a non-blocking API, which returns directly after the data is read from the data register. Ensure that the RxFullFlag is asserted before calling this API.
Parameters
basePointer to the FLEXIO_UART_Type structure.
bufferThe buffer to store the received bytes.
status_t FLEXIO_UART_WriteBlocking ( FLEXIO_UART_Type base,
const uint8_t *  txData,
size_t  txSize 
)
Note
This function blocks using the polling method until all bytes have been sent.
Parameters
basePointer to the FLEXIO_UART_Type structure.
txDataThe data bytes to send.
txSizeThe number of data bytes to send.
Return values
kStatus_FLEXIO_UART_TimeoutTransmission timed out and was aborted.
kStatus_SuccessSuccessfully wrote all data.
status_t FLEXIO_UART_ReadBlocking ( FLEXIO_UART_Type base,
uint8_t *  rxData,
size_t  rxSize 
)
Note
This function blocks using the polling method until all bytes have been received.
Parameters
basePointer to the FLEXIO_UART_Type structure.
rxDataThe buffer to store the received bytes.
rxSizeThe number of data bytes to be received.
Return values
kStatus_FLEXIO_UART_TimeoutTransmission timed out and was aborted.
kStatus_SuccessSuccessfully received all data.
status_t FLEXIO_UART_TransferCreateHandle ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle,
flexio_uart_transfer_callback_t  callback,
void *  userData 
)

This function initializes the FlexIO UART handle, which can be used for other FlexIO UART transactional APIs. Call this API once to get the initialized handle.

The UART driver supports the "background" receiving, which means that users can set up a RX ring buffer optionally. Data received is stored into the ring buffer even when the user doesn't call the FLEXIO_UART_TransferReceiveNonBlocking() API. If there is already data received in the ring buffer, users can get the received data from the ring buffer directly. The ring buffer is disabled if passing NULL as ringBuffer.

Parameters
baseto FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
callbackThe callback function.
userDataThe parameter of the callback function.
Return values
kStatus_SuccessSuccessfully create the handle.
kStatus_OutOfRangeThe FlexIO type/handle/ISR table out of range.
void FLEXIO_UART_TransferStartRingBuffer ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle,
uint8_t *  ringBuffer,
size_t  ringBufferSize 
)

This function sets up the RX ring buffer to a specific UART handle.

When the RX ring buffer is used, data received is stored into the ring buffer even when the user doesn't call the UART_ReceiveNonBlocking() API. If there is already data received in the ring buffer, users can get the received data from the ring buffer directly.

Note
When using the RX ring buffer, one byte is reserved for internal use. In other words, if ringBufferSize is 32, only 31 bytes are used for saving data.
Parameters
basePointer to the FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
ringBufferStart address of ring buffer for background receiving. Pass NULL to disable the ring buffer.
ringBufferSizeSize of the ring buffer.
void FLEXIO_UART_TransferStopRingBuffer ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle 
)

This function aborts the background transfer and uninstalls the ring buffer.

Parameters
basePointer to the FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
status_t FLEXIO_UART_TransferSendNonBlocking ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle,
flexio_uart_transfer_t xfer 
)

This function sends data using an interrupt method. This is a non-blocking function, which returns directly without waiting for all data to be written to the TX register. When all data is written to the TX register in ISR, the FlexIO UART driver calls the callback function and passes the kStatus_FLEXIO_UART_TxIdle as status parameter.

Note
The kStatus_FLEXIO_UART_TxIdle is passed to the upper layer when all data is written to the TX register. However, it does not ensure that all data is sent out.
Parameters
basePointer to the FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
xferFlexIO UART transfer structure. See flexio_uart_transfer_t.
Return values
kStatus_SuccessSuccessfully starts the data transmission.
kStatus_UART_TxBusyPrevious transmission still not finished, data not written to the TX register.
void FLEXIO_UART_TransferAbortSend ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle 
)

This function aborts the interrupt-driven data sending. Get the remainBytes to find out how many bytes are still not sent out.

Parameters
basePointer to the FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
status_t FLEXIO_UART_TransferGetSendCount ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle,
size_t *  count 
)

This function gets the number of bytes sent driven by interrupt.

Parameters
basePointer to the FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
countNumber of bytes sent so far by the non-blocking transaction.
Return values
kStatus_NoTransferInProgresstransfer has finished or no transfer in progress.
kStatus_SuccessSuccessfully return the count.
status_t FLEXIO_UART_TransferReceiveNonBlocking ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle,
flexio_uart_transfer_t xfer,
size_t *  receivedBytes 
)

This function receives data using the interrupt method. This is a non-blocking function, which returns without waiting for all data to be received. If the RX ring buffer is used and not empty, the data in ring buffer is copied and the parameter receivedBytes shows how many bytes are copied from the ring buffer. After copying, if the data in ring buffer is not enough to read, the receive request is saved by the UART driver. When new data arrives, the receive request is serviced first. When all data is received, the UART driver notifies the upper layer through a callback function and passes the status parameter kStatus_UART_RxIdle. For example, if the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer, the 5 bytes are copied to xfer->data. This function returns with the parameter receivedBytes set to 5. For the last 5 bytes, newly arrived data is saved from the xfer->data[5]. When 5 bytes are received, the UART driver notifies upper layer. If the RX ring buffer is not enabled, this function enables the RX and RX interrupt to receive data to xfer->data. When all data is received, the upper layer is notified.

Parameters
basePointer to the FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
xferUART transfer structure. See flexio_uart_transfer_t.
receivedBytesBytes received from the ring buffer directly.
Return values
kStatus_SuccessSuccessfully queue the transfer into the transmit queue.
kStatus_FLEXIO_UART_RxBusyPrevious receive request is not finished.
void FLEXIO_UART_TransferAbortReceive ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle 
)

This function aborts the receive data which was using IRQ.

Parameters
basePointer to the FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
status_t FLEXIO_UART_TransferGetReceiveCount ( FLEXIO_UART_Type base,
flexio_uart_handle_t *  handle,
size_t *  count 
)

This function gets the number of bytes received driven by interrupt.

Parameters
basePointer to the FLEXIO_UART_Type structure.
handlePointer to the flexio_uart_handle_t structure to store the transfer state.
countNumber of bytes received so far by the non-blocking transaction.
Return values
kStatus_NoTransferInProgresstransfer has finished or no transfer in progress.
kStatus_SuccessSuccessfully return the count.
void FLEXIO_UART_TransferHandleIRQ ( void *  uartType,
void *  uartHandle 
)

This function processes the FlexIO UART transmit and receives the IRQ request.

Parameters
uartTypePointer to the FLEXIO_UART_Type structure.
uartHandlePointer to the flexio_uart_handle_t structure to store the transfer state.