The MCUXpresso SDK provides a peripheral driver for the Low Power UART (LPUART) module of MCUXpresso SDK devices.
Typical use case
LPUART Operation
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/lpuart
|
#define | UART_RETRY_TIMES 0U /* Defining to zero means to keep waiting for the flag until it is assert/deassert. */ |
| Retry times for waiting flag. More...
|
|
|
enum | {
kStatus_LPUART_TxBusy = MAKE_STATUS(kStatusGroup_LPUART, 0),
kStatus_LPUART_RxBusy = MAKE_STATUS(kStatusGroup_LPUART, 1),
kStatus_LPUART_TxIdle = MAKE_STATUS(kStatusGroup_LPUART, 2),
kStatus_LPUART_RxIdle = MAKE_STATUS(kStatusGroup_LPUART, 3),
kStatus_LPUART_TxWatermarkTooLarge = MAKE_STATUS(kStatusGroup_LPUART, 4),
kStatus_LPUART_RxWatermarkTooLarge = MAKE_STATUS(kStatusGroup_LPUART, 5),
kStatus_LPUART_FlagCannotClearManually = MAKE_STATUS(kStatusGroup_LPUART, 6),
kStatus_LPUART_Error = MAKE_STATUS(kStatusGroup_LPUART, 7),
kStatus_LPUART_RxRingBufferOverrun,
kStatus_LPUART_RxHardwareOverrun = MAKE_STATUS(kStatusGroup_LPUART, 9),
kStatus_LPUART_NoiseError = MAKE_STATUS(kStatusGroup_LPUART, 10),
kStatus_LPUART_FramingError = MAKE_STATUS(kStatusGroup_LPUART, 11),
kStatus_LPUART_ParityError = MAKE_STATUS(kStatusGroup_LPUART, 12),
kStatus_LPUART_BaudrateNotSupport,
kStatus_LPUART_IdleLineDetected = MAKE_STATUS(kStatusGroup_LPUART, 14),
kStatus_LPUART_Timeout = MAKE_STATUS(kStatusGroup_LPUART, 15)
} |
| Error codes for the LPUART driver. More...
|
|
enum | lpuart_parity_mode_t {
kLPUART_ParityDisabled = 0x0U,
kLPUART_ParityEven = 0x2U,
kLPUART_ParityOdd = 0x3U
} |
| LPUART parity mode. More...
|
|
enum | lpuart_data_bits_t { kLPUART_EightDataBits = 0x0U
} |
| LPUART data bits count. More...
|
|
enum | lpuart_stop_bit_count_t {
kLPUART_OneStopBit = 0U,
kLPUART_TwoStopBit = 1U
} |
| LPUART stop bit count. More...
|
|
enum | lpuart_transmit_cts_source_t {
kLPUART_CtsSourcePin = 0U,
kLPUART_CtsSourceMatchResult = 1U
} |
| LPUART transmit CTS source. More...
|
|
enum | lpuart_transmit_cts_config_t {
kLPUART_CtsSampleAtStart = 0U,
kLPUART_CtsSampleAtIdle = 1U
} |
| LPUART transmit CTS configure. More...
|
|
enum | lpuart_idle_type_select_t {
kLPUART_IdleTypeStartBit = 0U,
kLPUART_IdleTypeStopBit = 1U
} |
| LPUART idle flag type defines when the receiver starts counting. More...
|
|
enum | lpuart_idle_config_t {
kLPUART_IdleCharacter1 = 0U,
kLPUART_IdleCharacter2 = 1U,
kLPUART_IdleCharacter4 = 2U,
kLPUART_IdleCharacter8 = 3U,
kLPUART_IdleCharacter16 = 4U,
kLPUART_IdleCharacter32 = 5U,
kLPUART_IdleCharacter64 = 6U,
kLPUART_IdleCharacter128 = 7U
} |
| LPUART idle detected configuration. More...
|
|
enum | _lpuart_interrupt_enable {
kLPUART_LinBreakInterruptEnable = (LPUART_BAUD_LBKDIE_MASK >> 8U),
kLPUART_RxActiveEdgeInterruptEnable = (LPUART_BAUD_RXEDGIE_MASK >> 8U),
kLPUART_TxDataRegEmptyInterruptEnable = (LPUART_CTRL_TIE_MASK),
kLPUART_TransmissionCompleteInterruptEnable = (LPUART_CTRL_TCIE_MASK),
kLPUART_RxDataRegFullInterruptEnable = (LPUART_CTRL_RIE_MASK),
kLPUART_IdleLineInterruptEnable = (LPUART_CTRL_ILIE_MASK),
kLPUART_RxOverrunInterruptEnable = (LPUART_CTRL_ORIE_MASK),
kLPUART_NoiseErrorInterruptEnable = (LPUART_CTRL_NEIE_MASK),
kLPUART_FramingErrorInterruptEnable = (LPUART_CTRL_FEIE_MASK),
kLPUART_ParityErrorInterruptEnable = (LPUART_CTRL_PEIE_MASK),
kLPUART_Match1InterruptEnable = (LPUART_CTRL_MA1IE_MASK),
kLPUART_Match2InterruptEnable = (LPUART_CTRL_MA2IE_MASK)
} |
| LPUART interrupt configuration structure, default settings all disabled. More...
|
|
enum | _lpuart_flags {
kLPUART_TxDataRegEmptyFlag,
kLPUART_TransmissionCompleteFlag,
kLPUART_RxDataRegFullFlag = (LPUART_STAT_RDRF_MASK),
kLPUART_IdleLineFlag = (LPUART_STAT_IDLE_MASK),
kLPUART_RxOverrunFlag = (LPUART_STAT_OR_MASK),
kLPUART_NoiseErrorFlag = (LPUART_STAT_NF_MASK),
kLPUART_FramingErrorFlag,
kLPUART_ParityErrorFlag = (LPUART_STAT_PF_MASK),
kLPUART_LinBreakFlag = (LPUART_STAT_LBKDIF_MASK),
kLPUART_RxActiveEdgeFlag = (LPUART_STAT_RXEDGIF_MASK),
kLPUART_RxActiveFlag,
kLPUART_DataMatch1Flag,
kLPUART_DataMatch2Flag
} |
| LPUART status flags. More...
|
|
|
void | LPUART_TransferCreateHandle (LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_callback_t callback, void *userData) |
| Initializes the LPUART handle. More...
|
|
status_t | LPUART_TransferSendNonBlocking (LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_t *xfer) |
| Transmits a buffer of data using the interrupt method. More...
|
|
void | LPUART_TransferStartRingBuffer (LPUART_Type *base, lpuart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize) |
| Sets up the RX ring buffer. More...
|
|
void | LPUART_TransferStopRingBuffer (LPUART_Type *base, lpuart_handle_t *handle) |
| Aborts the background transfer and uninstalls the ring buffer. More...
|
|
size_t | LPUART_TransferGetRxRingBufferLength (LPUART_Type *base, lpuart_handle_t *handle) |
| Get the length of received data in RX ring buffer. More...
|
|
void | LPUART_TransferAbortSend (LPUART_Type *base, lpuart_handle_t *handle) |
| Aborts the interrupt-driven data transmit. More...
|
|
status_t | LPUART_TransferGetSendCount (LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count) |
| Gets the number of bytes that have been sent out to bus. More...
|
|
status_t | LPUART_TransferReceiveNonBlocking (LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_t *xfer, size_t *receivedBytes) |
| Receives a buffer of data using the interrupt method. More...
|
|
void | LPUART_TransferAbortReceive (LPUART_Type *base, lpuart_handle_t *handle) |
| Aborts the interrupt-driven data receiving. More...
|
|
status_t | LPUART_TransferGetReceiveCount (LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count) |
| Gets the number of bytes that have been received. More...
|
|
void | LPUART_TransferHandleIRQ (LPUART_Type *base, void *irqHandle) |
| LPUART IRQ handle function. More...
|
|
void | LPUART_TransferHandleErrorIRQ (LPUART_Type *base, void *irqHandle) |
| LPUART Error IRQ handle function. More...
|
|
uint8_t* lpuart_transfer_t::data |
uint8_t* lpuart_transfer_t::rxData |
const uint8_t* lpuart_transfer_t::txData |
size_t lpuart_transfer_t::dataSize |
const uint8_t* volatile lpuart_handle_t::txData |
volatile size_t lpuart_handle_t::txDataSize |
size_t lpuart_handle_t::txDataSizeAll |
uint8_t* volatile lpuart_handle_t::rxData |
volatile size_t lpuart_handle_t::rxDataSize |
size_t lpuart_handle_t::rxDataSizeAll |
uint8_t* lpuart_handle_t::rxRingBuffer |
size_t lpuart_handle_t::rxRingBufferSize |
volatile uint16_t lpuart_handle_t::rxRingBufferHead |
volatile uint16_t lpuart_handle_t::rxRingBufferTail |
void* lpuart_handle_t::userData |
volatile uint8_t lpuart_handle_t::txState |
volatile uint8_t lpuart_handle_t::rxState |
#define UART_RETRY_TIMES 0U /* Defining to zero means to keep waiting for the flag until it is assert/deassert. */ |
typedef void(* lpuart_transfer_callback_t)(LPUART_Type *base, lpuart_handle_t *handle, status_t status, void *userData) |
Enumerator |
---|
kStatus_LPUART_TxBusy |
TX busy.
|
kStatus_LPUART_RxBusy |
RX busy.
|
kStatus_LPUART_TxIdle |
LPUART transmitter is idle.
|
kStatus_LPUART_RxIdle |
LPUART receiver is idle.
|
kStatus_LPUART_TxWatermarkTooLarge |
TX FIFO watermark too large.
|
kStatus_LPUART_RxWatermarkTooLarge |
RX FIFO watermark too large.
|
kStatus_LPUART_FlagCannotClearManually |
Some flag can't manually clear.
|
kStatus_LPUART_Error |
Error happens on LPUART.
|
kStatus_LPUART_RxRingBufferOverrun |
LPUART RX software ring buffer overrun.
|
kStatus_LPUART_RxHardwareOverrun |
LPUART RX receiver overrun.
|
kStatus_LPUART_NoiseError |
LPUART noise error.
|
kStatus_LPUART_FramingError |
LPUART framing error.
|
kStatus_LPUART_ParityError |
LPUART parity error.
|
kStatus_LPUART_BaudrateNotSupport |
Baudrate is not support in current clock source.
|
kStatus_LPUART_IdleLineDetected |
IDLE flag.
|
kStatus_LPUART_Timeout |
LPUART times out.
|
Enumerator |
---|
kLPUART_ParityDisabled |
Parity disabled.
|
kLPUART_ParityEven |
Parity enabled, type even, bit setting: PE|PT = 10.
|
kLPUART_ParityOdd |
Parity enabled, type odd, bit setting: PE|PT = 11.
|
Enumerator |
---|
kLPUART_EightDataBits |
Eight data bit.
|
Enumerator |
---|
kLPUART_OneStopBit |
One stop bit.
|
kLPUART_TwoStopBit |
Two stop bits.
|
Enumerator |
---|
kLPUART_CtsSourcePin |
CTS resource is the LPUART_CTS pin.
|
kLPUART_CtsSourceMatchResult |
CTS resource is the match result.
|
Enumerator |
---|
kLPUART_CtsSampleAtStart |
CTS input is sampled at the start of each character.
|
kLPUART_CtsSampleAtIdle |
CTS input is sampled when the transmitter is idle.
|
Enumerator |
---|
kLPUART_IdleTypeStartBit |
Start counting after a valid start bit.
|
kLPUART_IdleTypeStopBit |
Start counting after a stop bit.
|
This structure defines the number of idle characters that must be received before the IDLE flag is set.
Enumerator |
---|
kLPUART_IdleCharacter1 |
the number of idle characters.
|
kLPUART_IdleCharacter2 |
the number of idle characters.
|
kLPUART_IdleCharacter4 |
the number of idle characters.
|
kLPUART_IdleCharacter8 |
the number of idle characters.
|
kLPUART_IdleCharacter16 |
the number of idle characters.
|
kLPUART_IdleCharacter32 |
the number of idle characters.
|
kLPUART_IdleCharacter64 |
the number of idle characters.
|
kLPUART_IdleCharacter128 |
the number of idle characters.
|
This structure contains the settings for all LPUART interrupt configurations.
Enumerator |
---|
kLPUART_LinBreakInterruptEnable |
LIN break detect.
bit 7
|
kLPUART_RxActiveEdgeInterruptEnable |
Receive Active Edge.
bit 6
|
kLPUART_TxDataRegEmptyInterruptEnable |
Transmit data register empty.
bit 23
|
kLPUART_TransmissionCompleteInterruptEnable |
Transmission complete.
bit 22
|
kLPUART_RxDataRegFullInterruptEnable |
Receiver data register full.
bit 21
|
kLPUART_IdleLineInterruptEnable |
Idle line.
bit 20
|
kLPUART_RxOverrunInterruptEnable |
Receiver Overrun.
bit 27
|
kLPUART_NoiseErrorInterruptEnable |
Noise error flag.
bit 26
|
kLPUART_FramingErrorInterruptEnable |
Framing error flag.
bit 25
|
kLPUART_ParityErrorInterruptEnable |
Parity error flag.
bit 24
|
kLPUART_Match1InterruptEnable |
Parity error flag.
bit 15
|
kLPUART_Match2InterruptEnable |
Parity error flag.
bit 14
|
This provides constants for the LPUART status flags for use in the LPUART functions.
Enumerator |
---|
kLPUART_TxDataRegEmptyFlag |
Transmit data register empty flag, sets when transmit buffer is empty.
bit 23
|
kLPUART_TransmissionCompleteFlag |
Transmission complete flag, sets when transmission activity complete.
bit 22
|
kLPUART_RxDataRegFullFlag |
Receive data register full flag, sets when the receive data buffer is full.
bit 21
|
kLPUART_IdleLineFlag |
Idle line detect flag, sets when idle line detected.
bit 20
|
kLPUART_RxOverrunFlag |
Receive Overrun, sets when new data is received before data is read from receive register.
bit 19
|
kLPUART_NoiseErrorFlag |
Receive takes 3 samples of each received bit.
If any of these samples differ, noise flag sets. bit 18
|
kLPUART_FramingErrorFlag |
Frame error flag, sets if logic 0 was detected where stop bit expected.
bit 17
|
kLPUART_ParityErrorFlag |
If parity enabled, sets upon parity error detection.
bit 16
|
kLPUART_LinBreakFlag |
LIN break detect interrupt flag, sets when LIN break char detected and LIN circuit enabled.
bit 31
|
kLPUART_RxActiveEdgeFlag |
Receive pin active edge interrupt flag, sets when active edge detected.
bit 30
|
kLPUART_RxActiveFlag |
Receiver Active Flag (RAF), sets at beginning of valid start.
bit 24
|
kLPUART_DataMatch1Flag |
The next character to be read from LPUART_DATA matches MA1.
bit 15
|
kLPUART_DataMatch2Flag |
The next character to be read from LPUART_DATA matches MA2.
bit 14
|
This function configures the LPUART module with user-defined settings. Call the LPUART_GetDefaultConfig() function to configure the configuration structure and get the default configuration. The example below shows how to use this API to configure the LPUART.
* lpuartConfig.
isMsb =
false;
* lpuartConfig.txFifoWatermark = 0;
* lpuartConfig.rxFifoWatermark = 1;
*
- Parameters
-
base | LPUART peripheral base address. |
config | Pointer to a user-defined configuration structure. |
srcClock_Hz | LPUART clock source frequency in HZ. |
- Return values
-
kStatus_LPUART_BaudrateNotSupport | Baudrate is not support in current clock source. |
kStatus_Success | LPUART initialize succeed |
void LPUART_Deinit |
( |
LPUART_Type * |
base | ) |
|
This function waits for transmit to complete, disables TX and RX, and disables the LPUART clock.
- Parameters
-
base | LPUART peripheral base address. |
This function initializes the LPUART configuration structure to a default value. The default values are: lpuartConfig->baudRate_Bps = 115200U; lpuartConfig->parityMode = kLPUART_ParityDisabled; lpuartConfig->dataBitsCount = kLPUART_EightDataBits; lpuartConfig->isMsb = false; lpuartConfig->stopBitCount = kLPUART_OneStopBit; lpuartConfig->txFifoWatermark = 0; lpuartConfig->rxFifoWatermark = 1; lpuartConfig->rxIdleType = kLPUART_IdleTypeStartBit; lpuartConfig->rxIdleConfig = kLPUART_IdleCharacter1; lpuartConfig->enableTx = false; lpuartConfig->enableRx = false;
- Parameters
-
config | Pointer to a configuration structure. |
status_t LPUART_SetBaudRate |
( |
LPUART_Type * |
base, |
|
|
uint32_t |
baudRate_Bps, |
|
|
uint32_t |
srcClock_Hz |
|
) |
| |
This function configures the LPUART module baudrate. This function is used to update the LPUART module baudrate after the LPUART module is initialized by the LPUART_Init.
- Parameters
-
base | LPUART peripheral base address. |
baudRate_Bps | LPUART baudrate to be set. |
srcClock_Hz | LPUART clock source frequency in HZ. |
- Return values
-
kStatus_LPUART_BaudrateNotSupport | Baudrate is not supported in the current clock source. |
kStatus_Success | Set baudrate succeeded. |
void LPUART_Enable9bitMode |
( |
LPUART_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
This function set the 9-bit mode for LPUART module. The 9th bit is not used for parity thus can be modified by user.
- Parameters
-
base | LPUART peripheral base address. |
enable | true to enable, flase to disable. |
static void LPUART_SetMatchAddress |
( |
LPUART_Type * |
base, |
|
|
uint16_t |
address1, |
|
|
uint16_t |
address2 |
|
) |
| |
|
inlinestatic |
This function configures the address for LPUART module that works as slave in 9-bit data mode. One or two address fields can be configured. When the address field's match enable bit is set, the frame it receices with MSB being 1 is considered as an address frame, otherwise it is considered as data frame. Once the address frame matches one of slave's own addresses, this slave is addressed. This address frame and its following data frames are stored in the receive buffer, otherwise the frames will be discarded. To un-address a slave, just send an address frame with unmatched address.
- Note
- Any LPUART instance joined in the multi-slave system can work as slave. The position of the address mark is the same as the parity bit when parity is enabled for 8 bit and 9 bit data formats.
- Parameters
-
base | LPUART peripheral base address. |
address1 | LPUART slave address1. |
address2 | LPUART slave address2. |
static void LPUART_EnableMatchAddress |
( |
LPUART_Type * |
base, |
|
|
bool |
match1, |
|
|
bool |
match2 |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | LPUART peripheral base address. |
match1 | true to enable match address1, false to disable. |
match2 | true to enable match address2, false to disable. |
uint32_t LPUART_GetStatusFlags |
( |
LPUART_Type * |
base | ) |
|
This function gets all LPUART status flags. The flags are returned as the logical OR value of the enumerators _lpuart_flags. To check for a specific status, compare the return value with enumerators in the _lpuart_flags. For example, to check whether the TX is empty:
- Parameters
-
base | LPUART peripheral base address. |
- Returns
- LPUART status flags which are ORed by the enumerators in the _lpuart_flags.
status_t LPUART_ClearStatusFlags |
( |
LPUART_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
This function clears LPUART status flags with a provided mask. Automatically cleared flags can't be cleared by this function. Flags that can only cleared or set by hardware are: kLPUART_TxDataRegEmptyFlag, kLPUART_TransmissionCompleteFlag, kLPUART_RxDataRegFullFlag, kLPUART_RxActiveFlag, kLPUART_NoiseErrorFlag, kLPUART_ParityErrorFlag, kLPUART_TxFifoEmptyFlag,kLPUART_RxFifoEmptyFlag Note: This API should be called when the Tx/Rx is idle, otherwise it takes no effects.
- Parameters
-
base | LPUART peripheral base address. |
mask | the status flags to be cleared. The user can use the enumerators in the _lpuart_status_flag_t to do the OR operation and get the mask. |
- Returns
- 0 succeed, others failed.
- Return values
-
kStatus_LPUART_FlagCannotClearManually | The flag can't be cleared by this function but it is cleared automatically by hardware. |
kStatus_Success | Status in the mask are cleared. |
void LPUART_EnableInterrupts |
( |
LPUART_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
This function enables the LPUART interrupts according to a provided mask. The mask is a logical OR of enumeration members. See the _lpuart_interrupt_enable. This examples shows how to enable TX empty interrupt and RX full interrupt:
- Parameters
-
void LPUART_DisableInterrupts |
( |
LPUART_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
This function disables the LPUART interrupts according to a provided mask. The mask is a logical OR of enumeration members. See _lpuart_interrupt_enable. This example shows how to disable the TX empty interrupt and RX full interrupt:
- Parameters
-
uint32_t LPUART_GetEnabledInterrupts |
( |
LPUART_Type * |
base | ) |
|
This function gets the enabled LPUART interrupts. The enabled interrupts are returned as the logical OR value of the enumerators _lpuart_interrupt_enable. To check a specific interrupt enable status, compare the return value with enumerators in _lpuart_interrupt_enable. For example, to check whether the TX empty interrupt is enabled:
- Parameters
-
base | LPUART peripheral base address. |
- Returns
- LPUART interrupt flags which are logical OR of the enumerators in _lpuart_interrupt_enable.
static uint32_t LPUART_GetDataRegisterAddress |
( |
LPUART_Type * |
base | ) |
|
|
inlinestatic |
This function returns the LPUART data register address, which is mainly used by the DMA/eDMA.
- Parameters
-
base | LPUART peripheral base address. |
- Returns
- LPUART data register addresses which are used both by the transmitter and receiver.
static void LPUART_EnableTxDMA |
( |
LPUART_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables or disables the transmit data register empty flag, STAT[TDRE], to generate DMA requests.
- Parameters
-
base | LPUART peripheral base address. |
enable | True to enable, false to disable. |
static void LPUART_EnableRxDMA |
( |
LPUART_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables or disables the receiver data register full flag, STAT[RDRF], to generate DMA requests.
- Parameters
-
base | LPUART peripheral base address. |
enable | True to enable, false to disable. |
uint32_t LPUART_GetInstance |
( |
LPUART_Type * |
base | ) |
|
- Parameters
-
base | LPUART peripheral base address. |
- Returns
- LPUART instance.
static void LPUART_EnableTx |
( |
LPUART_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables or disables the LPUART transmitter.
- Parameters
-
base | LPUART peripheral base address. |
enable | True to enable, false to disable. |
static void LPUART_EnableRx |
( |
LPUART_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables or disables the LPUART receiver.
- Parameters
-
base | LPUART peripheral base address. |
enable | True to enable, false to disable. |
static void LPUART_WriteByte |
( |
LPUART_Type * |
base, |
|
|
uint8_t |
data |
|
) |
| |
|
inlinestatic |
This function writes data to the transmitter register directly. The upper layer must ensure that the TX register is empty or that the TX FIFO has room before calling this function.
- Parameters
-
base | LPUART peripheral base address. |
data | Data write to the TX register. |
static uint8_t LPUART_ReadByte |
( |
LPUART_Type * |
base | ) |
|
|
inlinestatic |
This function reads data from the receiver register directly. The upper layer must ensure that the receiver register is full or that the RX FIFO has data before calling this function.
- Parameters
-
base | LPUART peripheral base address. |
- Returns
- Data read from data register.
void LPUART_SendAddress |
( |
LPUART_Type * |
base, |
|
|
uint8_t |
address |
|
) |
| |
- Parameters
-
base | LPUART peripheral base address. |
address | LPUART slave address. |
status_t LPUART_WriteBlocking |
( |
LPUART_Type * |
base, |
|
|
const uint8_t * |
data, |
|
|
size_t |
length |
|
) |
| |
This function polls the transmitter register, first waits for the register to be empty or TX FIFO to have room, and writes data to the transmitter buffer, then waits for the dat to be sent out to the bus.
- Parameters
-
base | LPUART peripheral base address. |
data | Start address of the data to write. |
length | Size of the data to write. |
- Return values
-
kStatus_LPUART_Timeout | Transmission timed out and was aborted. |
kStatus_Success | Successfully wrote all data. |
status_t LPUART_ReadBlocking |
( |
LPUART_Type * |
base, |
|
|
uint8_t * |
data, |
|
|
size_t |
length |
|
) |
| |
This function polls the receiver register, waits for the receiver register full or receiver FIFO has data, and reads data from the TX register.
- Parameters
-
base | LPUART peripheral base address. |
data | Start address of the buffer to store the received data. |
length | Size of the buffer. |
- Return values
-
kStatus_LPUART_RxHardwareOverrun | Receiver overrun happened while receiving data. |
kStatus_LPUART_NoiseError | Noise error happened while receiving data. |
kStatus_LPUART_FramingError | Framing error happened while receiving data. |
kStatus_LPUART_ParityError | Parity error happened while receiving data. |
kStatus_LPUART_Timeout | Transmission timed out and was aborted. |
kStatus_Success | Successfully received all data. |
void LPUART_TransferCreateHandle |
( |
LPUART_Type * |
base, |
|
|
lpuart_handle_t * |
handle, |
|
|
lpuart_transfer_callback_t |
callback, |
|
|
void * |
userData |
|
) |
| |
This function initializes the LPUART handle, which can be used for other LPUART transactional APIs. Usually, for a specified LPUART instance, call this API once to get the initialized handle.
The LPUART 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 LPUART_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
-
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
callback | Callback function. |
userData | User data. |
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 LPUART driver calls the callback function and passes the kStatus_LPUART_TxIdle as status parameter.
- Note
- The kStatus_LPUART_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 kLPUART_TransmissionCompleteFlag to ensure that the transmit is finished.
- Parameters
-
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
xfer | LPUART transfer structure, see lpuart_transfer_t. |
- Return values
-
kStatus_Success | Successfully start the data transmission. |
kStatus_LPUART_TxBusy | Previous transmission still not finished, data not all written to the TX register. |
kStatus_InvalidArgument | Invalid argument. |
void LPUART_TransferStartRingBuffer |
( |
LPUART_Type * |
base, |
|
|
lpuart_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
-
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
ringBuffer | Start address of ring buffer for background receiving. Pass NULL to disable the ring buffer. |
ringBufferSize | size of the ring buffer. |
void LPUART_TransferStopRingBuffer |
( |
LPUART_Type * |
base, |
|
|
lpuart_handle_t * |
handle |
|
) |
| |
This function aborts the background transfer and uninstalls the ring buffer.
- Parameters
-
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
size_t LPUART_TransferGetRxRingBufferLength |
( |
LPUART_Type * |
base, |
|
|
lpuart_handle_t * |
handle |
|
) |
| |
- Parameters
-
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
- Returns
- Length of received data in RX ring buffer.
void LPUART_TransferAbortSend |
( |
LPUART_Type * |
base, |
|
|
lpuart_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
-
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
status_t LPUART_TransferGetSendCount |
( |
LPUART_Type * |
base, |
|
|
lpuart_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
-
base | LPUART peripheral base address. |
handle | LPUART 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 LPUART_TransferReceiveNonBlocking |
( |
LPUART_Type * |
base, |
|
|
lpuart_handle_t * |
handle, |
|
|
lpuart_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 LPUART driver. When the new data arrives, the receive request is serviced first. When all data is received, the LPUART 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 LPUART 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
-
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
xfer | LPUART transfer structure, see uart_transfer_t. |
receivedBytes | Bytes received from the ring buffer directly. |
- Return values
-
kStatus_Success | Successfully queue the transfer into the transmit queue. |
kStatus_LPUART_RxBusy | Previous receive request is not finished. |
kStatus_InvalidArgument | Invalid argument. |
void LPUART_TransferAbortReceive |
( |
LPUART_Type * |
base, |
|
|
lpuart_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 | LPUART peripheral base address. |
handle | LPUART handle pointer. |
status_t LPUART_TransferGetReceiveCount |
( |
LPUART_Type * |
base, |
|
|
lpuart_handle_t * |
handle, |
|
|
uint32_t * |
count |
|
) |
| |
This function gets the number of bytes that have been received.
- Parameters
-
base | LPUART peripheral base address. |
handle | LPUART 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 LPUART_TransferHandleIRQ |
( |
LPUART_Type * |
base, |
|
|
void * |
irqHandle |
|
) |
| |
This function handles the LPUART transmit and receive IRQ request.
- Parameters
-
base | LPUART peripheral base address. |
irqHandle | LPUART handle pointer. |
void LPUART_TransferHandleErrorIRQ |
( |
LPUART_Type * |
base, |
|
|
void * |
irqHandle |
|
) |
| |
This function handles the LPUART error IRQ request.
- Parameters
-
base | LPUART peripheral base address. |
irqHandle | LPUART handle pointer. |