MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The MCUXpresso SDK provides a peripheral driver for the Low Power UART (LPUART) module of MCUXpresso SDK devices.
Data Structures | |
struct | lpuart_config_t |
LPUART configuration structure. More... | |
struct | lpuart_transfer_t |
LPUART transfer structure. More... | |
struct | lpuart_handle_t |
LPUART handle structure. More... | |
Typedefs | |
typedef void(* | lpuart_transfer_callback_t )(LPUART_Type *base, lpuart_handle_t *handle, status_t status, void *userData) |
LPUART transfer callback function. More... | |
Driver version | |
#define | FSL_LPUART_DRIVER_VERSION (MAKE_VERSION(2, 2, 3)) |
LPUART driver version 2.2.3. More... | |
Initialization and deinitialization | |
status_t | LPUART_Init (LPUART_Type *base, const lpuart_config_t *config, uint32_t srcClock_Hz) |
Initializes an LPUART instance with the user configuration structure and the peripheral clock. More... | |
void | LPUART_Deinit (LPUART_Type *base) |
Deinitializes a LPUART instance. More... | |
void | LPUART_GetDefaultConfig (lpuart_config_t *config) |
Gets the default configuration structure. More... | |
status_t | LPUART_SetBaudRate (LPUART_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz) |
Sets the LPUART instance baudrate. More... | |
Status | |
uint32_t | LPUART_GetStatusFlags (LPUART_Type *base) |
Gets LPUART status flags. More... | |
status_t | LPUART_ClearStatusFlags (LPUART_Type *base, uint32_t mask) |
Clears status flags with a provided mask. More... | |
Interrupts | |
void | LPUART_EnableInterrupts (LPUART_Type *base, uint32_t mask) |
Enables LPUART interrupts according to a provided mask. More... | |
void | LPUART_DisableInterrupts (LPUART_Type *base, uint32_t mask) |
Disables LPUART interrupts according to a provided mask. More... | |
uint32_t | LPUART_GetEnabledInterrupts (LPUART_Type *base) |
Gets enabled LPUART interrupts. More... | |
static uint32_t | LPUART_GetDataRegisterAddress (LPUART_Type *base) |
Gets the LPUART data register address. More... | |
static void | LPUART_EnableTxDMA (LPUART_Type *base, bool enable) |
Enables or disables the LPUART transmitter DMA request. More... | |
static void | LPUART_EnableRxDMA (LPUART_Type *base, bool enable) |
Enables or disables the LPUART receiver DMA. More... | |
Bus Operations | |
static void | LPUART_EnableTx (LPUART_Type *base, bool enable) |
Enables or disables the LPUART transmitter. More... | |
static void | LPUART_EnableRx (LPUART_Type *base, bool enable) |
Enables or disables the LPUART receiver. More... | |
static void | LPUART_WriteByte (LPUART_Type *base, uint8_t data) |
Writes to the transmitter register. More... | |
static uint8_t | LPUART_ReadByte (LPUART_Type *base) |
Reads the receiver register. More... | |
void | LPUART_WriteBlocking (LPUART_Type *base, const uint8_t *data, size_t length) |
Writes to the transmitter register using a blocking method. More... | |
status_t | LPUART_ReadBlocking (LPUART_Type *base, uint8_t *data, size_t length) |
Reads the receiver data register using a blocking method. More... | |
Transactional | |
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... | |
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 written to the LPUART transmitter register. 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, lpuart_handle_t *handle) |
LPUART IRQ handle function. More... | |
void | LPUART_TransferHandleErrorIRQ (LPUART_Type *base, lpuart_handle_t *handle) |
LPUART Error IRQ handle function. More... | |
struct lpuart_config_t |
Data Fields | |
uint32_t | baudRate_Bps |
LPUART baud rate. | |
lpuart_parity_mode_t | parityMode |
Parity mode, disabled (default), even, odd. | |
lpuart_data_bits_t | dataBitsCount |
Data bits count, eight (default), seven. | |
bool | isMsb |
Data bits order, LSB (default), MSB. | |
lpuart_stop_bit_count_t | stopBitCount |
Number of stop bits, 1 stop bit (default) or 2 stop bits. | |
bool | enableTx |
Enable TX. | |
bool | enableRx |
Enable RX. | |
struct lpuart_transfer_t |
struct _lpuart_handle |
Data Fields | |
uint8_t *volatile | txData |
Address of remaining data to send. More... | |
volatile size_t | txDataSize |
Size of the remaining data to send. More... | |
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... | |
lpuart_transfer_callback_t | callback |
Callback function. More... | |
void * | userData |
LPUART callback function parameter. More... | |
volatile uint8_t | txState |
TX transfer state. More... | |
volatile uint8_t | rxState |
RX transfer state. More... | |
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 |
lpuart_transfer_callback_t lpuart_handle_t::callback |
void* lpuart_handle_t::userData |
volatile uint8_t lpuart_handle_t::txState |
volatile uint8_t lpuart_handle_t::rxState |
#define FSL_LPUART_DRIVER_VERSION (MAKE_VERSION(2, 2, 3)) |
typedef void(* lpuart_transfer_callback_t)(LPUART_Type *base, lpuart_handle_t *handle, status_t status, void *userData) |
enum _lpuart_status |
enum lpuart_parity_mode_t |
enum lpuart_data_bits_t |
This structure contains the settings for all LPUART interrupt configurations.
enum _lpuart_flags |
This provides constants for the LPUART status flags for use in the LPUART functions.
status_t LPUART_Init | ( | LPUART_Type * | base, |
const lpuart_config_t * | config, | ||
uint32_t | srcClock_Hz | ||
) |
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.
base | LPUART peripheral base address. |
config | Pointer to a user-defined configuration structure. |
srcClock_Hz | LPUART clock source frequency in HZ. |
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.
base | LPUART peripheral base address. |
void LPUART_GetDefaultConfig | ( | lpuart_config_t * | config | ) |
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->enableTx = false; lpuartConfig->enableRx = false;
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.
base | LPUART peripheral base address. |
baudRate_Bps | LPUART baudrate to be set. |
srcClock_Hz | LPUART clock source frequency in HZ. |
kStatus_LPUART_BaudrateNotSupport | Baudrate is not supported in the current clock source. |
kStatus_Success | Set baudrate succeeded. |
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:
base | LPUART peripheral base address. |
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_NoiseErrorInRxDataRegFlag, kLPUART_ParityErrorInRxDataRegFlag, kLPUART_TxFifoEmptyFlag,kLPUART_RxFifoEmptyFlag Note: This API should be called when the Tx/Rx is idle, otherwise it takes no effects.
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. |
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:
base | LPUART peripheral base address. |
mask | The interrupts to enable. Logical OR of _uart_interrupt_enable. |
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:
base | LPUART peripheral base address. |
mask | The interrupts to disable. Logical OR of _lpuart_interrupt_enable. |
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:
base | LPUART peripheral base address. |
|
inlinestatic |
This function returns the LPUART data register address, which is mainly used by the DMA/eDMA.
base | LPUART peripheral base address. |
|
inlinestatic |
This function enables or disables the transmit data register empty flag, STAT[TDRE], to generate DMA requests.
base | LPUART peripheral base address. |
enable | True to enable, false to disable. |
|
inlinestatic |
This function enables or disables the receiver data register full flag, STAT[RDRF], to generate DMA requests.
base | LPUART peripheral base address. |
enable | True to enable, false to disable. |
|
inlinestatic |
This function enables or disables the LPUART transmitter.
base | LPUART peripheral base address. |
enable | True to enable, false to disable. |
|
inlinestatic |
This function enables or disables the LPUART receiver.
base | LPUART peripheral base address. |
enable | True to enable, false to disable. |
|
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.
base | LPUART peripheral base address. |
data | Data write to the TX register. |
|
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.
base | LPUART peripheral base address. |
void LPUART_WriteBlocking | ( | LPUART_Type * | base, |
const uint8_t * | data, | ||
size_t | length | ||
) |
This function polls the transmitter register, waits for the register to be empty or for TX FIFO to have room, and writes data to the transmitter buffer.
base | LPUART peripheral base address. |
data | Start address of the data to write. |
length | Size of the data to write. |
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.
base | LPUART peripheral base address. |
data | Start address of the buffer to store the received data. |
length | Size of the buffer. |
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_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
.
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
callback | Callback function. |
userData | User data. |
status_t LPUART_TransferSendNonBlocking | ( | LPUART_Type * | base, |
lpuart_handle_t * | handle, | ||
lpuart_transfer_t * | xfer | ||
) |
This function send data using an interrupt method. This is a non-blocking function, which returns directly without waiting for all data written to the transmitter register. When all data is written to the TX register in the ISR, the LPUART driver calls the callback function and passes the kStatus_LPUART_TxIdle as status parameter.
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
xfer | LPUART transfer structure, see lpuart_transfer_t. |
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.
ringBufferSize
is 32, then only 31 bytes are used for saving data.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.
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
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.
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 written to LPUART TX register by an interrupt method.
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
count | Send bytes count. |
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.
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. |
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.
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.
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
count | Receive bytes count. |
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, |
lpuart_handle_t * | handle | ||
) |
This function handles the LPUART transmit and receive IRQ request.
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |
void LPUART_TransferHandleErrorIRQ | ( | LPUART_Type * | base, |
lpuart_handle_t * | handle | ||
) |
This function handles the LPUART error IRQ request.
base | LPUART peripheral base address. |
handle | LPUART handle pointer. |