Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
Universal Asynchronous Receiver/Transmitter (LPUART)

Data Structures

struct  lpuart_config_t
 LPUART configure 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.
 

Enumerations

enum  _lpuart_status {
  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,
  kStatus_LPUART_Error = MAKE_STATUS(kStatusGroup_LPUART, 7),
  kStatus_LPUART_RxRingBufferOverrun,
  kStatus_LPUART_RxHardwareOverrun = MAKE_STATUS(kStatusGroup_LPUART, 9)
}
 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_stop_bit_count_t {
  kLPUART_OneStopBit = 0U,
  kLPUART_TwoStopBit = 1U
}
 LPUART stop bit count. More...
 
enum  _lpuart_interrupt_enable {
  kLPUART_LinBreakInterruptEnable = (LPUART_BAUD_LBKDIE_MASK >> 8),
  kLPUART_RxActiveEdgeInterruptEnable = (LPUART_BAUD_RXEDGIE_MASK >> 8),
  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_TxFifoOverflowInterruptEnable = (LPUART_FIFO_TXOFE_MASK >> 8),
  kLPUART_RxFifoUnderflowInterruptEnable = (LPUART_FIFO_RXUFE_MASK >> 8)
}
 LPUART interrupt configuration structure, default settings all disabled. More...
 
enum  _lpuart_flags {
  kLPUART_TxDataRegEmptyFlag,
  kLPUART_TransmissionCompleteFlag,
  kLPUART_RxDataRegFullFlag,
  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,
  kLPUART_RxActiveFlag,
  kLPUART_DataMatch1Flag = LPUART_STAT_MA1F_MASK,
  kLPUART_DataMatch2Flag = LPUART_STAT_MA2F_MASK,
  kLPUART_NoiseErrorInRxDataRegFlag,
  kLPUART_ParityErrorInRxDataRegFlag,
  kLPUART_TxFifoEmptyFlag = (LPUART_FIFO_TXEMPT_MASK >> 16),
  kLPUART_RxFifoEmptyFlag = (LPUART_FIFO_RXEMPT_MASK >> 16),
  kLPUART_TxFifoOverflowFlag,
  kLPUART_RxFifoUnderflowFlag
}
 LPUART status flags. More...
 

Initialization and deinitialization

void 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...
 
void 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...
 
void LPUART_WriteBlocking (LPUART_Type *base, const uint8_t *data, size_t length)
 Writes to transmitter register using a blocking method. More...
 
static void LPUART_WriteByte (LPUART_Type *base, uint8_t data)
 Writes to the transmitter register. More...
 
void LPUART_ReadBlocking (LPUART_Type *base, uint8_t *data, size_t length)
 Reads the RX data register using a blocking method. More...
 
static uint8_t LPUART_ReadByte (LPUART_Type *base)
 Reads the RX register. More...
 

Transactional

void LPUART_CreateHandle (LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_callback_t callback, void *userData)
 Initializes the LPUART handle. More...
 
status_t LPUART_SendNonBlocking (LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_t *xfer)
 Transmits a buffer of data using the interrupt method. More...
 
void LPUART_StartRingBuffer (LPUART_Type *base, lpuart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize)
 Sets up the RX ring buffer. More...
 
void LPUART_StopRingBuffer (LPUART_Type *base, lpuart_handle_t *handle)
 Abort the background transfer and uninstall the ring buffer. More...
 
void LPUART_AbortSend (LPUART_Type *base, lpuart_handle_t *handle)
 Aborts the interrupt-driven data transmit. More...
 
status_t LPUART_GetSendCount (LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count)
 Get the number of bytes that have been written to LPUART TX register. More...
 
status_t LPUART_ReceiveNonBlocking (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_AbortReceive (LPUART_Type *base, lpuart_handle_t *handle)
 Aborts the interrupt-driven data receiving. More...
 
status_t LPUART_GetReceiveCount (LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count)
 Get the number of bytes that have been received. More...
 
void LPUART_HandleIRQ (LPUART_Type *base, lpuart_handle_t *handle)
 LPUART IRQ handle function. More...
 
void LPUART_HandleErrorIRQ (LPUART_Type *base, lpuart_handle_t *handle)
 LPUART Error IRQ handle function. More...
 

Usage Information

The KSDK provides a peripheral driver for the Inter-Integrated Circuit (LPUART) module of Kinetis devices.


Data Structure Documentation

struct lpuart_config_t

LPUART configure structure.

Data Fields
uint32_t baudRate_Bps

LPUART baud rate

bool enableRx

Enable RX

bool enableTx

Enable TX

lpuart_parity_mode_t parityMode

Parity mode, disabled (default), even, odd

uint8_t rxFifoWatermark

RX FIFO watermark

lpuart_stop_bit_count_t stopBitCount

Number of stop bits, 1 stop bit (default) or 2 stop bits

uint8_t txFifoWatermark

TX FIFO watermark

struct lpuart_transfer_t

LPUART transfer structure.

Data Fields
uint8_t * data

The buffer of data to be transfer.

size_t dataSize

The byte count to be transfer.

struct _lpuart_handle

LPUART handle structure.

Data Fields
lpuart_transfer_callback_t callback

Callback function.

uint8_t *volatile rxData

Address of remaining data to receive.

volatile size_t rxDataSize

Size of the remaining data to receive.

size_t rxDataSizeAll

Size of the data to receive.

uint8_t * rxRingBuffer

Start address of the receiver ring buffer.

volatile uint16_t rxRingBufferHead

Index for the driver to store received data into ring buffer.

size_t rxRingBufferSize

Size of the ring buffer.

volatile uint16_t rxRingBufferTail

Index for the user to get data from the ring buffer.

volatile uint8_t rxState

RX transfer state

uint8_t *volatile txData

Address of remaining data to send.

volatile size_t txDataSize

Size of the remaining data to send.

size_t txDataSizeAll

Size of the data to send out.

volatile uint8_t txState

TX transfer state.

void * userData

LPUART callback function parameter.

Enumeration Type Documentation

LPUART status flags.

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

kLPUART_TransmissionCompleteFlag 

Transmission complete flag, sets when transmission activity complete

kLPUART_RxDataRegFullFlag 

Receive data register full flag, sets when the receive data buffer is full

kLPUART_IdleLineFlag 

Idle line detect flag, sets when idle line detected

kLPUART_RxOverrunFlag 

Receive Overrun, sets when new data is received before data is read from receive register

kLPUART_NoiseErrorFlag 

Receive takes 3 samples of each received bit. If any of these samples differ, noise flag sets

kLPUART_FramingErrorFlag 

Frame error flag, sets if logic 0 was detected where stop bit expected

kLPUART_ParityErrorFlag 

If parity enabled, sets upon parity error detection

kLPUART_LinBreakFlag 

LIN break detect interrupt flag, sets when LIN break char detected and LIN circuit enabled

kLPUART_RxActiveEdgeFlag 

Receive pin active edge interrupt flag, sets when active edge detected

kLPUART_RxActiveFlag 

Receiver Active Flag (RAF), sets at beginning of valid start bit

kLPUART_DataMatch1Flag 

The next character to be read from LPUART_DATA matches MA1

kLPUART_DataMatch2Flag 

The next character to be read from LPUART_DATA matches MA2

kLPUART_NoiseErrorInRxDataRegFlag 

NOISY bit, sets if noise detected in current data word

kLPUART_ParityErrorInRxDataRegFlag 

PARITYE bit, sets if noise detected in current data word

kLPUART_TxFifoEmptyFlag 

TXEMPT bit, sets if transmit buffer is empty

kLPUART_RxFifoEmptyFlag 

RXEMPT bit, sets if receive buffer is empty

kLPUART_TxFifoOverflowFlag 

TXOF bit, sets if transmit buffer overflow occurred

kLPUART_RxFifoUnderflowFlag 

RXUF bit, sets if receive buffer underflow occurred

LPUART interrupt configuration structure, default settings all disabled.

This structure contains the settings for all LPUART interrupt configurations.

Enumerator
kLPUART_LinBreakInterruptEnable 

LIN break detect.

kLPUART_RxActiveEdgeInterruptEnable 

Receive Active Edge.

kLPUART_TxDataRegEmptyInterruptEnable 

Transmit data register empty.

kLPUART_TransmissionCompleteInterruptEnable 

Transmission complete.

kLPUART_RxDataRegFullInterruptEnable 

Receiver data register full.

kLPUART_IdleLineInterruptEnable 

Idle line.

kLPUART_RxOverrunInterruptEnable 

Receiver Overrun.

kLPUART_NoiseErrorInterruptEnable 

Noise error flag.

kLPUART_FramingErrorInterruptEnable 

Framing error flag.

kLPUART_ParityErrorInterruptEnable 

Parity error flag.

kLPUART_TxFifoOverflowInterruptEnable 

Transmit FIFO Overflow.

kLPUART_RxFifoUnderflowInterruptEnable 

Receive FIFO Underflow.

Error codes for the LPUART driver.

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 not 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.

LPUART parity mode.

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

LPUART stop bit count.

Enumerator
kLPUART_OneStopBit 

One stop bit

kLPUART_TwoStopBit 

Two stop bits

Function Documentation

void LPUART_AbortReceive ( LPUART_Type *  base,
lpuart_handle_t *  handle 
)

Aborts the interrupt-driven data receiving.

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

Parameters
baseLPUART peripheral base address.
handleLPUART handle pointer.
void LPUART_AbortSend ( LPUART_Type *  base,
lpuart_handle_t *  handle 
)

Aborts the interrupt-driven data transmit.

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
baseLPUART peripheral base address.
handleLPUART handle pointer.
status_t LPUART_ClearStatusFlags ( LPUART_Type *  base,
uint32_t  mask 
)

Clears status flags with a provided 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

Parameters
baseLPUART peripheral base address.
maskthe 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_FlagCannotClearManuallyThe flag can't be cleared by this function but it is cleared automatically by hardware.
kStatus_SuccessStatus in the mask are cleared.
void LPUART_CreateHandle ( LPUART_Type *  base,
lpuart_handle_t *  handle,
lpuart_transfer_callback_t  callback,
void *  userData 
)

Initializes the LPUART handle.

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_ReceiveNonBlocking() 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
baseLPUART peripheral base address.
handleLPUART handle pointer.
callbackCallback function.
userDataUser data.
void LPUART_Deinit ( LPUART_Type *  base)

Deinitializes a LPUART instance.

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

Parameters
baseLPUART peripheral base address.
void LPUART_DisableInterrupts ( LPUART_Type *  base,
uint32_t  mask 
)

Disables LPUART interrupts according to a provided 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:

1 LPUART_DisableInterrupts(LPUART1,kLPUART_TxDataRegEmptyInterruptEnable | kLPUART_RxDataRegFullInterruptEnable);
Parameters
baseLPUART peripheral base address.
maskThe interrupts to disable. Logical OR of _lpuart_interrupt_enable.
void LPUART_EnableInterrupts ( LPUART_Type *  base,
uint32_t  mask 
)

Enables LPUART interrupts according to a provided 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:

1 LPUART_EnableInterrupts(LPUART1,kLPUART_TxDataRegEmptyInterruptEnable | kLPUART_RxDataRegFullInterruptEnable);
Parameters
baseLPUART peripheral base address.
maskThe interrupts to enable. Logical OR of _uart_interrupt_enable.
static void LPUART_EnableRx ( LPUART_Type *  base,
bool  enable 
)
inlinestatic

Enables or disables the LPUART receiver.

This function enables or disables the LPUART receiver.

Parameters
baseLPUART peripheral base address.
enableTrue to enable, false to disable.
static void LPUART_EnableRxDMA ( LPUART_Type *  base,
bool  enable 
)
inlinestatic

Enables or disables the LPUART receiver DMA.

This function enables or disables the receiver data register full flag, STAT[RDRF], to generate DMA requests.

Parameters
baseLPUART peripheral base address.
enableTrue to enable, false to disable.
static void LPUART_EnableTx ( LPUART_Type *  base,
bool  enable 
)
inlinestatic

Enables or disables the LPUART transmitter.

This function enables or disables the LPUART transmitter.

Parameters
baseLPUART peripheral base address.
enableTrue to enable, false to disable.
static void LPUART_EnableTxDMA ( LPUART_Type *  base,
bool  enable 
)
inlinestatic

Enables or disables the LPUART transmitter DMA request.

This function enables or disables the transmit data register empty flag, STAT[TDRE], to generate DMA requests.

Parameters
baseLPUART peripheral base address.
enableTrue to enable, false to disable.
static uint32_t LPUART_GetDataRegisterAddress ( LPUART_Type *  base)
inlinestatic

Gets the LPUART data register address.

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

Parameters
baseLPUART peripheral base address.
Returns
LPUART data register addresses which are used both by the transmitter and receiver.
void LPUART_GetDefaultConfig ( lpuart_config_t config)

Gets the default configuration structure.

This function initializes the LPUART configuration structure to a default value. The default values are: lpuartConfig->baudRate_Bps = 115200U; lpuartConfig->parityMode = kLPUART_ParityDisabled; lpuartConfig->stopBitCount = kLPUART_OneStopBit; lpuartConfig->txFifoWatermark = 0; lpuartConfig->rxFifoWatermark = 1; lpuartConfig->enableTx = false; lpuartConfig->enableRx = false;

Parameters
configPointer to a configuration structure.
uint32_t LPUART_GetEnabledInterrupts ( LPUART_Type *  base)

Gets enabled LPUART interrupts.

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:

1 uint32_t enabledInterrupts = LPUART_GetEnabledInterrupts(LPUART1);
2 
3 if (kLPUART_TxDataRegEmptyInterruptEnable & enabledInterrupts)
4 {
5  ...
6 }
Parameters
baseLPUART peripheral base address.
Returns
LPUART interrupt flags which are logical OR of the enumerators in _lpuart_interrupt_enable.
status_t LPUART_GetReceiveCount ( LPUART_Type *  base,
lpuart_handle_t *  handle,
uint32_t *  count 
)

Get the number of bytes that have been received.

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

Parameters
baseLPUART peripheral base address.
handleLPUART handle pointer.
countReceive bytes count.
Return values
kStatus_NoTransferInProgressNo receive in progress.
kStatus_InvalidArgumentParameter is invalid.
kStatus_SuccessGet successfully through the parameter count;
status_t LPUART_GetSendCount ( LPUART_Type *  base,
lpuart_handle_t *  handle,
uint32_t *  count 
)

Get the number of bytes that have been written to LPUART TX register.

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

Parameters
baseLPUART peripheral base address.
handleLPUART handle pointer.
countSend bytes count.
Return values
kStatus_NoTransferInProgressNo send in progress.
kStatus_InvalidArgumentParameter is invalid.
kStatus_SuccessGet successfully through the parameter count;
uint32_t LPUART_GetStatusFlags ( LPUART_Type *  base)

Gets LPUART status flags.

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:

1 if (kLPUART_TxDataRegEmptyFlag & LPUART_GetStatusFlags(LPUART1))
2 {
3  ...
4 }
Parameters
baseLPUART peripheral base address.
Returns
LPUART status flags which are ORed by the enumerators in the _lpuart_flags.
void LPUART_HandleErrorIRQ ( LPUART_Type *  base,
lpuart_handle_t *  handle 
)

LPUART Error IRQ handle function.

This function handles the LPUART error IRQ request.

Parameters
baseLPUART peripheral base address.
handleLPUART handle pointer.
void LPUART_HandleIRQ ( LPUART_Type *  base,
lpuart_handle_t *  handle 
)

LPUART IRQ handle function.

This function handles the LPUART transmit and receive IRQ request.

Parameters
baseLPUART peripheral base address.
handleLPUART handle pointer.
void 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.

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.

1 lpuart_config_t lpuartConfig;
2 lpuartConfig.baudRate_Bps = 115200U;
3 lpuartConfig.parityMode = kLPUART_ParityDisabled;
4 lpuartConfig.stopBitCount = kLPUART_OneStopBit;
5 lpuartConfig.txFifoWatermark = 0;
6 lpuartConfig.rxFifoWatermark = 1;
7 LPUART_Init(LPUART1, &lpuartConfig, 20000000U);
Parameters
baseLPUART peripheral base address.
configPointer to a user-defined configuration structure.
srcClock_HzLPUART clock source frequency in HZ.
void LPUART_ReadBlocking ( LPUART_Type *  base,
uint8_t *  data,
size_t  length 
)

Reads the RX data register using a blocking method.

This function polls the RX register, waits for the RX register full or RX FIFO has data then reads data from the TX register.

Parameters
baseLPUART peripheral base address.
dataStart address of the buffer to store the received data.
lengthSize of the buffer.
static uint8_t LPUART_ReadByte ( LPUART_Type *  base)
inlinestatic

Reads the RX register.

This function reads data from the TX 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
baseLPUART peripheral base address.
Returns
Data read from data register.
status_t LPUART_ReceiveNonBlocking ( LPUART_Type *  base,
lpuart_handle_t *  handle,
lpuart_transfer_t xfer,
size_t *  receivedBytes 
)

Receives a buffer of data using the interrupt method.

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
baseLPUART peripheral base address.
handleLPUART handle pointer.
xferLPUART transfer structure, refer to uart_transfer_t.
receivedBytesBytes received from the ring buffer directly.
Return values
kStatus_SuccessSuccessfully queue the transfer into the transmit queue.
kStatus_LPUART_RxBusyPrevious receive request is not finished.
status_t LPUART_SendNonBlocking ( LPUART_Type *  base,
lpuart_handle_t *  handle,
lpuart_transfer_t xfer 
)

Transmits a buffer of data using the interrupt method.

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
baseLPUART peripheral base address.
handleLPUART handle pointer.
xferLPUART transfer structure, refer to lpuart_transfer_t.
Return values
kStatus_SuccessSuccessfully start the data transmission.
kStatus_LPUART_TxBusyPrevious transmission still not finished, data not all written to the TX register.
void LPUART_SetBaudRate ( LPUART_Type *  base,
uint32_t  baudRate_Bps,
uint32_t  srcClock_Hz 
)

Sets the LPUART instance baudrate.

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.

1 LPUART_SetBaudRate(LPUART1, 115200U, 20000000U);
Parameters
baseLPUART peripheral base address.
baudRate_BpsLPUART baudrate to be set.
srcClock_HzLPUART clock source frequency in HZ.
void LPUART_StartRingBuffer ( LPUART_Type *  base,
lpuart_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 is stored into the ring buffer even when the user doesn't call the UART_ReceiveNonBlocking() 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
baseLPUART peripheral base address.
handleLPUART handle pointer.
ringBufferStart address of ring buffer for background receiving. Pass NULL to disable the ring buffer.
ringBufferSizesize of the ring buffer.
void LPUART_StopRingBuffer ( LPUART_Type *  base,
lpuart_handle_t *  handle 
)

Abort the background transfer and uninstall the ring buffer.

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

Parameters
baseLPUART peripheral base address.
handleLPUART handle pointer.
void LPUART_WriteBlocking ( LPUART_Type *  base,
const uint8_t *  data,
size_t  length 
)

Writes to transmitter register using a blocking method.

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

Note
This function does not check whether all data has been sent out to the bus. Before disabling the transmitter, check the kLPUART_TransmissionCompleteFlag to ensure that the transmit is finished.
Parameters
baseLPUART peripheral base address.
dataStart address of the data to write.
lengthSize of the data to write.
static void LPUART_WriteByte ( LPUART_Type *  base,
uint8_t  data 
)
inlinestatic

Writes to the transmitter register.

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
baseLPUART peripheral base address.
dataData write to the TX register.