Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Uart_driver
Data Structures | |
| struct | _uart_config |
| UART configuration structure. More... | |
| struct | _uart_transfer |
| UART transfer structure. More... | |
| struct | _uart_handle |
| UART handle structure. More... | |
Typedefs | |
| typedef enum _uart_parity_mode | uart_parity_mode_t |
| UART parity mode. | |
| typedef enum _uart_stop_bit_count | uart_stop_bit_count_t |
| UART stop bit count. | |
| typedef enum _uart_idle_type_select | uart_idle_type_select_t |
| UART idle type select. | |
| typedef struct _uart_config | uart_config_t |
| UART configuration structure. | |
| typedef struct _uart_transfer | uart_transfer_t |
| UART transfer structure. | |
| typedef void(* | uart_transfer_callback_t )(UART_Type *base, uart_handle_t *handle, status_t status, void *userData) |
| UART transfer callback function. | |
Enumerations | |
| enum | _uart_status { 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_TxWatermarkTooLarge = MAKE_STATUS(kStatusGroup_UART, 4), kStatus_UART_RxWatermarkTooLarge = MAKE_STATUS(kStatusGroup_UART, 5), kStatus_UART_FlagCannotClearManually, kStatus_UART_Error = MAKE_STATUS(kStatusGroup_UART, 7), kStatus_UART_RxRingBufferOverrun = MAKE_STATUS(kStatusGroup_UART, 8), kStatus_UART_RxHardwareOverrun = MAKE_STATUS(kStatusGroup_UART, 9), kStatus_UART_NoiseError = MAKE_STATUS(kStatusGroup_UART, 10), kStatus_UART_FramingError = MAKE_STATUS(kStatusGroup_UART, 11), kStatus_UART_ParityError = MAKE_STATUS(kStatusGroup_UART, 12), kStatus_UART_BaudrateNotSupport, kStatus_UART_IdleLineDetected = MAKE_STATUS(kStatusGroup_UART, 14) } |
Error codes for the UART driver. More... | |
| enum | _uart_parity_mode { kUART_ParityDisabled = 0x0U, kUART_ParityEven = 0x2U, kUART_ParityOdd = 0x3U } |
UART parity mode. More... | |
| enum | _uart_stop_bit_count { kUART_OneStopBit = 0U, kUART_TwoStopBit = 1U } |
UART stop bit count. More... | |
| enum | _uart_idle_type_select { kUART_IdleTypeStartBit = 0U, kUART_IdleTypeStopBit = 1U } |
UART idle type select. More... | |
| enum | _uart_interrupt_enable { kUART_LinBreakInterruptEnable = (UART_BDH_LBKDIE_MASK), kUART_RxActiveEdgeInterruptEnable = (UART_BDH_RXEDGIE_MASK), kUART_TxDataRegEmptyInterruptEnable = (UART_C2_TIE_MASK << 8), kUART_TransmissionCompleteInterruptEnable = (UART_C2_TCIE_MASK << 8), kUART_RxDataRegFullInterruptEnable = (UART_C2_RIE_MASK << 8), kUART_IdleLineInterruptEnable = (UART_C2_ILIE_MASK << 8), kUART_RxOverrunInterruptEnable = (UART_C3_ORIE_MASK << 16), kUART_NoiseErrorInterruptEnable = (UART_C3_NEIE_MASK << 16), kUART_FramingErrorInterruptEnable = (UART_C3_FEIE_MASK << 16), kUART_ParityErrorInterruptEnable = (UART_C3_PEIE_MASK << 16), kUART_RxFifoOverflowInterruptEnable = (UART_CFIFO_RXOFE_MASK << 24), kUART_TxFifoOverflowInterruptEnable = (UART_CFIFO_TXOFE_MASK << 24), kUART_RxFifoUnderflowInterruptEnable = (UART_CFIFO_RXUFE_MASK << 24) } |
UART interrupt configuration structure, default settings all disabled. More... | |
| enum | _uart_flags { kUART_TxDataRegEmptyFlag = (UART_S1_TDRE_MASK), kUART_TransmissionCompleteFlag = (UART_S1_TC_MASK), kUART_RxDataRegFullFlag = (UART_S1_RDRF_MASK), kUART_IdleLineFlag = (UART_S1_IDLE_MASK), kUART_RxOverrunFlag = (UART_S1_OR_MASK), kUART_NoiseErrorFlag = (UART_S1_NF_MASK), kUART_FramingErrorFlag = (UART_S1_FE_MASK), kUART_ParityErrorFlag = (UART_S1_PF_MASK), kUART_LinBreakFlag, kUART_RxActiveEdgeFlag, kUART_RxActiveFlag, kUART_NoiseErrorInRxDataRegFlag = (UART_ED_NOISY_MASK << 16), kUART_ParityErrorInRxDataRegFlag = (UART_ED_PARITYE_MASK << 16), kUART_TxFifoEmptyFlag = (int)(UART_SFIFO_TXEMPT_MASK << 24), kUART_RxFifoEmptyFlag = (UART_SFIFO_RXEMPT_MASK << 24), kUART_TxFifoOverflowFlag = (UART_SFIFO_TXOF_MASK << 24), kUART_RxFifoOverflowFlag = (UART_SFIFO_RXOF_MASK << 24), kUART_RxFifoUnderflowFlag = (UART_SFIFO_RXUF_MASK << 24) } |
UART status flags. More... | |
Functions | |
| uint32_t | UART_GetInstance (UART_Type *base) |
| Get the UART instance from peripheral base address. | |
Initialization and deinitialization | |
| status_t | UART_Init (UART_Type *base, const uart_config_t *config, uint32_t srcClock_Hz) |
| Initializes a UART instance with a user configuration structure and peripheral clock. | |
| void | UART_Deinit (UART_Type *base) |
| Deinitializes a UART instance. | |
| void | UART_GetDefaultConfig (uart_config_t *config) |
| Gets the default configuration structure. | |
| status_t | UART_SetBaudRate (UART_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz) |
| Sets the UART instance baud rate. | |
Status | |
| uint32_t | UART_GetStatusFlags (UART_Type *base) |
| Gets UART status flags. | |
| status_t | UART_ClearStatusFlags (UART_Type *base, uint32_t mask) |
| Clears status flags with the provided mask. | |
Interrupts | |
| void | UART_EnableInterrupts (UART_Type *base, uint32_t mask) |
| Enables UART interrupts according to the provided mask. | |
| void | UART_DisableInterrupts (UART_Type *base, uint32_t mask) |
| Disables the UART interrupts according to the provided mask. | |
| uint32_t | UART_GetEnabledInterrupts (UART_Type *base) |
| Gets the enabled UART interrupts. | |
DMA Control | |
| static uint32_t | UART_GetDataRegisterAddress (UART_Type *base) |
| Gets the UART data register address. | |
| static void | UART_EnableTxDMA (UART_Type *base, bool enable) |
| Enables or disables the UART transmitter DMA request. | |
| static void | UART_EnableRxDMA (UART_Type *base, bool enable) |
| Enables or disables the UART receiver DMA. | |
Bus Operations | |
| static void | UART_EnableTx (UART_Type *base, bool enable) |
| Enables or disables the UART transmitter. | |
| static void | UART_EnableRx (UART_Type *base, bool enable) |
| Enables or disables the UART receiver. | |
| static void | UART_WriteByte (UART_Type *base, uint8_t data) |
| Writes to the TX register. | |
| static uint8_t | UART_ReadByte (UART_Type *base) |
| Reads the RX register directly. | |
| void | UART_WriteBlocking (UART_Type *base, const uint8_t *data, size_t length) |
| Writes to the TX register using a blocking method. | |
| status_t | UART_ReadBlocking (UART_Type *base, uint8_t *data, size_t length) |
| Read RX data register using a blocking method. | |
Transactional | |
| void | UART_TransferCreateHandle (UART_Type *base, uart_handle_t *handle, uart_transfer_callback_t callback, void *userData) |
| Initializes the UART handle. | |
| void | UART_TransferStartRingBuffer (UART_Type *base, uart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize) |
| Sets up the RX ring buffer. | |
| void | UART_TransferStopRingBuffer (UART_Type *base, uart_handle_t *handle) |
| Aborts the background transfer and uninstalls the ring buffer. | |
| size_t | UART_TransferGetRxRingBufferLength (uart_handle_t *handle) |
| Get the length of received data in RX ring buffer. | |
| status_t | UART_TransferSendNonBlocking (UART_Type *base, uart_handle_t *handle, uart_transfer_t *xfer) |
| Transmits a buffer of data using the interrupt method. | |
| void | UART_TransferAbortSend (UART_Type *base, uart_handle_t *handle) |
| Aborts the interrupt-driven data transmit. | |
| status_t | UART_TransferGetSendCount (UART_Type *base, uart_handle_t *handle, uint32_t *count) |
| Gets the number of bytes written to the UART TX register. | |
| status_t | UART_TransferReceiveNonBlocking (UART_Type *base, uart_handle_t *handle, uart_transfer_t *xfer, size_t *receivedBytes) |
| Receives a buffer of data using an interrupt method. | |
| void | UART_TransferAbortReceive (UART_Type *base, uart_handle_t *handle) |
| Aborts the interrupt-driven data receiving. | |
| status_t | UART_TransferGetReceiveCount (UART_Type *base, uart_handle_t *handle, uint32_t *count) |
| Gets the number of bytes that have been received. | |
| void | UART_TransferHandleIRQ (UART_Type *base, uart_handle_t *handle) |
| UART IRQ handle function. | |
| void | UART_TransferHandleErrorIRQ (UART_Type *base, uart_handle_t *handle) |
| UART Error IRQ handle function. | |
Typedef Documentation
| typedef struct _uart_config uart_config_t |
UART configuration structure.
| typedef enum _uart_idle_type_select uart_idle_type_select_t |
UART idle type select.
| typedef enum _uart_parity_mode uart_parity_mode_t |
UART parity mode.
| typedef enum _uart_stop_bit_count uart_stop_bit_count_t |
UART stop bit count.
| typedef void(* uart_transfer_callback_t)(UART_Type *base, uart_handle_t *handle, status_t status, void *userData) |
UART transfer callback function.
Definition at line 182 of file fsl_uart.h.
| typedef struct _uart_transfer uart_transfer_t |
UART transfer structure.
Enumeration Type Documentation
| enum _uart_flags |
UART status flags.
This provides constants for the UART status flags for use in the UART functions.
- Enumerator:
Definition at line 116 of file fsl_uart.h.
UART idle type select.
- Enumerator:
kUART_IdleTypeStartBit Start counting after a valid start bit.
kUART_IdleTypeStopBit Start counting after a stop bit.
Definition at line 66 of file fsl_uart.h.
UART interrupt configuration structure, default settings all disabled.
This structure contains the settings for all of the UART interrupt configurations.
- Enumerator:
Definition at line 77 of file fsl_uart.h.
| enum _uart_parity_mode |
UART parity mode.
- Enumerator:
kUART_ParityDisabled Parity disabled
kUART_ParityEven Parity enabled, type even, bit setting: PE|PT = 10
kUART_ParityOdd Parity enabled, type odd, bit setting: PE|PT = 11
Definition at line 51 of file fsl_uart.h.
| enum _uart_status |
Error codes for the UART driver.
- Enumerator:
Definition at line 29 of file fsl_uart.h.
| enum _uart_stop_bit_count |
UART stop bit count.
Definition at line 59 of file fsl_uart.h.
Function Documentation
Clears status flags with the provided mask.
This function clears UART status flags with a provided mask. An automatically cleared flag can't be cleared by this function. These flags can only be cleared or set by hardware. kUART_TxDataRegEmptyFlag, kUART_TransmissionCompleteFlag, kUART_RxDataRegFullFlag, kUART_RxActiveFlag, kUART_NoiseErrorInRxDataRegFlag, kUART_ParityErrorInRxDataRegFlag, kUART_TxFifoEmptyFlag,kUART_RxFifoEmptyFlag Note that this API should be called when the Tx/Rx is idle. Otherwise it has no effect.
- Parameters:
-
base UART peripheral base address. mask The status flags to be cleared; it is logical OR value of _uart_flags.
- Return values:
-
kStatus_UART_FlagCannotClearManually The flag can't be cleared by this function but it is cleared automatically by hardware. kStatus_Success Status in the mask is cleared.
brief Clears status flags with the provided mask.
This function clears UART status flags with a provided mask. An automatically cleared flag can't be cleared by this function. These flags can only be cleared or set by hardware. kUART_TxDataRegEmptyFlag, kUART_TransmissionCompleteFlag, kUART_RxDataRegFullFlag, kUART_RxActiveFlag, kUART_NoiseErrorInRxDataRegFlag, kUART_ParityErrorInRxDataRegFlag, kUART_TxFifoEmptyFlag,kUART_RxFifoEmptyFlag Note that this API should be called when the Tx/Rx is idle. Otherwise it has no effect.
param base UART peripheral base address. param mask The status flags to be cleared; it is logical OR value of ref _uart_flags. retval kStatus_UART_FlagCannotClearManually The flag can't be cleared by this function but it is cleared automatically by hardware. retval kStatus_Success Status in the mask is cleared.
Definition at line 642 of file fsl_uart.c.
| void UART_Deinit | ( | UART_Type * | base ) |
Deinitializes a UART instance.
This function waits for TX complete, disables TX and RX, and disables the UART clock.
- Parameters:
-
base UART peripheral base address.
brief Deinitializes a UART instance.
This function waits for TX complete, disables TX and RX, and disables the UART clock.
param base UART peripheral base address.
Definition at line 355 of file fsl_uart.c.
| void UART_DisableInterrupts | ( | UART_Type * | base, |
| uint32_t | mask | ||
| ) |
Disables the UART interrupts according to the provided mask.
This function disables the UART interrupts according to the provided mask. The mask is a logical OR of enumeration members. See _uart_interrupt_enable. For example, to disable TX empty interrupt and RX full interrupt do the following.
UART_DisableInterrupts(UART1,kUART_TxDataRegEmptyInterruptEnable | kUART_RxDataRegFullInterruptEnable );
- Parameters:
-
base UART peripheral base address. mask The interrupts to disable. Logical OR of _uart_interrupt_enable.
brief Disables the UART interrupts according to the provided mask.
This function disables the UART interrupts according to the provided mask. The mask is a logical OR of enumeration members. See ref _uart_interrupt_enable. For example, to disable TX empty interrupt and RX full interrupt do the following. code UART_DisableInterrupts(UART1,kUART_TxDataRegEmptyInterruptEnable | kUART_RxDataRegFullInterruptEnable); endcode
param base UART peripheral base address. param mask The interrupts to disable. Logical OR of ref _uart_interrupt_enable.
Definition at line 543 of file fsl_uart.c.
| void UART_EnableInterrupts | ( | UART_Type * | base, |
| uint32_t | mask | ||
| ) |
Enables UART interrupts according to the provided mask.
This function enables the UART interrupts according to the provided mask. The mask is a logical OR of enumeration members. See _uart_interrupt_enable. For example, to enable TX empty interrupt and RX full interrupt, do the following.
UART_EnableInterrupts(UART1,kUART_TxDataRegEmptyInterruptEnable | kUART_RxDataRegFullInterruptEnable );
- Parameters:
-
base UART peripheral base address. mask The interrupts to enable. Logical OR of _uart_interrupt_enable.
brief Enables UART interrupts according to the provided mask.
This function enables the UART interrupts according to the provided mask. The mask is a logical OR of enumeration members. See ref _uart_interrupt_enable. For example, to enable TX empty interrupt and RX full interrupt, do the following. code UART_EnableInterrupts(UART1,kUART_TxDataRegEmptyInterruptEnable | kUART_RxDataRegFullInterruptEnable); endcode
param base UART peripheral base address. param mask The interrupts to enable. Logical OR of ref _uart_interrupt_enable.
Definition at line 515 of file fsl_uart.c.
| static void UART_EnableRx | ( | UART_Type * | base, |
| bool | enable | ||
| ) | [static] |
Enables or disables the UART receiver.
This function enables or disables the UART receiver.
- Parameters:
-
base UART peripheral base address. enable True to enable, false to disable.
Definition at line 517 of file fsl_uart.h.
| static void UART_EnableRxDMA | ( | UART_Type * | base, |
| bool | enable | ||
| ) | [static] |
Enables or disables the UART receiver DMA.
This function enables or disables the receiver data register full flag, S1[RDRF], to generate DMA requests.
- Parameters:
-
base UART peripheral base address. enable True to enable, false to disable.
Definition at line 459 of file fsl_uart.h.
| static void UART_EnableTx | ( | UART_Type * | base, |
| bool | enable | ||
| ) | [static] |
Enables or disables the UART transmitter.
This function enables or disables the UART transmitter.
- Parameters:
-
base UART peripheral base address. enable True to enable, false to disable.
Definition at line 497 of file fsl_uart.h.
| static void UART_EnableTxDMA | ( | UART_Type * | base, |
| bool | enable | ||
| ) | [static] |
Enables or disables the UART transmitter DMA request.
This function enables or disables the transmit data register empty flag, S1[TDRE], to generate the DMA requests.
- Parameters:
-
base UART peripheral base address. enable True to enable, false to disable.
Definition at line 429 of file fsl_uart.h.
| static uint32_t UART_GetDataRegisterAddress | ( | UART_Type * | base ) | [static] |
Gets the UART data register address.
This function returns the UART data register address, which is mainly used by DMA/eDMA.
- Parameters:
-
base UART peripheral base address.
- Returns:
- UART data register addresses which are used both by the transmitter and the receiver.
Definition at line 416 of file fsl_uart.h.
| void UART_GetDefaultConfig | ( | uart_config_t * | config ) |
Gets the default configuration structure.
This function initializes the UART configuration structure to a default value. The default values are as follows. uartConfig->baudRate_Bps = 115200U; uartConfig->bitCountPerChar = kUART_8BitsPerChar; uartConfig->parityMode = kUART_ParityDisabled; uartConfig->stopBitCount = kUART_OneStopBit; uartConfig->txFifoWatermark = 0; uartConfig->rxFifoWatermark = 1; uartConfig->idleType = kUART_IdleTypeStartBit; uartConfig->enableTx = false; uartConfig->enableRx = false;
- Parameters:
-
config Pointer to configuration structure.
brief Gets the default configuration structure.
This function initializes the UART configuration structure to a default value. The default values are as follows. uartConfig->baudRate_Bps = 115200U; uartConfig->bitCountPerChar = kUART_8BitsPerChar; uartConfig->parityMode = kUART_ParityDisabled; uartConfig->stopBitCount = kUART_OneStopBit; uartConfig->txFifoWatermark = 0; uartConfig->rxFifoWatermark = 1; uartConfig->idleType = kUART_IdleTypeStartBit; uartConfig->enableTx = false; uartConfig->enableRx = false;
param config Pointer to configuration structure.
Definition at line 394 of file fsl_uart.c.
| uint32_t UART_GetEnabledInterrupts | ( | UART_Type * | base ) |
Gets the enabled UART interrupts.
This function gets the enabled UART interrupts. The enabled interrupts are returned as the logical OR value of the enumerators _uart_interrupt_enable. To check a specific interrupts enable status, compare the return value with enumerators in _uart_interrupt_enable. For example, to check whether TX empty interrupt is enabled, do the following.
uint32_t enabledInterrupts = UART_GetEnabledInterrupts(UART1); if (kUART_TxDataRegEmptyInterruptEnable & enabledInterrupts) { ... }
- Parameters:
-
base UART peripheral base address.
- Returns:
- UART interrupt flags which are logical OR of the enumerators in _uart_interrupt_enable.
brief Gets the enabled UART interrupts.
This function gets the enabled UART interrupts. The enabled interrupts are returned as the logical OR value of the enumerators ref _uart_interrupt_enable. To check a specific interrupts enable status, compare the return value with enumerators in ref _uart_interrupt_enable. For example, to check whether TX empty interrupt is enabled, do the following. code uint32_t enabledInterrupts = UART_GetEnabledInterrupts(UART1);
if (kUART_TxDataRegEmptyInterruptEnable & enabledInterrupts) { ... } endcode
param base UART peripheral base address. return UART interrupt flags which are logical OR of the enumerators in ref _uart_interrupt_enable.
Definition at line 578 of file fsl_uart.c.
| uint32_t UART_GetInstance | ( | UART_Type * | base ) |
Get the UART instance from peripheral base address.
- Parameters:
-
base UART peripheral base address.
- Returns:
- UART instance.
brief Get the UART instance from peripheral base address.
param base UART peripheral base address. return UART instance.
Definition at line 128 of file fsl_uart.c.
| uint32_t UART_GetStatusFlags | ( | UART_Type * | base ) |
Gets UART status flags.
This function gets all UART status flags. The flags are returned as the logical OR value of the enumerators _uart_flags. To check a specific status, compare the return value with enumerators in _uart_flags. For example, to check whether the TX is empty, do the following.
if (kUART_TxDataRegEmptyFlag & UART_GetStatusFlags(UART1)) { ... }
- Parameters:
-
base UART peripheral base address.
- Returns:
- UART status flags which are ORed by the enumerators in the _uart_flags.
brief Gets UART status flags.
This function gets all UART status flags. The flags are returned as the logical OR value of the enumerators ref _uart_flags. To check a specific status, compare the return value with enumerators in ref _uart_flags. For example, to check whether the TX is empty, do the following. code if (kUART_TxDataRegEmptyFlag & UART_GetStatusFlags(UART1)) { ... } endcode
param base UART peripheral base address. return UART status flags which are ORed by the enumerators in the _uart_flags.
Definition at line 608 of file fsl_uart.c.
| status_t UART_Init | ( | UART_Type * | base, |
| const uart_config_t * | config, | ||
| uint32_t | srcClock_Hz | ||
| ) |
Initializes a UART instance with a user configuration structure and peripheral clock.
This function configures the UART module with the user-defined settings. The user can configure the configuration structure and also get the default configuration by using the UART_GetDefaultConfig() function. The example below shows how to use this API to configure UART.
uart_config_t uartConfig; uartConfig.baudRate_Bps = 115200U; uartConfig.parityMode = kUART_ParityDisabled ; uartConfig.stopBitCount = kUART_OneStopBit ; uartConfig.txFifoWatermark = 0; uartConfig.rxFifoWatermark = 1; UART_Init(UART1, &uartConfig, 20000000U);
- Parameters:
-
base UART peripheral base address. config Pointer to the user-defined configuration structure. srcClock_Hz UART clock source frequency in HZ.
- Return values:
-
kStatus_UART_BaudrateNotSupport Baudrate is not support in current clock source. kStatus_Success Status UART initialize succeed
brief Initializes a UART instance with a user configuration structure and peripheral clock.
This function configures the UART module with the user-defined settings. The user can configure the configuration structure and also get the default configuration by using the UART_GetDefaultConfig() function. The example below shows how to use this API to configure UART. code uart_config_t uartConfig; uartConfig.baudRate_Bps = 115200U; uartConfig.parityMode = kUART_ParityDisabled; uartConfig.stopBitCount = kUART_OneStopBit; uartConfig.txFifoWatermark = 0; uartConfig.rxFifoWatermark = 1; UART_Init(UART1, &uartConfig, 20000000U); endcode
param base UART peripheral base address. param config Pointer to the user-defined configuration structure. param srcClock_Hz UART clock source frequency in HZ. retval kStatus_UART_BaudrateNotSupport Baudrate is not support in current clock source. retval kStatus_Success Status UART initialize succeed
Definition at line 211 of file fsl_uart.c.
Read RX data register using a blocking method.
This function polls the RX register, waits for the RX register to be full or for RX FIFO to have data, and reads data from the TX register.
- Parameters:
-
base UART peripheral base address. data Start address of the buffer to store the received data. length Size of the buffer.
- Return values:
-
kStatus_UART_RxHardwareOverrun Receiver overrun occurred while receiving data. kStatus_UART_NoiseError A noise error occurred while receiving data. kStatus_UART_FramingError A framing error occurred while receiving data. kStatus_UART_ParityError A parity error occurred while receiving data. kStatus_Success Successfully received all data.
brief Read RX data register using a blocking method.
This function polls the RX register, waits for the RX register to be full or for RX FIFO to have data, and reads data from the TX register.
param base UART peripheral base address. param data Start address of the buffer to store the received data. param length Size of the buffer. retval kStatus_UART_RxHardwareOverrun Receiver overrun occurred while receiving data. retval kStatus_UART_NoiseError A noise error occurred while receiving data. retval kStatus_UART_FramingError A framing error occurred while receiving data. retval kStatus_UART_ParityError A parity error occurred while receiving data. retval kStatus_Success Successfully received all data.
Definition at line 749 of file fsl_uart.c.
| static uint8_t UART_ReadByte | ( | UART_Type * | base ) | [static] |
Reads the RX register directly.
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:
-
base UART peripheral base address.
- Returns:
- The byte read from UART data register.
Definition at line 552 of file fsl_uart.h.
Sets the UART instance baud rate.
This function configures the UART module baud rate. This function is used to update the UART module baud rate after the UART module is initialized by the UART_Init.
UART_SetBaudRate(UART1, 115200U, 20000000U);
- Parameters:
-
base UART peripheral base address. baudRate_Bps UART baudrate to be set. srcClock_Hz UART clock source freqency in Hz.
- Return values:
-
kStatus_UART_BaudrateNotSupport Baudrate is not support in the current clock source. kStatus_Success Set baudrate succeeded.
brief Sets the UART instance baud rate.
This function configures the UART module baud rate. This function is used to update the UART module baud rate after the UART module is initialized by the UART_Init. code UART_SetBaudRate(UART1, 115200U, 20000000U); endcode
param base UART peripheral base address. param baudRate_Bps UART baudrate to be set. param srcClock_Hz UART clock source freqency in Hz. retval kStatus_UART_BaudrateNotSupport Baudrate is not support in the current clock source. retval kStatus_Success Set baudrate succeeded.
Definition at line 434 of file fsl_uart.c.
| void UART_TransferAbortReceive | ( | UART_Type * | base, |
| uart_handle_t * | handle | ||
| ) |
Aborts the interrupt-driven data receiving.
This function aborts the interrupt-driven data receiving. The user can get the remainBytes to know how many bytes are not received yet.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer.
brief Aborts the interrupt-driven data receiving.
This function aborts the interrupt-driven data receiving. The user can get the remainBytes to know how many bytes are not received yet.
param base UART peripheral base address. param handle UART handle pointer.
Definition at line 1168 of file fsl_uart.c.
| void UART_TransferAbortSend | ( | UART_Type * | base, |
| uart_handle_t * | handle | ||
| ) |
Aborts the interrupt-driven data transmit.
This function aborts the interrupt-driven data sending. The user can get the remainBytes to find out how many bytes are not sent out.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer.
brief Aborts the interrupt-driven data transmit.
This function aborts the interrupt-driven data sending. The user can get the remainBytes to find out how many bytes are not sent out.
param base UART peripheral base address. param handle UART handle pointer.
Definition at line 973 of file fsl_uart.c.
| void UART_TransferCreateHandle | ( | UART_Type * | base, |
| uart_handle_t * | handle, | ||
| uart_transfer_callback_t | callback, | ||
| void * | userData | ||
| ) |
Initializes the UART handle.
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.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer. callback The callback function. userData The parameter of the callback function.
brief Initializes the UART handle.
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.
param base UART peripheral base address. param handle UART handle pointer. param callback The callback function. param userData The parameter of the callback function.
Definition at line 817 of file fsl_uart.c.
| status_t UART_TransferGetReceiveCount | ( | UART_Type * | base, |
| uart_handle_t * | handle, | ||
| uint32_t * | count | ||
| ) |
Gets the number of bytes that have been received.
This function gets the number of bytes that have been received.
- Parameters:
-
base UART peripheral base address. handle UART 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;
brief Gets the number of bytes that have been received.
This function gets the number of bytes that have been received.
param base UART peripheral base address. param handle UART handle pointer. param count Receive bytes count. retval kStatus_NoTransferInProgress No receive in progress. retval kStatus_InvalidArgument Parameter is invalid. retval kStatus_Success Get successfully through the parameter count;
Definition at line 1201 of file fsl_uart.c.
| size_t UART_TransferGetRxRingBufferLength | ( | uart_handle_t * | handle ) |
Get the length of received data in RX ring buffer.
- Parameters:
-
handle UART handle pointer.
- Returns:
- Length of received data in RX ring buffer.
brief Get the length of received data in RX ring buffer.
param handle UART handle pointer. return Length of received data in RX ring buffer.
Definition at line 153 of file fsl_uart.c.
| status_t UART_TransferGetSendCount | ( | UART_Type * | base, |
| uart_handle_t * | handle, | ||
| uint32_t * | count | ||
| ) |
Gets the number of bytes written to the UART TX register.
This function gets the number of bytes written to the UART TX register by using the interrupt method.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer. count Send bytes count.
- Return values:
-
kStatus_NoTransferInProgress No send in progress. kStatus_InvalidArgument The parameter is invalid. kStatus_Success Get successfully through the parameter count;
brief Gets the number of bytes written to the UART TX register.
This function gets the number of bytes written to the UART TX register by using the interrupt method.
param base UART peripheral base address. param handle UART handle pointer. param count Send bytes count. retval kStatus_NoTransferInProgress No send in progress. retval kStatus_InvalidArgument The parameter is invalid. retval kStatus_Success Get successfully through the parameter count;
Definition at line 996 of file fsl_uart.c.
| void UART_TransferHandleErrorIRQ | ( | UART_Type * | base, |
| uart_handle_t * | handle | ||
| ) |
UART Error IRQ handle function.
This function handles the UART error IRQ request.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer.
brief UART Error IRQ handle function.
This function handles the UART error IRQ request.
param base UART peripheral base address. param handle UART handle pointer.
Definition at line 1520 of file fsl_uart.c.
| void UART_TransferHandleIRQ | ( | UART_Type * | base, |
| uart_handle_t * | handle | ||
| ) |
UART IRQ handle function.
This function handles the UART transmit and receive IRQ request.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer.
brief UART IRQ handle function.
This function handles the UART transmit and receive IRQ request.
param base UART peripheral base address. param handle UART handle pointer.
Definition at line 1229 of file fsl_uart.c.
| status_t UART_TransferReceiveNonBlocking | ( | UART_Type * | base, |
| uart_handle_t * | handle, | ||
| uart_transfer_t * | xfer, | ||
| size_t * | receivedBytes | ||
| ) |
Receives a buffer of data using an interrupt method.
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 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 the status parameter kStatus_UART_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 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 the xfer->data. When all data is received, the upper layer is notified.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer. xfer UART transfer structure, see uart_transfer_t. receivedBytes Bytes received from the ring buffer directly.
- Return values:
-
kStatus_Success Successfully queue the transfer into transmit queue. kStatus_UART_RxBusy Previous receive request is not finished. kStatus_InvalidArgument Invalid argument.
brief Receives a buffer of data using an interrupt method.
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 p 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 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 the status parameter ref kStatus_UART_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 p 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 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 the xfer->data. When all data is received, the upper layer is notified.
param base UART peripheral base address. param handle UART handle pointer. param xfer UART transfer structure, see uart_transfer_t. param receivedBytes Bytes received from the ring buffer directly. retval kStatus_Success Successfully queue the transfer into transmit queue. retval kStatus_UART_RxBusy Previous receive request is not finished. retval kStatus_InvalidArgument Invalid argument.
Definition at line 1037 of file fsl_uart.c.
| status_t UART_TransferSendNonBlocking | ( | UART_Type * | base, |
| uart_handle_t * | handle, | ||
| uart_transfer_t * | xfer | ||
| ) |
Transmits a buffer of data using the interrupt method.
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 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 is written to the TX register. However, it does not ensure that all data is sent out. Before disabling the TX, check the kUART_TransmissionCompleteFlag to ensure that the TX is finished.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer. xfer UART transfer structure. See uart_transfer_t.
- Return values:
-
kStatus_Success Successfully start the data transmission. kStatus_UART_TxBusy Previous transmission still not finished; data not all written to TX register yet. kStatus_InvalidArgument Invalid argument.
brief Transmits a buffer of data using the interrupt method.
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 ISR, the UART driver calls the callback function and passes the ref kStatus_UART_TxIdle as status parameter.
note The kStatus_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. Before disabling the TX, check the kUART_TransmissionCompleteFlag to ensure that the TX is finished.
param base UART peripheral base address. param handle UART handle pointer. param xfer UART transfer structure. See uart_transfer_t. retval kStatus_Success Successfully start the data transmission. retval kStatus_UART_TxBusy Previous transmission still not finished; data not all written to TX register yet. retval kStatus_InvalidArgument Invalid argument.
Definition at line 934 of file fsl_uart.c.
| void UART_TransferStartRingBuffer | ( | UART_Type * | base, |
| uart_handle_t * | handle, | ||
| uint8_t * | ringBuffer, | ||
| size_t | ringBufferSize | ||
| ) |
Sets up the RX ring buffer.
This function sets up the RX ring buffer to a specific UART handle.
When the RX ring buffer is used, data received are stored into the ring buffer even when the user doesn't call the UART_TransferReceiveNonBlocking() API. If data is already 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
ringBufferSizeis 32, only 31 bytes are used for saving data.
- Parameters:
-
base UART peripheral base address. handle UART 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.
brief Sets up the RX ring buffer.
This function sets up the RX ring buffer to a specific UART handle.
When the RX ring buffer is used, data received are stored into the ring buffer even when the user doesn't call the UART_TransferReceiveNonBlocking() API. If data is already 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 p ringBufferSize is 32, only 31 bytes are used for saving data.
param base UART peripheral base address. param handle UART handle pointer. param ringBuffer Start address of the ring buffer for background receiving. Pass NULL to disable the ring buffer. param ringBufferSize Size of the ring buffer.
Definition at line 865 of file fsl_uart.c.
| void UART_TransferStopRingBuffer | ( | UART_Type * | base, |
| uart_handle_t * | handle | ||
| ) |
Aborts the background transfer and uninstalls the ring buffer.
This function aborts the background transfer and uninstalls the ring buffer.
- Parameters:
-
base UART peripheral base address. handle UART handle pointer.
brief Aborts the background transfer and uninstalls the ring buffer.
This function aborts the background transfer and uninstalls the ring buffer.
param base UART peripheral base address. param handle UART handle pointer.
Definition at line 894 of file fsl_uart.c.
| void UART_WriteBlocking | ( | UART_Type * | base, |
| const uint8_t * | data, | ||
| size_t | length | ||
| ) |
Writes to the TX register using a blocking method.
This function polls the TX register, waits for the TX register to be empty or for the TX FIFO to have room and writes data to the TX buffer.
- Note:
- This function does not check whether all data is sent out to the bus. Before disabling the TX, check kUART_TransmissionCompleteFlag to ensure that the TX is finished.
- Parameters:
-
base UART peripheral base address. data Start address of the data to write. length Size of the data to write.
brief Writes to the TX register using a blocking method.
This function polls the TX register, waits for the TX register to be empty or for the TX FIFO to have room and writes data to the TX buffer.
note This function does not check whether all data is sent out to the bus. Before disabling the TX, check kUART_TransmissionCompleteFlag to ensure that the TX is finished.
param base UART peripheral base address. param data Start address of the data to write. param length Size of the data to write.
Definition at line 707 of file fsl_uart.c.
| static void UART_WriteByte | ( | UART_Type * | base, |
| uint8_t | data | ||
| ) | [static] |
Writes to the TX register.
This function writes data to the TX register directly. The upper layer must ensure that the TX register is empty or TX FIFO has empty room before calling this function.
- Parameters:
-
base UART peripheral base address. data The byte to write.
Definition at line 538 of file fsl_uart.h.
Generated on Tue Jul 12 2022 15:37:34 by
1.7.2