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

Overview

The MCUXpresso SDK provides a peripheral driver for the Low Power UART (UART) module of MCUXpresso SDK devices.

Typical use case

UART Operation

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/uart

Data Structures

struct  uart_fifo_config_t
 UART FIFO Configuration Structure definition. More...
 
struct  uart_autobaud_config_t
 UART Auto baud detect and set Configuration Structure definition. More...
 
struct  uart_infrared_config_t
 UART Infrared Configuration Structure type definition. More...
 
struct  uart_config_t
 UART configuration structure. More...
 
struct  uart_handle_t
 UART transfer handle. More...
 
struct  uart_transfer_t
 UART transfer structure. More...
 

Macros

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

Typedefs

typedef void(* uart_transfer_callback_t )(UART_Type *base, uart_handle_t *handle, status_t status, void *userData)
 UART interrupt transfer callback function definition. More...
 

Enumerations

enum  {
  kStatus_UART_TxBusy = MAKE_STATUS(kStatusGroup_UART, 0),
  kStatus_UART_RxBusy = MAKE_STATUS(kStatusGroup_UART, 1),
  kStatus_UART_TxIdle = MAKE_STATUS(kStatusGroup_UART, 2),
  kStatus_UART_RxIdle = MAKE_STATUS(kStatusGroup_UART, 3),
  kStatus_UART_FlagCannotClearManually = MAKE_STATUS(kStatusGroup_UART, 4),
  kStatus_UART_Error = MAKE_STATUS(kStatusGroup_UART, 5),
  kStatus_UART_RxRingBufferOverrun = MAKE_STATUS(kStatusGroup_UART, 6),
  kStatus_UART_RxHardwareOverrun = MAKE_STATUS(kStatusGroup_UART, 7),
  kStatus_UART_FifoError = MAKE_STATUS(kStatusGroup_UART, 8),
  kStatus_UART_FramingError = MAKE_STATUS(kStatusGroup_UART, 9),
  kStatus_UART_ParityError = MAKE_STATUS(kStatusGroup_UART, 10),
  kStatus_UART_BaudrateNotSupport,
  kStatus_UART_IdleLineDetected = MAKE_STATUS(kStatusGroup_UART, 12),
  kStatus_UART_Timeout = MAKE_STATUS(kStatusGroup_UART, 13),
  kStatus_UART_RxFifoError = MAKE_STATUS(kStatusGroup_UART, 14)
}
 Error codes for the UART driver. More...
 
enum  _uart_interrupt_enable {
  kUART_RxDataReadyInterruptEnable,
  kUART_TxDataRequestInterruptEnable,
  kUART_RxStatusInterruptEnable,
  kUART_ModemStatusChangeInterruptEnable,
  kUART_RxTimeoutInterruptEnable = (UART_IER_RTOIE_MASK),
  kUART_AutoBaudCompleteInterruptEnable
}
 UART interrupt configuration structure, default settings all disabled. More...
 
enum  _uart_status_flags {
  kUART_RxDataReadyInterruptFlag,
  kUART_RxOverrunInterruptFlag = (UART_LSR_OE_MASK),
  kUART_ParityErrorInterruptFlag = (UART_LSR_PE_MASK),
  kUART_FramingErrorInterruptFLag,
  kUART_BreakDetectInterruptFlag = (UART_LSR_BI_MASK),
  kUART_TxDataRequestInterruptFlag,
  kUART_TxEmptyInterruptFlag,
  kUART_FifoErrorInterruptFlag,
  kUART_RxTimeoutInterruptFlag = (UART_IIR_TOD_MASK << 8),
  kUART_AutoBaudCompleteInterruptFlag
}
 UART status flags. More...
 
enum  uart_parity_mode_t {
  kUART_ParityDisabled = 0x0U,
  kUART_ParityOdd = 0x1U,
  kUART_ParityEven = 0x2U
}
 UART parity mode. More...
 
enum  uart_data_bits_t {
  kUART_Databits5 = 0x0U,
  kUART_Databits6,
  kUART_Databits7,
  kUART_Databits8
}
 UART data bits count. More...
 
enum  uart_stop_bit_count_t {
  kUART_Stopbits1,
  kUART_Stopbits2
}
 UART stop bit count. More...
 
enum  uart_txfifo_watermark_t {
  kUART_TxfifoHalfEmpty = 0U,
  kUART_TxfifoEmpty
}
 UART TX FIFO watermark level definition. More...
 
enum  uart_rxfifo_watermark_t {
  kUART_RxfifoByte1 = 0U,
  kUART_RxfifoBytes8,
  kUART_RxfifoBytes16,
  kUART_RxfifoBytes32
}
 UART RX FIFO watermark level definition. More...
 
enum  uart_autobaud_program_t {
  kUART_BaudrateProgramManual = 0,
  kUART_BaudrateProgramAuto
}
 UART Auto Baud Calculation type definition. More...
 
enum  uart_autobaud_calculation_t {
  kUART_BaudrateCalFormula = 0,
  kUART_BaudrateCalTable
}
 UART Auto Baud Calculation type definition. More...
 
enum  uart_infrared_polarity_t {
  kUART_IrPositivePulse = 0,
  kUART_IrNegativePulse
}
 UART Infrared mode ncoder/Decoder Polarity type definition. More...
 
enum  uart_infrared_pulsewidth_t {
  kUART_IrPulsewidth3div16 = 0,
  kUART_IrPulsewidth1p6us
}
 UART Infrared Transmit Pulse Width type definition. More...
 

Functions

uint32_t UART_GetInstance (UART_Type *base)
 Get the UART instance from peripheral base address. More...
 

Driver version

#define FSL_UART_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 UART driver version. More...
 

Initialization and deinitialization

status_t UART_Init (UART_Type *base, const uart_config_t *config, uint32_t srcClock_Hz)
 Initializes an UART instance with the user configuration structure and the peripheral clock frequency. More...
 
void UART_Deinit (UART_Type *base)
 Deinitializes a UART instance. More...
 
void UART_GetDefaultConfig (uart_config_t *config)
 Gets the default configuration structure. More...
 

Hardware Status Flags

uint16_t UART_GetStatusFlags (UART_Type *base)
 Gets UART hardware status flags. More...
 

Interrupt

void UART_EnableInterrupts (UART_Type *base, uint8_t interrupts)
 Enables UART interrupts according to the provided mask. More...
 
void UART_DisableInterrupts (UART_Type *base, uint8_t interrupts)
 Disables UART interrupts according to the provided mask. More...
 
uint8_t UART_GetEnabledInterrupts (UART_Type *base)
 Gets the enabled UART interrupts. More...
 

General Peripheral Configuration

static void UART_Enable (UART_Type *base, bool enable)
 Enables or disables the UART module. More...
 
static void UART_EnableHighSpeed (UART_Type *base, bool enable)
 Enables or disables the UART high speed mode. More...
 
static void UART_EnableDMA (UART_Type *base, bool enable)
 Enables or disables the UART dma request. More...
 
static void UART_SetFifoConfig (UART_Type *base, uart_fifo_config_t *fifoConfig)
 Set the UART FIFO configuration. More...
 
static bool UART_IsFifoEnabled (UART_Type *base)
 Checks the UART FIFO enable status. More...
 
static void UART_EnablCts (UART_Type *base, bool enable)
 Enables or disables the UART CTS input. More...
 
static void UART_EnableRts (UART_Type *base, bool enable)
 Enables or disables the UART RTS output. More...
 
static bool UART_IsCtsAsserted (UART_Type *base)
 Checks the CTS pin status. More...
 
static void UART_EnableLoop (UART_Type *base, bool enable)
 Enables or disables the UART loop mode. More...
 
static void UART_SetParity (UART_Type *base, uart_parity_mode_t parity)
 Set the UART parity type. More...
 
static void UART_EnableStickyParity (UART_Type *base, bool enable)
 Enables or disables sticky parity. More...
 
static void UART_SetDataBits (UART_Type *base, uart_data_bits_t dataBits)
 Set the UART data bits. More...
 
static void UART_SetStopBits (UART_Type *base, uart_stop_bit_count_t stopBits)
 Set the UART stop bits. More...
 
static uint8_t UART_GetRxFifoLevel (UART_Type *base)
 Get current UART receive FIFO level. More...
 
status_t UART_SetBaudRate (UART_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
 Sets the UART instance baudrate. More...
 
void UART_SetAutoBaudConfig (UART_Type *base, uart_autobaud_config_t *autoBaudConfig)
 Sets the UART auto baud configuration. More...
 
static uint16_t UART_GetAutoBaudCount (UART_Type *base)
 Get UART auto baud count number. More...
 
void UART_SetAutoBaud (UART_Type *base)
 Set DL register according to Auto Baud Detect Count value. More...
 
void UART_SetInfraredConfig (UART_Type *base, uart_infrared_config_t *infraredConfig)
 Sets the UART auto baud configuration. More...
 

Bus Operation

static uint32_t UART_GetRxDataRegisterAddress (UART_Type *base)
 Gets the UART receive data register byte address. More...
 
static uint32_t UART_GetTxDataRegisterAddress (UART_Type *base)
 Gets the UART transmit data register byte address. More...
 
static void UART_WriteByte (UART_Type *base, uint8_t data)
 Writes to the TX register. More...
 
static uint8_t UART_ReadByte (UART_Type *base)
 Reads the RX register directly. More...
 
static void UART_Write9bits (UART_Type *base, uint16_t data)
 Send 9 bit data to the UART peripheral. More...
 
uint16_t UART_Read9bits (UART_Type *base)
 Read 9 bit data from the UART peripheral. More...
 
status_t UART_WriteBlocking (UART_Type *base, const uint8_t *data, uint32_t length)
 Writes TX register using a blocking method. More...
 
status_t UART_ReadBlocking (UART_Type *base, uint8_t *data, uint32_t length)
 Reads RX data register using a blocking method. More...
 
static void UART_EnableBreakCondition (UART_Type *base, bool enable)
 Enables or disables break condition. More...
 

Transactional

void UART_TransferCreateHandle (UART_Type *base, uart_handle_t *handle, uart_transfer_callback_t callback, void *userData)
 Initializes the UART handle. More...
 
void UART_TransferStartRingBuffer (UART_Type *base, uart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize)
 Sets up the RX ring buffer. More...
 
void UART_TransferStopRingBuffer (UART_Type *base, uart_handle_t *handle)
 Aborts the background transfer and uninstalls the ring buffer. More...
 
size_t UART_TransferGetRxRingBufferLength (UART_Type *base, uart_handle_t *handle)
 Get the length of received data in RX ring buffer. More...
 
status_t UART_TransferSendNonBlocking (UART_Type *base, uart_handle_t *handle, uart_transfer_t *xfer)
 Transmits a buffer of data using the interrupt method. More...
 
status_t UART_TransferGetSendCount (UART_Type *base, uart_handle_t *handle, uint32_t *count)
 Gets the number of bytes that have been sent out to bus. More...
 
void UART_TransferAbortSend (UART_Type *base, uart_handle_t *handle)
 Aborts the interrupt-driven data transmit. More...
 
status_t UART_TransferReceiveNonBlocking (UART_Type *base, uart_handle_t *handle, uart_transfer_t *xfer, size_t *receivedBytes)
 Receives a buffer of data using the interrupt method. More...
 
status_t UART_TransferGetReceiveCount (UART_Type *base, uart_handle_t *handle, uint32_t *count)
 Gets the number of bytes that have been received. More...
 
void UART_TransferAbortReceive (UART_Type *base, uart_handle_t *handle)
 Aborts the interrupt-driven data receiving. More...
 
void UART_TransferHandleIRQ (UART_Type *base, uart_handle_t *handle)
 UART IRQ handle function. More...
 
void UART_TransferHandleErrorIRQ (UART_Type *base, uart_handle_t *handle)
 UART Error IRQ handle function. More...
 

Data Structure Documentation

struct uart_fifo_config_t

Data Fields

uart_txfifo_watermark_t txFifoWatermark
 TX FIFO watermark. More...
 
uart_rxfifo_watermark_t rxFifoWatermark
 RX FIFO watermark. More...
 
bool resetTxFifo
 Tx FIFO reset. More...
 
bool resetRxFifo
 Rx FIFO reset. More...
 
bool fifoEnable
 FIFO enable. More...
 

Field Documentation

uart_txfifo_watermark_t uart_fifo_config_t::txFifoWatermark

FCR[TIL]

uart_rxfifo_watermark_t uart_fifo_config_t::rxFifoWatermark

FCR[ITL]

bool uart_fifo_config_t::resetTxFifo

FCR[RESETTF]

bool uart_fifo_config_t::resetRxFifo

FCR[RESETRF]

bool uart_fifo_config_t::fifoEnable

FCR[TRFIFOE]

struct uart_autobaud_config_t

Data Fields

bool autoBaudEnable
 Enable or Disable Auto Baud Function. More...
 
uart_autobaud_program_t baudProgramType
 Uart Auto Baud Program type. More...
 
uart_autobaud_calculation_t baudCalType
 Uart Auto Baud calculation type. More...
 

Field Documentation

bool uart_autobaud_config_t::autoBaudEnable

ABR[ABE]

uart_autobaud_program_t uart_autobaud_config_t::baudProgramType

ABR[ABUP]

uart_autobaud_calculation_t uart_autobaud_config_t::baudCalType

ABR[ABT]

struct uart_infrared_config_t

Data Fields

bool txIrEnable
 Enable or Disable Uart Transmit IR Function. More...
 
bool rxIrEnable
 Enable or Disable Uart Receive IR Function. More...
 
uart_infrared_polarity_t txIrPolarity
 Transmit IR Polarity type. More...
 
uart_infrared_polarity_t rxIrPolarity
 Receive IR Polarity type. More...
 
uart_infrared_pulsewidth_t irPulseWidth
 IR Pulse Width type. More...
 

Field Documentation

bool uart_infrared_config_t::txIrEnable

ISR[XMITIR]

bool uart_infrared_config_t::rxIrEnable

ISR[RCVEIR]

uart_infrared_polarity_t uart_infrared_config_t::txIrPolarity

ISR[TXPL]

uart_infrared_polarity_t uart_infrared_config_t::rxIrPolarity

ISR[RXPL]

uart_infrared_pulsewidth_t uart_infrared_config_t::irPulseWidth

ISR[XMODE]

struct uart_config_t

Data Fields

uint32_t baudRate_Bps
 UART baud rate. More...
 
uart_parity_mode_t parityMode
 Parity mode, disabled (default), even, odd. More...
 
bool enableStickyParity
 Sticky parity, when enabled the parity bit remains unchanged and is opposite to PEN bit. More...
 
uart_data_bits_t dataBitCount
 Data bits count, eight (default), seven. More...
 
uart_stop_bit_count_t stopBitCount
 Number of stop bits, 1 stop bit (default) or 2 stop bits. More...
 
uart_fifo_config_t fifoConfig
 FIFO configuration. More...
 
uart_autobaud_config_t autoBaudConfig
 Auto baud detect and set configuration. More...
 
uart_infrared_config_t infraredConfig
 Infrared function configuration. More...
 
bool enableHighSpeed
 High speed enable. More...
 
bool enableLoop
 Loop mode MCR[LOOP].
 
bool enableTxCTS
 TX CTS enable. More...
 
bool enableRxRTS
 RX RTS enable. More...
 
bool enable
 Enable UART. More...
 

Field Documentation

uint32_t uart_config_t::baudRate_Bps

DLL, DLH

uart_parity_mode_t uart_config_t::parityMode

LCR[EPS][PEN]

bool uart_config_t::enableStickyParity

LCR[STKYP]

uart_data_bits_t uart_config_t::dataBitCount

LCR[WLS10]

uart_stop_bit_count_t uart_config_t::stopBitCount

LCR[STB]

uart_fifo_config_t uart_config_t::fifoConfig
uart_autobaud_config_t uart_config_t::autoBaudConfig
uart_infrared_config_t uart_config_t::infraredConfig
bool uart_config_t::enableHighSpeed

IER[HSE] = 1

bool uart_config_t::enableTxCTS

MCR[AFE] = 1

bool uart_config_t::enableRxRTS

To enable RTS, CTS must be enabled. MCR[AFE][RTS] = 11

bool uart_config_t::enable

IER[UUE]

struct _uart_handle_t
Note
If user wants to use the transactional API to transfer data in interrupt way, one UART instance should and can only be allocated one handle.
The handle is maintained by UART driver internally, which means the transfer state is retained and user shall not modify its state txState or rxState in application level. If user only wish to use transactional APIs without understanding its machanism, it is not necessary to understand these members.

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...
 
size_t txDataSizeAll
 Size of the data to send out. 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 rxDataSizeAll
 Size of the data to receive. 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...
 
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. More...
 

Field Documentation

uint8_t* volatile uart_handle_t::txData
volatile size_t uart_handle_t::txDataSize
size_t uart_handle_t::txDataSizeAll
uint8_t* volatile uart_handle_t::rxData
volatile size_t uart_handle_t::rxDataSize
size_t uart_handle_t::rxDataSizeAll
uint8_t* uart_handle_t::rxRingBuffer
size_t uart_handle_t::rxRingBufferSize
volatile uint16_t uart_handle_t::rxRingBufferHead
volatile uint16_t uart_handle_t::rxRingBufferTail
uart_transfer_callback_t uart_handle_t::callback
void* uart_handle_t::userData
volatile uint8_t uart_handle_t::txState
volatile uint8_t uart_handle_t::rxState
struct uart_transfer_t

Data Fields

uint8_t * data
 The buffer pointer of data to be transferred. More...
 
uint32_t dataSize
 The byte count to be transferred. More...
 

Field Documentation

uint8_t* uart_transfer_t::data
uint32_t uart_transfer_t::dataSize

Macro Definition Documentation

#define FSL_UART_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
#define UART_RETRY_TIMES   0U /* Defining to zero means to keep waiting for the flag until it is asserts/deasserts. */

Typedef Documentation

typedef void(* uart_transfer_callback_t)(UART_Type *base, uart_handle_t *handle, status_t status, void *userData)

Defines the interface of user callback function used in UART interrupt transfer using transactional APIs. The callback function shall be defined and declared in application level by user. Before starting UART transmiting or receiving by calling UART_TransferSendNonBlocking or UART_TransferReceiveNonBlocking, call UART_TransferCreateHandle to install the user callback. When the transmiting or receiving ends or any bus error like hardware overrun occurs, user callback will be invoked by driver.

Parameters
baseUART peripheral base address.
handleTransfer handle.
statusTransfer status
userDataPointer to user specified data or structure etc.

Enumeration Type Documentation

anonymous enum
Enumerator
kStatus_UART_TxBusy 

TX busy.

kStatus_UART_RxBusy 

RX busy.

kStatus_UART_TxIdle 

UART transmitter is idle.

kStatus_UART_RxIdle 

UART receiver is idle.

kStatus_UART_FlagCannotClearManually 

Some flag can't manually clear.

kStatus_UART_Error 

Error happens on UART.

kStatus_UART_RxRingBufferOverrun 

UART RX software ring buffer overrun.

kStatus_UART_RxHardwareOverrun 

UART RX receiver overrun.

kStatus_UART_FifoError 

UART noise error.

kStatus_UART_FramingError 

UART framing error.

kStatus_UART_ParityError 

UART parity error.

kStatus_UART_BaudrateNotSupport 

Baudrate is not support in current clock source.

kStatus_UART_IdleLineDetected 

IDLE flag.

kStatus_UART_Timeout 

UART times out.

kStatus_UART_RxFifoError 

UART Rx FIFO error.

This structure contains the settings for all of the UART interrupt configurations.

Enumerator
kUART_RxDataReadyInterruptEnable 

Receiver data ready interrupt, caused by rx register full when FIFO disabled or rx data count above water mark when FIFO enabled.

bit 0

kUART_TxDataRequestInterruptEnable 

Transmitter data request interrupt, caused by tx register empty when FIFO disabled or tx data count below water mark when FIFO enabled.

bit 1

kUART_RxStatusInterruptEnable 

Receiver line status interrupt, caused by such status as rx over run, framing/parity error and break detect.

bit 2

kUART_ModemStatusChangeInterruptEnable 

Modem status change interrupt, caused by RTS/CTS pin status change.

bit 3

kUART_RxTimeoutInterruptEnable 

Receiver timeout interrupt.

bit 4

kUART_AutoBaudCompleteInterruptEnable 

Auto baud completes programing baud rate divisor interrupt.

bit 5

This provides constants for the UART status flags for use in the UART functions.

Enumerator
kUART_RxDataReadyInterruptFlag 

Receiver data ready flag, self cleared by reading data out.

bit 0

kUART_RxOverrunInterruptFlag 

Receiver overrun flag, can cause rx status interrupt, slef cleared when reading the LSR(line status register).

bit 1

kUART_ParityErrorInterruptFlag 

Parity error flag, can cause rx status interrupt, self cleared when reading the LSR(line status register).

bit 2

kUART_FramingErrorInterruptFLag 

Framing error flag, can cause rx status interrupt, self cleared when reading the LSR(line status register).

bit 3

kUART_BreakDetectInterruptFlag 

Break detect flag, can cause rx status interrupt, self cleared when reading the LSR(line status register).

bit 4

kUART_TxDataRequestInterruptFlag 

Transmitter data request flag, self cleared by pushing data to tx FIFO until data count exceed water mark.

bit 5

kUART_TxEmptyInterruptFlag 

Transmitter empty flag, self cleared by pushing data to tx FIFO.

bit 6

kUART_FifoErrorInterruptFlag 

FIFO error flag, self cleared by empting the rx FIFO.

bit 7

kUART_RxTimeoutInterruptFlag 

Receiver timeout interrupt flag.

bit 11

kUART_AutoBaudCompleteInterruptFlag 

Auto baud completes programing baud rate divisor flag.

bit 12

Enumerator
kUART_ParityDisabled 

Parity disabled, bit setting: LCR[PEN] = 0.

kUART_ParityOdd 

Parity enabled, type odd, bit setting: LCR[EPS]|[PEN] = 01.

kUART_ParityEven 

Parity enabled, type even, bit setting: LCR[EPS]|[PEN] = 11.

Enumerator
kUART_Databits5 

UART data bits length: 5 bits.

kUART_Databits6 

UART data bits length: 6 bits.

kUART_Databits7 

UART data bits length: 7 bits.

kUART_Databits8 

UART data bits length: 8 bits.

Enumerator
kUART_Stopbits1 

UART stop bits length: 1 bits.

kUART_Stopbits2 

UART stop bits length: 2 bits.

Enumerator
kUART_TxfifoHalfEmpty 

UART Transmit Interrupt Level: half empty.

kUART_TxfifoEmpty 

UART Transmit Interrupt Level: full empty.

Enumerator
kUART_RxfifoByte1 

1 byte or more in rx fifo causes interrupt(Not valid in dma mode)

kUART_RxfifoBytes8 

8 byte or more in rx fifo causes interrupt

kUART_RxfifoBytes16 

16 byte or more in rx fifo causes interrupt

kUART_RxfifoBytes32 

32 byte or more in rx fifo causes interrupt

Enumerator
kUART_BaudrateProgramManual 

User calculates and programs UART divisor latch register using the value UART stored in Auto-Baud Count Register.

kUART_BaudrateProgramAuto 

UART programs UART Divisor Latch Register automatically.

When choosing kUART_BaudrateProgramAuto for baud rate program method, this is used to configure the baudrate calculation method of UART.

Enumerator
kUART_BaudrateCalFormula 

Formula is used to calculate baud rate, any baud rate can be programmed by the UART but could fail below 28.8 Kbps.

kUART_BaudrateCalTable 

Table is used to calculate baud rate, allows any baud rate above 28.8 Kbps.

Below 28.8 Kbps the only baud rates that can be programmed by the UART are 19200, 14400, 9600, 4800, 1200, and 300.

Enumerator
kUART_IrPositivePulse 

UART IR Encoder/Decoder takes positive pulse as zero.

kUART_IrNegativePulse 

UART IR Encoder/Decoder takes negative pulse as zero.

Enumerator
kUART_IrPulsewidth3div16 

UART IR Transmit pulse width is 3/16 of a bit time width.

kUART_IrPulsewidth1p6us 

UART IR Transmit pulse width is 1.6us width.

Function Documentation

uint32_t UART_GetInstance ( UART_Type *  base)
Parameters
baseUART peripheral base address.
Returns
UART instance.
status_t UART_Init ( UART_Type *  base,
const uart_config_t config,
uint32_t  srcClock_Hz 
)

This function configures the UART module with user-defined settings. Call the UART_GetDefaultConfig function to get the configuration structure configured with default settings. The example below shows how to use this API to configure the UART.

* uart_config_t uartConfig;
* UART_GetDefaultConfig(&uartConfig);
* UART_Init(UART1, &uartConfig, 20000000U);
*
Parameters
baseUART peripheral base address.
configPointer to a user-defined configuration structure.
srcClock_HzUART clock source frequency in Hz.
Return values
kStatus_UART_BaudrateNotSupportBaudrate is not support in current clock source.
kStatus_SuccessUART initialize succeed
void UART_Deinit ( UART_Type *  base)

This function waits for transmit to complete, disables TX and RX, and disables the UART clock.

Parameters
baseUART peripheral base address.
void UART_GetDefaultConfig ( uart_config_t config)

This function initializes the UART configuration structure to a default value. The example below shows how to use this API to configure the UART.

* uart_config_t uartConfig;
* UART_GetDefaultConfig(&uartConfig);
* UART_Init(UART1, &uartConfig, 20000000U);
*
Parameters
configPointer to a configuration structure.
uint16_t UART_GetStatusFlags ( UART_Type *  base)
Parameters
baseUART peripheral base address.
Returns
UART status flags, can be a single flag or several flags in _uart_status_flags combined by OR.
void UART_EnableInterrupts ( UART_Type *  base,
uint8_t  interrupts 
)

This function enables the UART interrupts according to the provided mask. The mask is a logical OR of enumeration members in _uart_interrupt_enable.

Parameters
baseUART peripheral base address.
interruptsThe interrupt source mask, can be a single source or several sources in _uart_interrupt_enable combined by OR.
void UART_DisableInterrupts ( UART_Type *  base,
uint8_t  interrupts 
)

This function disables the UART interrupts according to the provided mask. The mask is a logical OR of enumeration members in _uart_interrupt_enable.

Parameters
baseUART peripheral base address.
interruptsThe interrupt source mask, can be a single source or several sources in _uart_interrupt_enable combined by OR.
uint8_t UART_GetEnabledInterrupts ( UART_Type *  base)

This function gets the enabled UART interrupts. The enabled interrupts are returned as the logical OR value of the enumerators _uart_interrupt_enable.

Parameters
baseUART peripheral base address.
Returns
The interrupt source mask, can be a single source or several sources in _uart_interrupt_enable combined by OR.
static void UART_Enable ( UART_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUART peripheral base address.
enableTrue to enable, false to disable.
static void UART_EnableHighSpeed ( UART_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUART peripheral base address.
enableTrue to enable, false to disable.
static void UART_EnableDMA ( UART_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUART peripheral base address.
enableTrue to enable, false to disable.
static void UART_SetFifoConfig ( UART_Type *  base,
uart_fifo_config_t fifoConfig 
)
inlinestatic
Note
The FIFO configuration register FCR is write only, so we have no way of getting current FIFO configuration. In this case any modification of FCR must contain the full FIFO configuration, including tx/rx watermark, whether to reset tx/rx FIFO, and tx/rx FIFO enable.
Parameters
baseUART peripheral base address
fifoConfigPointer to FIFO configuration structure
static bool UART_IsFifoEnabled ( UART_Type *  base)
inlinestatic
Parameters
baseUART peripheral base address.
Returns
true is FIFO is enabled.
static void UART_EnablCts ( UART_Type *  base,
bool  enable 
)
inlinestatic
Note
The RTS output can not be enabled without enabling the CTS input, which means disabling CTS will disables RTS as well.
Parameters
baseUART peripheral base address.
enableTrue to enable, false to disable.
static void UART_EnableRts ( UART_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUART peripheral base address.
enableTrue to enable, false to disable.
static bool UART_IsCtsAsserted ( UART_Type *  base)
inlinestatic
Parameters
baseUART peripheral base address.
Returns
true is CTS pin is asserted meaning free to send data.
static void UART_EnableLoop ( UART_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUART peripheral base address.
enableTrue to enable, false to disable.
static void UART_SetParity ( UART_Type *  base,
uart_parity_mode_t  parity 
)
inlinestatic
Parameters
baseUART peripheral base address.
parityparity type
static void UART_EnableStickyParity ( UART_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseUART peripheral base address.
enableTrue to enable, false to disable.
static void UART_SetDataBits ( UART_Type *  base,
uart_data_bits_t  dataBits 
)
inlinestatic
Parameters
baseUART peripheral base address.
dataBitsbits to set
static void UART_SetStopBits ( UART_Type *  base,
uart_stop_bit_count_t  stopBits 
)
inlinestatic
Parameters
baseUART peripheral base address.
stopBitsstop bits to set
static uint8_t UART_GetRxFifoLevel ( UART_Type *  base)
inlinestatic
Parameters
baseSelect the UART port, should be kUART1_Id, kUART2_Id.
Returns
The number of data entries in the receive FIFO
status_t UART_SetBaudRate ( UART_Type *  base,
uint32_t  baudRate_Bps,
uint32_t  srcClock_Hz 
)

This API configures the UART module baudrate. This API can be used to update the UART module baudrate after the UART module is initialized by the UART_Init.

* UART_SetBaudRate(UART1, 115200U, 20000000U);
*
Parameters
baseUART peripheral base address.
baudRate_BpsUART baudrate to be set.
srcClock_HzUART clock source frequency in HZ.
Return values
kStatus_UART_BaudrateNotSupportBaudrate is not supported in the current clock source.
kStatus_SuccessSet baudrate succeeded.
void UART_SetAutoBaudConfig ( UART_Type *  base,
uart_autobaud_config_t autoBaudConfig 
)

This API configures the UART auto baud function, including enable/disable, calculation type, program type.

Parameters
baseUART peripheral base address.
autoBaudConfigpointer to UART auto baud configuration.
static uint16_t UART_GetAutoBaudCount ( UART_Type *  base)
inlinestatic
Parameters
baseUART peripheral base address
Returns
none
void UART_SetAutoBaud ( UART_Type *  base)
Parameters
baseUART peripheral base address.
void UART_SetInfraredConfig ( UART_Type *  base,
uart_infrared_config_t infraredConfig 
)

This API configures the UART auto baud function, including enable/disable, calculation type, program type.

Parameters
baseUART peripheral base address.
infraredConfigpointer to UART infrared configuration.
static uint32_t UART_GetRxDataRegisterAddress ( UART_Type *  base)
inlinestatic

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

Parameters
baseUART peripheral base address.
Returns
UART data register byte addresses which are used both by the transmitter and the receiver.
static uint32_t UART_GetTxDataRegisterAddress ( UART_Type *  base)
inlinestatic

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

Parameters
baseUART peripheral base address.
Returns
UART data register byte addresses which are used both by the transmitter and the receiver.
static void UART_WriteByte ( UART_Type *  base,
uint8_t  data 
)
inlinestatic

This function writes data to the TX register directly. The upper layer must ensure that the TX register is empty or TX FIFO has room before calling this function.

Parameters
baseUART peripheral base address.
dataThe byte to write.
static uint8_t UART_ReadByte ( UART_Type *  base)
inlinestatic

This function reads data from the RX register directly. The upper layer must ensure that the RX register is full or that the TX FIFO has data before calling this function.

Parameters
baseUART peripheral base address.
Returns
The byte read from UART data register.
static void UART_Write9bits ( UART_Type *  base,
uint16_t  data 
)
inlinestatic

Before calling this API, make sure parity and sticky parity are enabled, and tx register empty or room in tx FIFO.

Parameters
baseUART peripheral base address.
dataThe data to be sent
uint16_t UART_Read9bits ( UART_Type *  base)

Before calling this API, make sure parity is enabled, and rx register full or data available in rx FIFO.

Parameters
baseUART peripheral base address.
Returns
The received data
status_t UART_WriteBlocking ( UART_Type *  base,
const uint8_t *  data,
uint32_t  length 
)

This function polls the TX register, waits TX register to be empty or TX FIFO have room then writes data to the TX buffer.

Parameters
baseUART peripheral base address.
dataStart address of the data to write.
lengthSize of the data to write.
status_t UART_ReadBlocking ( UART_Type *  base,
uint8_t *  data,
uint32_t  length 
)

This function polls the RX register, waits RX register to be full or RX FIFO have data, then reads data from the RX register.

Parameters
baseUART peripheral base address.
dataStart address of the buffer to store the received data.
lengthSize of the buffer.
Return values
kStatus_FailReceiver error occurred while receiving data.
kStatus_UART_RxHardwareOverrunReceiver overrun occurred while receiving data
kStatus_UART_NoiseErrorNoise error occurred while receiving data
kStatus_UART_FramingErrorFramingerror occurred while receiving data
kStatus_UART_ParityErrorParity error occurred while receiving data
kStatus_SuccessSuccessfully received all data.
static void UART_EnableBreakCondition ( UART_Type *  base,
bool  enable 
)
inlinestatic

When break condition is enabled tx pin is pulled low by UART, when disabled the pin is high.

Parameters
baseUART peripheral base address.
enableTrue to enable, false to disable.
void UART_TransferCreateHandle ( UART_Type *  base,
uart_handle_t *  handle,
uart_transfer_callback_t  callback,
void *  userData 
)

This function initializes the UART handle, which can be used for other UART transactional APIs. Usually, for a specified UART instance, call this API once to get the initialized handle.

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

Parameters
baseUART peripheral base address.
handleUART handle pointer.
callbackCallback function.
userDataUser data.
void UART_TransferStartRingBuffer ( UART_Type *  base,
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_TransferReceiveNonBlocking() API. If there is already data received in the ring buffer, the user can get the received data from the ring buffer directly.

Note
When using RX ring buffer, one byte is reserved for internal use. In other words, if ringBufferSize is 32, then only 31 bytes are used for saving data.
Parameters
baseUART peripheral base address.
handleUART handle pointer.
ringBufferStart address of ring buffer for background receiving. Pass NULL to disable the ring buffer.
ringBufferSizesize of the ring buffer.
void UART_TransferStopRingBuffer ( UART_Type *  base,
uart_handle_t *  handle 
)

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

Parameters
baseUART peripheral base address.
handleUART handle pointer.
size_t UART_TransferGetRxRingBufferLength ( UART_Type *  base,
uart_handle_t *  handle 
)
Parameters
baseUART peripheral base address.
handleUART handle pointer.
Returns
Length of received data in RX ring buffer.
status_t UART_TransferSendNonBlocking ( UART_Type *  base,
uart_handle_t *  handle,
uart_transfer_t xfer 
)

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

Note
The kStatus_UART_TxIdle is passed to the upper layer when all data are written to the TX register. However, there is no check to ensure that all the data sent out. Before disabling the TX, check the kUART_TransmissionCompleteFlag to ensure that the transmit is finished.
Parameters
baseUART peripheral base address.
handleUART handle pointer.
xferUART transfer structure, see uart_transfer_t.
Return values
kStatus_SuccessSuccessfully start the data transmission.
kStatus_UART_TxBusyPrevious transmission still not finished, data not all written to the TX register.
kStatus_InvalidArgumentInvalid argument.
status_t UART_TransferGetSendCount ( UART_Type *  base,
uart_handle_t *  handle,
uint32_t *  count 
)

This function gets the number of bytes that have been sent out to bus by an interrupt method.

Parameters
baseUART peripheral base address.
handleUART handle pointer.
countSend bytes count.
Return values
kStatus_NoTransferInProgressNo send in progress.
kStatus_InvalidArgumentParameter is invalid.
kStatus_SuccessGet successfully through the parameter count;
void UART_TransferAbortSend ( UART_Type *  base,
uart_handle_t *  handle 
)

This function aborts the interrupt driven data sending. The user can get the remainBtyes to find out how many bytes are not sent out.

Parameters
baseUART peripheral base address.
handleUART handle pointer.
status_t UART_TransferReceiveNonBlocking ( UART_Type *  base,
uart_handle_t *  handle,
uart_transfer_t xfer,
size_t *  receivedBytes 
)

This function receives data using an interrupt method. This is a non-blocking function which returns without waiting to ensure that all data are received. If the RX ring buffer is used and not empty, the data in the ring buffer is copied and the parameter receivedBytes shows how many bytes are copied from the ring buffer. After copying, if the data in the ring buffer is not enough for read, the receive request is saved by the UART driver. When the 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 a status parameter kStatus_UART_RxIdle. For example, the upper layer needs 10 bytes but there are only 5 bytes in ring buffer. The 5 bytes are copied to xfer->data, which returns with the parameter receivedBytes set to 5. For the remaining 5 bytes, the newly arrived data is saved from xfer->data[5]. When 5 bytes are received, the UART driver notifies the 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
baseUART peripheral base address.
handleUART handle pointer.
xferUART transfer structure, see uart_transfer_t.
receivedBytesBytes received from the ring buffer directly.
Return values
kStatus_SuccessSuccessfully queue the transfer into the transmit queue.
kStatus_UART_RxBusyPrevious receive request is not finished.
kStatus_InvalidArgumentInvalid argument.
status_t UART_TransferGetReceiveCount ( UART_Type *  base,
uart_handle_t *  handle,
uint32_t *  count 
)

This function gets the number of bytes that have been received.

Parameters
baseUART peripheral base address.
handleUART handle pointer.
countReceive bytes count.
Return values
kStatus_NoTransferInProgressNo receive in progress.
kStatus_InvalidArgumentParameter is invalid.
kStatus_SuccessGet successfully through the parameter count;
void UART_TransferAbortReceive ( UART_Type *  base,
uart_handle_t *  handle 
)

This function aborts the interrupt-driven data receiving. The user can get the remainBytes to find out how many bytes not received yet.

Parameters
baseUART peripheral base address.
handleUART handle pointer.
void UART_TransferHandleIRQ ( UART_Type *  base,
uart_handle_t *  handle 
)

This function handles the UART transmit and receive IRQ request.

Parameters
baseUART peripheral base address.
handleUART handle pointer.
void UART_TransferHandleErrorIRQ ( UART_Type *  base,
uart_handle_t *  handle 
)

This function handles the UART error IRQ request.

Parameters
baseUART peripheral base address.
handleUART handle pointer.