MCUXpresso SDK API Reference Manual  Rev 2.12.1
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Lpuart

Overview

Data Structures

struct  lpuart_baud_t
 LPUART driver baudrate configuration. More...
 
struct  lpuart_data_t
 lpuart data transfer configurations. More...
 
union  lpuart_config_t
 Union type to access the LPUART control bit configurations. More...
 

Macros

#define FSL_LPUART_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 Defines LPUART driver version 2.0.1. More...
 

Typedefs

typedef void(* lpuartCallBack )(uint8_t *data, uint32_t length, status_t status)
 lpuart callback pointer. More...
 

Enumerations

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_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_RxActiveEdgeFlag = (LPUART_STAT_RXEDGIF_MASK),
  kLPUART_RxActiveFlag
}
 LPUART status flags. More...
 
enum  _lpuart_interrupt_enable {
  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)
}
 LPUART interrupt configuration structure, default settings all disabled. More...
 
enum  lpuart_source_clock_t
 LPUART driver source clock.
 
enum  lpuart_baudrate_t {
  kLPUART_BaudRate9600 = 0,
  kLPUART_BaudRate19200 = 1,
  kLPUART_BaudRate38400 = 2,
  kLPUART_BaudRate57600 = 3,
  kLPUART_BaudRate115200 = 4,
  kLPUART_BaudRate230400 = 5,
  kLPUART_BaudRate460800 = 6,
  kLPUART_BaudRate921600 = 7
}
 LPUART driver source clock. More...
 

Functions

status_t LPUART_Init (LPUART_Type *base, const lpuart_config_t *lpuartConfig, uint32_t sourceClock)
 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...
 
static void LPUART_SoftwareReset (LPUART_Type *base)
 Resets the LPUART using software. More...
 
status_t LPUART_Receive (LPUART_Type *base, uint8_t *data, uint32_t bufferSize, lpuartCallBack rxCallBack)
 Enable Lpuart Receive operation in interrupt mode with callback registered. More...
 
status_t LPUART_Transmit (LPUART_Type *base, uint8_t *data, uint32_t length, lpuartCallBack txCallBack)
 Perform Lpuart Transmit operation in interrupt mode with callback registered. More...
 
status_t LPUART_PollReceive (LPUART_Type *base, uint8_t *data, uint32_t *length)
 Enable Lpuart Receive operation in polling mode. More...
 
status_t LPUART_PollTransmit (LPUART_Type *base, uint8_t *data, uint32_t length)
 Enable Lpuart transmit operation in polling mode. More...
 
static void LPUART_EnableTxGPDMA (LPUART_Type *base, bool enable)
 Enables or disables the LPUART transmitter DMA request. More...
 
static void LPUART_EnableRxGPDMA (LPUART_Type *base, bool enable)
 Enables or disables the LPUART receiver DMA. More...
 
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_ClearTxFlagsInterrupts (LPUART_Type *base)
 Clears LPUART TX interrupt flags. More...
 
void LPUART_ClearRxFlagsInterrupts (LPUART_Type *base)
 Clears LPUART RX interrupt flags. More...
 
static uint32_t LPUART_GetDataRegisterAddress (LPUART_Type *base)
 Gets the LPUART data register address. More...
 
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_GetStatusFlags (LPUART_Type *base)
 Gets LPUART status flags. More...
 
status_t LPUART_RegisterRXCallBack (LPUART_Type *base, lpuartCallBack rxCallBack)
 Register the RX callback. More...
 
status_t LPUART_RegisterTXCallBack (LPUART_Type *base, lpuartCallBack txCallBack)
 Register the TX callback. More...
 

Data Structure Documentation

struct lpuart_baud_t
struct lpuart_data_t
union lpuart_config_t

Field Documentation

uint32_t lpuart_config_t::ParityEnable

Byte 0, bit[2:0]: Baud rate selection: 000 -> 9600, 001 -> 19200, 010 -> 38400, 011 -> 57600, 100 -> 115200, 101 -> 230400, 110 -> 460800, 111 -> 921600

uint32_t lpuart_config_t::ParityType

Byte 0, bit3: Parity Enable/Disable: 0 -> Disable, 1 -> Enable.

uint32_t lpuart_config_t::StopBits

Byte 0, bit4: Parity Type: 0 -> Even, 1 -> Odd

uint32_t lpuart_config_t::_reserved1

Byte 0, bit5: Stop bits: Number of stop bits. 0 -> 1 stop bit, 1 -> 2 stop bits

uint32_t lpuart_config_t::TXCTSE

Byte 0, bit[7:6]: RFU

uint32_t lpuart_config_t::TXRTSE

Byte 1, bit[0] : TXCTSE : Transmitter clear-to-send enable, controls the operation of the transmitter. 0-> CTS has no effect on the transmitter. 1-> Enables clear-to-send operation. Transmitter checks the state of CTS each time it is ready to send a character. If CTS is asserted, the character is sent. If CTS is deasserted, remains in mark state and transmission is delayed until CTS is asserted. NOTE: Do not set both RXRTSE and TXRTSE

uint32_t lpuart_config_t::TXRTSPOL

Byte 1, bit[1] : TXRTSE : Transmitter request-to-send enable. Controls RTS before and after a transmission. 0-> Transmitter has no effect on RTS. 1-> When a character is placed into an empty transmitter data buffer, RTS asserts one bit time before the start bit is transmitted. RTS deasserts one bit time after all characters are completely sent, including stop bit.

uint32_t lpuart_config_t::RXRTSE

Byte 1, bit[2] : TXRTSPOL : Transmitter request-to-send polarity. Controls the polarity of the transmitter RTS. TXRTSPOL does not affect the polarity of the receiver RTS. RTS will remain negated in the active low state unless TXRTSE is set. 0-> Transmitter RTS is active low. 1-> Transmitter RTS is active high.

uint32_t lpuart_config_t::TXCTSC

Byte 1, bit[3] : RXRTSE: Receiver request-to-send enable. Allows the RTS output to control the CTS input of the transmitting device to prevent receiver overrun. 0-> Receiver has no effect on RTS. 1-> RTS is deasserted if the receiver data register is full or a start bit has been detected that would cause receiver data reg to become full. RTS is asserted if the receiver data register is not full and has not detected a start bit that would cause the receiver data register to become full.

uint32_t lpuart_config_t::TXCTSSRC

Byte 1, bit[4] : TXCTSC: Transmit CTS Configuration: configure if CTS state is checked at start of each character or only when the transmitter is idle. 0-> CTS input is sampled at start of each character. 1-> Sampled when the transmitter is idle.

uint32_t lpuart_config_t::RTSWATER

Byte 1, bit[5] : TXCTSSRC: Transmit CTS Source: 0-> CTS input is CTS_B pin. 1-> CTS input is inverted Receiver Match result.

uint32_t lpuart_config_t::TxWaterMark

Byte 1, bit[7:6] : RTSWATER: Configures the assertion and negation of the RX RTS_B output.

uint32_t lpuart_config_t::RxWaterMark

Byte 2, bit[1:0]: Transmit Watermark, when the number of datawords in the transmit FIFO/buffer is equal to or less than the TxWaterMark value, an interrupt or a DMA request is generated.

Macro Definition Documentation

#define FSL_LPUART_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))

Typedef Documentation

typedef void(* lpuartCallBack)(uint8_t *data, uint32_t length, status_t status)

Enumeration Type Documentation

anonymous enum
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.

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_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

This structure contains the settings for all LPUART interrupt configurations.

Enumerator
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

Enumerator
kLPUART_BaudRate9600 

baudrate 9600

kLPUART_BaudRate19200 

baudrate 19200

kLPUART_BaudRate38400 

baudrate 38400

kLPUART_BaudRate57600 

baudrate 57600

kLPUART_BaudRate115200 

baudrate 115200

kLPUART_BaudRate230400 

baudrate 230400

kLPUART_BaudRate460800 

baudrate 460800

kLPUART_BaudRate921600 

baudrate 921600

Function Documentation

status_t LPUART_Init ( LPUART_Type *  base,
const lpuart_config_t lpuartConfig,
uint32_t  sourceClock 
)

This function configures the LPUART module with user-defined settings, see the LPUART_CTRL_t.

Parameters
baseLPUART peripheral base address.
lpuartConfigLPUART configuration pointer.
sourceClockLPUART source clock frequency.
Returns
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
baseLPUART peripheral base address.
static void LPUART_SoftwareReset ( LPUART_Type *  base)
inlinestatic

This function resets all internal logic and registers except the Global Register. Remains set until cleared by software.

Parameters
baseLPUART peripheral base address.
status_t LPUART_Receive ( LPUART_Type *  base,
uint8_t *  data,
uint32_t  bufferSize,
lpuartCallBack  rxCallBack 
)

This function is non-blocking call, clears error flags, enables reception with FIFO enabled in half duplex mode.

Parameters
dataPointer to memory to store received Lpuart data.
lengthPointer to memory to store length of received Lpuart data.
bufferSizeSize of the Rx buffer Pointer. Data received beyond this size will lead to loss of data and overflow error.
rxCallBackPointer to callback function on completion/error during Lpuart communication.
Returns
kStatus_Success LPUART receive succeed
status_t LPUART_Transmit ( LPUART_Type *  base,
uint8_t *  data,
uint32_t  length,
lpuartCallBack  txCallBack 
)

This function is non-blocking call, clears error flags, enable FIFO, kisk start Transmit in half duplex mode.

Parameters
dataPointer to memory to store received Lpuart data.
lengthPointer to memory to store length of received Lpuart data.
bufferSizeSize of the Rx buffer Pointer. Data received beyond this size will lead to loss of data and overflow error.
rxCallBackPointer to callback function on completion/error during Lpuart communication.
Returns
kStatus_InvalidArgument Parameter error
kStatus_Success LPUART receive succeed
status_t LPUART_PollReceive ( LPUART_Type *  base,
uint8_t *  data,
uint32_t *  length 
)

This function is blocking call, clears error flags, enables reception with FIFO enabled in half duplex mode.

Parameters
dataPointer to memory to store received Lpuart data.
lengthPointer to memory to store length of received Lpuart data.
Returns
kStatus_Success LPUART receive succeed
status_t LPUART_PollTransmit ( LPUART_Type *  base,
uint8_t *  data,
uint32_t  length 
)

This function is blocking call, clears error flags, enables transmission with FIFO enabled in half duplex mode.

Parameters
dataPointer to memory to store received Lpuart data.
lengthPointer to memory to store length of received Lpuart data.
Returns
kStatus_Success LPUART transmit succeed
static void LPUART_EnableTxGPDMA ( LPUART_Type *  base,
bool  enable 
)
inlinestatic

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 void LPUART_EnableRxGPDMA ( LPUART_Type *  base,
bool  enable 
)
inlinestatic

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

This function enables or disables the LPUART transmitter.

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

This function enables or disables the LPUART receiver.

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

This function returns the LPUART data register address, which is mainly used by the GPDMA.

Parameters
baseLPUART peripheral base address.
Returns
LPUART data register addresses which are used both by the transmitter and receiver.
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.

Parameters
baseLPUART peripheral base address.
maskThe interrupts to enable. Logical OR of _lpuart_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.

Parameters
baseLPUART peripheral base address.
maskThe interrupts to disable. Logical OR of _lpuart_interrupt_enable.
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.

Parameters
baseLPUART peripheral base address.
Returns
LPUART status flags which are ORed by the enumerators in the _lpuart_flags.
status_t LPUART_RegisterRXCallBack ( LPUART_Type *  base,
lpuartCallBack  rxCallBack 
)

This function can be used to monitor the error status during DMA transfer, note that in this case, the callback parameter data and length are invalid.

Parameters
baseLPUART peripheral base address.
rxCallBackCallback to register.
Return values
kStatus_SuccessRegister succeed.
kStatus_InvalidArgumentInvalid parameter.
status_t LPUART_RegisterTXCallBack ( LPUART_Type *  base,
lpuartCallBack  txCallBack 
)

This function can be used to monitor the error status during DMA transfer.

Parameters
baseLPUART peripheral base address.
txCallBackCallback to register.
Return values
kStatus_SuccessRegister succeed.
kStatus_InvalidArgumentInvalid parameter.