All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
USART Driver
USART: Universal Asynchronous Receiver/Transmitter Driver

## Overview

## Data Structures

struct | usart_config_t
| USART configuration structure. More...
struct | usart_transfer_t
| USART transfer structure. More...
struct | usart_handle_t
| USART handle structure. More...

## Macros

#define | FSL_SDK_ENABLE_USART_DRIVER_TRANSACTIONAL_APIS 1
| Macro gate for enable transaction API. More...
#define | FSL_SDK_USART_DRIVER_ENABLE_BAUDRATE_AUTO_GENERATE 1
| USART baud rate auto generate switch gate. More...
#define | UART_RETRY_TIMES 0U
| Retry times for waiting flag. More...

## Typedefs

typedef void(* | usart_transfer_callback_t )(USART_Type *base, usart_handle_t *handle, status_t status, void *userData)
| USART transfer callback function. More...

## Enumerations

enum

{
kStatus_USART_TxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 0),
kStatus_USART_RxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 1),
kStatus_USART_TxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 2),
kStatus_USART_RxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 3),
kStatus_USART_TxError = MAKE_STATUS(kStatusGroup_LPC_USART, 4),
kStatus_USART_RxError = MAKE_STATUS(kStatusGroup_LPC_USART, 5),
kStatus_USART_RxRingBufferOverrun = MAKE_STATUS(kStatusGroup_LPC_USART, 6),
kStatus_USART_NoiseError = MAKE_STATUS(kStatusGroup_LPC_USART, 7),
kStatus_USART_FramingError = MAKE_STATUS(kStatusGroup_LPC_USART, 8),
kStatus_USART_ParityError = MAKE_STATUS(kStatusGroup_LPC_USART, 9),
kStatus_USART_HardwareOverrun = MAKE_STATUS(kStatusGroup_LPC_USART, 10),
kStatus_USART_BaudrateNotSupport,
kStatus_USART_Timeout = MAKE_STATUS(kStatusGroup_LPC_USART, 12)
}

| Error codes for the USART driver. More...
enum | usart_parity_mode_t { kUSART_ParityDisabled = 0x0U, kUSART_ParityEven = 0x2U, kUSART_ParityOdd = 0x3U }
| USART parity mode. More...
enum | usart_sync_mode_t { kUSART_SyncModeDisabled = 0x0U, kUSART_SyncModeSlave = 0x2U, kUSART_SyncModeMaster = 0x3U }
| USART synchronous mode. More...
enum | usart_stop_bit_count_t { kUSART_OneStopBit = 0U, kUSART_TwoStopBit = 1U }
| USART stop bit count. More...
enum | usart_data_len_t { kUSART_7BitsPerChar = 0U, kUSART_8BitsPerChar = 1U }
| USART data size. More...
enum | usart_clock_polarity_t { kUSART_RxSampleOnFallingEdge = 0x0U, kUSART_RxSampleOnRisingEdge = 0x1U }
| USART clock polarity configuration, used in sync mode. More...

enum

_usart_interrupt_enable {
kUSART_RxReadyInterruptEnable = (USART_INTENSET_RXRDYEN_MASK),
kUSART_TxReadyInterruptEnable = (USART_INTENSET_TXRDYEN_MASK),
kUSART_TxIdleInterruptEnable = (USART_INTENSET_TXIDLEEN_MASK),
kUSART_DeltaCtsInterruptEnable = (USART_INTENSET_DELTACTSEN_MASK),
kUSART_TxDisableInterruptEnable = (USART_INTENSET_TXDISEN_MASK),
kUSART_HardwareOverRunInterruptEnable = (USART_INTENSET_OVERRUNEN_MASK),
kUSART_RxBreakInterruptEnable = (USART_INTENSET_DELTARXBRKEN_MASK),
kUSART_RxStartInterruptEnable = (USART_INTENSET_STARTEN_MASK),
kUSART_FramErrorInterruptEnable = (USART_INTENSET_FRAMERREN_MASK),
kUSART_ParityErrorInterruptEnable = (USART_INTENSET_PARITYERREN_MASK),
kUSART_RxNoiseInterruptEnable = (USART_INTENSET_RXNOISEEN_MASK),
kUSART_AutoBaudErrorInterruptEnable = (USART_INTENSET_ABERREN_MASK),
kUSART_AllInterruptEnable
}

| USART interrupt configuration structure, default settings all disabled. More...

enum

_usart_flags {
kUSART_RxReady = (USART_STAT_RXRDY_MASK),
kUSART_RxIdleFlag = (USART_STAT_RXIDLE_MASK),
kUSART_TxReady = (USART_STAT_TXRDY_MASK),
kUSART_TxIdleFlag = (USART_STAT_TXIDLE_MASK),
kUSART_CtsState = (USART_STAT_CTS_MASK),
kUSART_DeltaCtsFlag = (USART_STAT_DELTACTS_MASK),
kUSART_TxDisableFlag = (USART_STAT_TXDISSTAT_MASK),
kUSART_HardwareOverrunFlag = (USART_STAT_OVERRUNINT_MASK),
kUSART_RxBreakFlag = (USART_STAT_DELTARXBRK_MASK),
kUSART_RxStartFlag = (USART_STAT_START_MASK),
kUSART_FramErrorFlag = (USART_STAT_FRAMERRINT_MASK),
kUSART_ParityErrorFlag = (USART_STAT_PARITYERRINT_MASK),
kUSART_RxNoiseFlag = (USART_STAT_RXNOISEINT_MASK),
kUSART_AutoBaudErrorFlag = (USART_STAT_ABERR_MASK)
}

| USART status flags. More...

## Driver version

#define | FSL_USART_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))
| USART driver version. More...

## Get the instance of USART

uint32_t | USART_GetInstance (USART_Type *base)
| Returns instance number for USART peripheral base address. More...

## Initialization and deinitialization

status_t | USART_Init (USART_Type *base, const usart_config_t *config, uint32_t srcClock_Hz)
| Initializes a USART instance with user configuration structure and peripheral clock. More...
void | USART_Deinit (USART_Type *base)
| Deinitializes a USART instance. More...
void | USART_GetDefaultConfig (usart_config_t *config)
| Gets the default configuration structure. More...
status_t | USART_SetBaudRate (USART_Type *base, uint32_t baudrate_Bps, uint32_t srcClock_Hz)
| Sets the USART instance baud rate. More...

## Status

static uint32_t | USART_GetStatusFlags (USART_Type *base)
| Get USART status flags. More...
static void | USART_ClearStatusFlags (USART_Type *base, uint32_t mask)
| Clear USART status flags. More...

## Interrupts

static void | USART_EnableInterrupts (USART_Type *base, uint32_t mask)
| Enables USART interrupts according to the provided mask. More...
static void | USART_DisableInterrupts (USART_Type *base, uint32_t mask)
| Disables USART interrupts according to a provided mask. More...
static uint32_t | USART_GetEnabledInterrupts (USART_Type *base)
| Returns enabled USART interrupts. More...

## Bus Operations

static void | USART_EnableContinuousSCLK (USART_Type *base, bool enable)
| Continuous Clock generation. More...
static void | USART_EnableAutoClearSCLK (USART_Type *base, bool enable)
| Enable Continuous Clock generation bit auto clear. More...
static void | USART_EnableCTS (USART_Type *base, bool enable)
| Enable CTS. More...
static void | USART_EnableTx (USART_Type *base, bool enable)
| Enable the USART transmit. More...
static void | USART_EnableRx (USART_Type *base, bool enable)
| Enable the USART receive. More...
static void | USART_WriteByte (USART_Type *base, uint8_t data)
| Writes to the TXDAT register. More...
static uint8_t | USART_ReadByte (USART_Type *base)
| Reads the RXDAT directly. More...
status_t | USART_WriteBlocking (USART_Type *base, const uint8_t *data, size_t length)
| Writes to the TX register using a blocking method. More...
status_t | USART_ReadBlocking (USART_Type *base, uint8_t *data, size_t length)
| Read RX data register using a blocking method. More...

## Transactional

status_t | USART_TransferCreateHandle (USART_Type *base, usart_handle_t *handle, usart_transfer_callback_t callback, void *userData)
| Initializes the USART handle. More...
status_t | USART_TransferSendNonBlocking (USART_Type *base, usart_handle_t *handle, usart_transfer_t *xfer)
| Transmits a buffer of data using the interrupt method. More...
void | USART_TransferStartRingBuffer (USART_Type *base, usart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize)
| Sets up the RX ring buffer. More...
void | USART_TransferStopRingBuffer (USART_Type *base, usart_handle_t *handle)
| Aborts the background transfer and uninstalls the ring buffer. More...
size_t | USART_TransferGetRxRingBufferLength (usart_handle_t *handle)
| Get the length of received data in RX ring buffer. More...
void | USART_TransferAbortSend (USART_Type *base, usart_handle_t *handle)
| Aborts the interrupt-driven data transmit. More...
status_t | USART_TransferGetSendCount (USART_Type *base, usart_handle_t *handle, uint32_t *count)
| Get the number of bytes that have been written to USART TX register. More...
status_t | USART_TransferReceiveNonBlocking (USART_Type *base, usart_handle_t *handle, usart_transfer_t *xfer, size_t *receivedBytes)
| Receives a buffer of data using an interrupt method. More...
void | USART_TransferAbortReceive (USART_Type *base, usart_handle_t *handle)
| Aborts the interrupt-driven data receiving. More...
status_t | USART_TransferGetReceiveCount (USART_Type *base, usart_handle_t *handle, uint32_t *count)
| Get the number of bytes that have been received. More...
void | USART_TransferHandleIRQ (USART_Type *base, usart_handle_t *handle)
| USART IRQ handle function. More...

## Data Structure Documentation

struct usart_config_t

### Data Fields

uint32_t | baudRate_Bps
| USART baud rate.
bool | enableRx
| USART receive enable. More...
bool | enableTx
| USART transmit enable. More...
bool | loopback
| Enable peripheral loopback.
bool | enableContinuousSCLK
| USART continuous Clock generation enable in synchronous master mode. More...
bool | enableHardwareFlowControl
| Enable hardware control RTS/CTS.
usart_parity_mode_t | parityMode
| Parity mode, disabled (default), even, odd.
usart_stop_bit_count_t | stopBitCount
| Number of stop bits, 1 stop bit (default) or 2 stop bits.
usart_data_len_t | bitCountPerChar
| Data length - 7 bit, 8 bit.
usart_sync_mode_t | syncMode
| Transfer mode - asynchronous, synchronous master, synchronous slave. More...
usart_clock_polarity_t | clockPolarity
| Selects the clock polarity and sampling edge in sync mode. More...

#### Field Documentation

bool usart_config_t::enableRx

bool usart_config_t::enableTx

bool usart_config_t::enableContinuousSCLK

usart_sync_mode_t usart_config_t::syncMode

usart_clock_polarity_t usart_config_t::clockPolarity

struct usart_transfer_t

### Data Fields

size_t | dataSize
| The byte count to be transfer. More...
uint8_t * | data
| The buffer of data to be transfer. More...
uint8_t * | rxData
| The buffer to receive data. More...
const uint8_t * | txData
| The buffer of data to be sent. More...

#### Field Documentation

uint8_t* usart_transfer_t::data

uint8_t* usart_transfer_t::rxData

const uint8_t* usart_transfer_t::txData

size_t usart_transfer_t::dataSize

struct _usart_handle

### Data Fields

const 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...
usart_transfer_callback_t | callback
| Callback function. More...
void * | userData
| USART callback function parameter. More...
volatile uint8_t | txState
| TX transfer state. More...
volatile uint8_t | rxState
| RX transfer state.

#### Field Documentation

const uint8_t* volatile usart_handle_t::txData

volatile size_t usart_handle_t::txDataSize

size_t usart_handle_t::txDataSizeAll

uint8_t* volatile usart_handle_t::rxData

volatile size_t usart_handle_t::rxDataSize

size_t usart_handle_t::rxDataSizeAll

uint8_t* usart_handle_t::rxRingBuffer

size_t usart_handle_t::rxRingBufferSize

volatile uint16_t usart_handle_t::rxRingBufferHead

volatile uint16_t usart_handle_t::rxRingBufferTail

usart_transfer_callback_t usart_handle_t::callback

void* usart_handle_t::userData

volatile uint8_t usart_handle_t::txState

## Macro Definition Documentation

#define FSL_USART_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))

#define FSL_SDK_ENABLE_USART_DRIVER_TRANSACTIONAL_APIS 1

1 for enable, 0 for disable.

#define FSL_SDK_USART_DRIVER_ENABLE_BAUDRATE_AUTO_GENERATE 1

1 for enable, 0 for disable

#define UART_RETRY_TIMES 0U

Defining to zero means to keep waiting for the flag until it is assert/deassert.

## Typedef Documentation

typedef void(* usart_transfer_callback_t)(USART_Type *base, usart_handle_t *handle, status_t status, void *userData)

## Enumeration Type Documentation

anonymous enum

Enumerator
kStatus_USART_TxBusy | Transmitter is busy.
kStatus_USART_RxBusy | Receiver is busy.
kStatus_USART_TxIdle | USART transmitter is idle.
kStatus_USART_RxIdle | USART receiver is idle.
kStatus_USART_TxError | Error happens on tx.
kStatus_USART_RxError | Error happens on rx.
kStatus_USART_RxRingBufferOverrun | Error happens on rx ring buffer.
kStatus_USART_NoiseError | USART noise error.
kStatus_USART_FramingError | USART framing error.
kStatus_USART_ParityError | USART parity error.
kStatus_USART_HardwareOverrun | USART hardware over flow.
kStatus_USART_BaudrateNotSupport | Baudrate is not support in current clock source.
kStatus_USART_Timeout | USART times out.

enum usart_parity_mode_t

Enumerator
kUSART_ParityDisabled | Parity disabled.
kUSART_ParityEven | Parity enabled, type even, bit setting: PARITYSEL = 10.
kUSART_ParityOdd | Parity enabled, type odd, bit setting: PARITYSEL = 11.

enum usart_sync_mode_t

Enumerator
kUSART_SyncModeDisabled | Asynchronous mode.
kUSART_SyncModeSlave | Synchronous slave mode.
kUSART_SyncModeMaster | Synchronous master mode.

enum usart_stop_bit_count_t

Enumerator
kUSART_OneStopBit | One stop bit.
kUSART_TwoStopBit | Two stop bits.

enum usart_data_len_t

Enumerator
kUSART_7BitsPerChar | Seven bit mode.
kUSART_8BitsPerChar | Eight bit mode.

enum usart_clock_polarity_t

Enumerator
kUSART_RxSampleOnFallingEdge | Un_RXD is sampled on the falling edge of SCLK.
kUSART_RxSampleOnRisingEdge | Un_RXD is sampled on the rising edge of SCLK.

enum _usart_interrupt_enable

Enumerator
kUSART_RxReadyInterruptEnable | Receive ready interrupt.
kUSART_TxReadyInterruptEnable | Transmit ready interrupt.
kUSART_TxIdleInterruptEnable | Transmit idle interrupt.
kUSART_DeltaCtsInterruptEnable | Cts pin change interrupt.
kUSART_TxDisableInterruptEnable | Transmit disable interrupt.
kUSART_HardwareOverRunInterruptEnable | hardware ove run interrupt.
kUSART_RxBreakInterruptEnable | Receive break interrupt.
kUSART_RxStartInterruptEnable | Receive ready interrupt.
kUSART_FramErrorInterruptEnable | Receive start interrupt.
kUSART_ParityErrorInterruptEnable | Receive frame error interrupt.
kUSART_RxNoiseInterruptEnable | Receive noise error interrupt.
kUSART_AutoBaudErrorInterruptEnable | Receive auto baud error interrupt.
kUSART_AllInterruptEnable | All interrupt.

enum _usart_flags

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

Enumerator
kUSART_RxReady | Receive ready flag.
kUSART_RxIdleFlag | Receive IDLE flag.
kUSART_TxReady | Transmit ready flag.
kUSART_TxIdleFlag | Transmit idle flag.
kUSART_CtsState | Cts pin status.
kUSART_DeltaCtsFlag | Cts pin change flag.
kUSART_TxDisableFlag | Transmit disable flag.
kUSART_HardwareOverrunFlag | Hardware over run flag.
kUSART_RxBreakFlag | Receive break flag.
kUSART_RxStartFlag | receive start flag.
kUSART_FramErrorFlag | Frame error flag.
kUSART_ParityErrorFlag | Parity error flag.
kUSART_RxNoiseFlag | Receive noise flag.
kUSART_AutoBaudErrorFlag | Auto baud error flag.

## Function Documentation

uint32_t USART_GetInstance | ( | USART_Type * | base | ) |

status_t USART_Init | ( | USART_Type * | base,
|  | const usart_config_t * | config,
|  | uint32_t | srcClock_Hz
| ) |  |

This function configures the USART module with the user-defined settings. The user can configure the configuration structure and also get the default configuration by using the USART_GetDefaultConfig() function. Example below shows how to use this API to configure USART.

* usart_config_t usartConfig;
* usartConfig.baudRate_Bps = 115200U;
* usartConfig.parityMode = kUSART_ParityDisabled;
* usartConfig.stopBitCount = kUSART_OneStopBit;
* USART_Init(USART1, &usartConfig, 20000000U);
*

Parameters

  base | USART peripheral base address.
  config | Pointer to user-defined configuration structure.
  srcClock_Hz | USART clock source frequency in HZ.

Return values

  kStatus_USART_BaudrateNotSupport | Baudrate is not support in current clock source.
  kStatus_InvalidArgument | USART base address is not valid
  kStatus_Success | Status USART initialize succeed

void USART_Deinit | ( | USART_Type * | base | ) |

This function waits for TX complete, disables the USART clock.

Parameters

  base | USART peripheral base address.

void USART_GetDefaultConfig | ( | usart_config_t * | config | ) |

This function initializes the USART configuration structure to a default value. The default values are: usartConfig->baudRate_Bps = 9600U; usartConfig->parityMode = kUSART_ParityDisabled; usartConfig->stopBitCount = kUSART_OneStopBit; usartConfig->bitCountPerChar = kUSART_8BitsPerChar; usartConfig->loopback = false; usartConfig->enableTx = false; usartConfig->enableRx = false; ...

Parameters

  config | Pointer to configuration structure.

status_t USART_SetBaudRate | ( | USART_Type * | base,
|  | uint32_t | baudrate_Bps,
|  | uint32_t | srcClock_Hz
| ) |  |

This function configures the USART module baud rate. This function is used to update the USART module baud rate after the USART module is initialized by the USART_Init.

* USART_SetBaudRate(USART1, 115200U, 20000000U);
*

Parameters

  base | USART peripheral base address.
  baudrate_Bps | USART baudrate to be set.
  srcClock_Hz | USART clock source frequency in HZ.

Return values

  kStatus_USART_BaudrateNotSupport | Baudrate is not support in current clock source.
  kStatus_Success | Set baudrate succeed.
  kStatus_InvalidArgument | One or more arguments are invalid.

static uint32_t USART_GetStatusFlags | ( | USART_Type * | base | ) |

inlinestatic

This function get all USART status flags, the flags are returned as the logical OR value of the enumerators _usart_flags. To check a specific status, compare the return value with enumerators in _usart_flags. For example, to check whether the RX is ready:

* if (kUSART_RxReady & USART_GetStatusFlags(USART1))
* {
* ...
* }
*

Parameters

  base | USART peripheral base address.

Returns
  USART status flags which are ORed by the enumerators in the _usart_flags.

static void USART_ClearStatusFlags | ( | USART_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

This function clear supported USART status flags For example:

* USART_ClearStatusFlags(USART1, kUSART_HardwareOverrunFlag)
*

Parameters

  base | USART peripheral base address.
  mask | status flags to be cleared.

static void USART_EnableInterrupts | ( | USART_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

This function enables the USART interrupts according to the provided mask. The mask is a logical OR of enumeration members. See _usart_interrupt_enable. For example, to enable TX ready interrupt and RX ready interrupt:

* USART_EnableInterrupts(USART1, kUSART_RxReadyInterruptEnable | kUSART_TxReadyInterruptEnable);
*

Parameters

  base | USART peripheral base address.
  mask | The interrupts to enable. Logical OR of _usart_interrupt_enable.

static void USART_DisableInterrupts | ( | USART_Type * | base,
|  | uint32_t | mask
| ) |  |

inlinestatic

This function disables the USART interrupts according to a provided mask. The mask is a logical OR of enumeration members. See _usart_interrupt_enable. This example shows how to disable the TX ready interrupt and RX ready interrupt:

* USART_DisableInterrupts(USART1, kUSART_TxReadyInterruptEnable | kUSART_RxReadyInterruptEnable);
*

Parameters

  base | USART peripheral base address.
  mask | The interrupts to disable. Logical OR of _usart_interrupt_enable.

static uint32_t USART_GetEnabledInterrupts | ( | USART_Type * | base | ) |

inlinestatic

This function returns the enabled USART interrupts.

Parameters

  base | USART peripheral base address.

static void USART_EnableContinuousSCLK | ( | USART_Type * | base,
|  | bool | enable
| ) |  |

inlinestatic

By default, SCLK is only output while data is being transmitted in synchronous mode. Enable this funciton, SCLK will run continuously in synchronous mode, allowing characters to be received on Un_RxD independently from transmission on Un_TXD).

Parameters

  base | USART peripheral base address.
  enable | Enable Continuous Clock generation mode or not, true for enable and false for disable.

static void USART_EnableAutoClearSCLK | ( | USART_Type * | base,
|  | bool | enable
| ) |  |

inlinestatic

While enable this cuntion, the Continuous Clock bit is automatically cleared when a complete character has been received. This bit is cleared at the same time.

Parameters

  base | USART peripheral base address.
  enable | Enable auto clear or not, true for enable and false for disable.

static void USART_EnableCTS | ( | USART_Type * | base,
|  | bool | enable
| ) |  |

inlinestatic

This function will determine whether CTS is used for flow control.

Parameters

  base | USART peripheral base address.
  enable | Enable CTS or not, true for enable and false for disable.

static void USART_EnableTx | ( | USART_Type * | base,
|  | bool | enable
| ) |  |

inlinestatic

This function will enable or disable the USART transmit.

Parameters

  base | USART peripheral base address.
  enable | true for enable and false for disable.

static void USART_EnableRx | ( | USART_Type * | base,
|  | bool | enable
| ) |  |

inlinestatic

This function will enable or disable the USART receive. Note: if the transmit is enabled, the receive will not be disabled.

Parameters

  base | USART peripheral base address.
  enable | true for enable and false for disable.

static void USART_WriteByte | ( | USART_Type * | base,
|  | uint8_t | data
| ) |  |

inlinestatic

This function will writes data to the TXDAT automatly.The upper layer must ensure that TXDATA has space for data to write before calling this function.

Parameters

  base | USART peripheral base address.
  data | The byte to write.

static uint8_t USART_ReadByte | ( | USART_Type * | base | ) |

inlinestatic

This function reads data from the RXDAT automatly. The upper layer must ensure that the RXDAT is not empty before calling this function.

Parameters

  base | USART peripheral base address.

Returns
  The byte read from USART data register.

status_t USART_WriteBlocking | ( | USART_Type * | base,
|  | const uint8_t * | data,
|  | size_t | length
| ) |  |

This function polls the TX register, waits for the TX register to be empty.

Parameters

  base | USART peripheral base address.
  data | Start address of the data to write.
  length | Size of the data to write.

Return values

  kStatus_USART_Timeout | Transmission timed out and was aborted.
  kStatus_Success | Successfully wrote all data.

status_t USART_ReadBlocking | ( | USART_Type * | base,
|  | uint8_t * | data,
|  | size_t | length
| ) |  |

This function polls the RX register, waits for the RX register to be full.

Parameters

  base | USART peripheral base address.
  data | Start address of the buffer to store the received data.
  length | Size of the buffer.

Return values

  kStatus_USART_FramingError | Receiver overrun happened while receiving data.
  kStatus_USART_ParityError | Noise error happened while receiving data.
  kStatus_USART_NoiseError | Framing error happened while receiving data.
  kStatus_USART_RxError | Overflow or underflow happened.
  kStatus_USART_Timeout | Transmission timed out and was aborted.
  kStatus_Success | Successfully received all data.

status_t USART_TransferCreateHandle | ( | USART_Type * | base,
|  | usart_handle_t * | handle,
|  | usart_transfer_callback_t | callback,
|  | void * | userData
| ) |  |

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

Parameters

  base | USART peripheral base address.
  handle | USART handle pointer.
  callback | The callback function.
  userData | The parameter of the callback function.

status_t USART_TransferSendNonBlocking | ( | USART_Type * | base,
|  | usart_handle_t * | handle,
|  | usart_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 the IRQ handler, the USART driver calls the callback function and passes the kStatus_USART_TxIdle as status parameter.

Note
  The kStatus_USART_TxIdle is passed to the upper layer when all data is written to the TX register. However it does not ensure that all data are sent out. Before disabling the TX, check the kUSART_TransmissionCompleteFlag to ensure that the TX is finished.

Parameters

  base | USART peripheral base address.
  handle | USART handle pointer.
  xfer | USART transfer structure. See usart_transfer_t.

Return values

  kStatus_Success | Successfully start the data transmission.
  kStatus_USART_TxBusy | Previous transmission still not finished, data not all written to TX register yet.
  kStatus_InvalidArgument | Invalid argument.

void USART_TransferStartRingBuffer | ( | USART_Type * | base,
|  | usart_handle_t * | handle,
|  | uint8_t * | ringBuffer,
|  | size_t | ringBufferSize
| ) |  |

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

When the RX ring buffer is used, data received are stored into the ring buffer even when the user doesn't call the USART_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 the 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

  base | USART peripheral base address.
  handle | USART handle pointer.
  ringBuffer | Start address of the ring buffer for background receiving. Pass NULL to disable the ring buffer.
  ringBufferSize | size of the ring buffer.

void USART_TransferStopRingBuffer | ( | USART_Type * | base,
|  | usart_handle_t * | handle
| ) |  |

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

Parameters

  base | USART peripheral base address.
  handle | USART handle pointer.

size_t USART_TransferGetRxRingBufferLength | ( | usart_handle_t * | handle | ) |

Parameters

  handle | USART handle pointer.

Returns
  Length of received data in RX ring buffer.

void USART_TransferAbortSend | ( | USART_Type * | base,
|  | usart_handle_t * | handle
| ) |  |

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

Parameters

  base | USART peripheral base address.
  handle | USART handle pointer.

status_t USART_TransferGetSendCount | ( | USART_Type * | base,
|  | usart_handle_t * | handle,
|  | uint32_t * | count
| ) |  |

This function gets the number of bytes that have been written to USART TX register by interrupt method.

Parameters

  base | USART peripheral base address.
  handle | USART handle pointer.
  count | Send bytes count.

Return values

  kStatus_NoTransferInProgress | No send in progress.
  kStatus_InvalidArgument | Parameter is invalid.
  kStatus_Success | Get successfully through the parameter `count`;

status_t USART_TransferReceiveNonBlocking | ( | USART_Type * | base,
|  | usart_handle_t * | handle,
|  | usart_transfer_t * | xfer,
|  | size_t * | receivedBytes
| ) |  |

This function receives data using an 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 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 to read, the receive request is saved by the USART driver. When the new data arrives, the receive request is serviced first. When all data is received, the USART driver notifies the upper layer through a callback function and passes the status parameter kStatus_USART_RxIdle. For example, the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer. The 5 bytes are copied to the xfer->data and this function returns with the parameter `receivedBytes` set to 5. For the left 5 bytes, newly arrived data is saved from the xfer->data[5]. When 5 bytes are received, the USART 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 the xfer->data. When all data is received, the upper layer is notified.

Parameters

  base | USART peripheral base address.
  handle | USART handle pointer.
  xfer | USART transfer structure, see usart_transfer_t.
  receivedBytes | Bytes received from the ring buffer directly.

Return values

  kStatus_Success | Successfully queue the transfer into transmit queue.
  kStatus_USART_RxBusy | Previous receive request is not finished.
  kStatus_InvalidArgument | Invalid argument.

void USART_TransferAbortReceive | ( | USART_Type * | base,
|  | usart_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

  base | USART peripheral base address.
  handle | USART handle pointer.

status_t USART_TransferGetReceiveCount | ( | USART_Type * | base,
|  | usart_handle_t * | handle,
|  | uint32_t * | count
| ) |  |

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

Parameters

  base | USART peripheral base address.
  handle | USART handle pointer.
  count | Receive bytes count.

Return values

  kStatus_NoTransferInProgress | No receive in progress.
  kStatus_InvalidArgument | Parameter is invalid.
  kStatus_Success | Get successfully through the parameter `count`;

void USART_TransferHandleIRQ | ( | USART_Type * | base,
|  | usart_handle_t * | handle
| ) |  |

This function handles the USART transmit and receive IRQ request.

Parameters

  base | USART peripheral base address.
  handle | USART handle pointer.