29#if (HAL_USE_UART == TRUE) || defined(__DOXYGEN__)
42#if (KINETIS_UART_USE_UART1 == TRUE) || defined(__DOXYGEN__)
45#if (KINETIS_UART_USE_UART2 == TRUE) || defined(__DOXYGEN__)
48#if (KINETIS_UART_USE_UART3 == TRUE) || defined(__DOXYGEN__)
74#ifdef UART_USE_RING_BUFFER
76 if (!port_is_isr_context()) {
83 base->STAT |= LPUART_STAT_RXINV_MASK;
93 _uart_tx1_isr_code(uartp);
96 _uart_rx_complete_isr_code(uartp);
100 _uart_rx_error_isr_code(uartp, UART_OVERRUN_ERROR);
103 _uart_rx_error_isr_code(uartp, UART_FRAMING_ERROR);
106 _uart_rx_error_isr_code(uartp, UART_PARITY_ERROR);
109 _uart_rx_error_isr_code(uartp, UART_NOISE_ERROR);
125#if KINETIS_UART_USE_UART1 == TRUE
130#if KINETIS_UART_USE_UART2 == TRUE
135#if KINETIS_UART_USE_UART3 == TRUE
150 if (uartp->
state == UART_STOP) {
161#ifdef UART_USE_RING_BUFFER
166 dma_request_source_t reqRx, reqTx;
167 uint32_t dmaStreamRx, dmaStreamTx;
169#if KINETIS_UART_USE_UART1 == TRUE
172 reqRx = kDmaRequestMux0LPUART0Rx;
173 reqTx = kDmaRequestMux0LPUART0Tx;
174 dmaStreamRx = KINETIS_DMA_STREAM_UART0_RX;
175 dmaStreamTx = KINETIS_DMA_STREAM_UART0_TX;
176 nvicEnableVector(LPUART0_TX_IRQn, KINETIS_UART0_IRQ_PRIORITY);
177 nvicEnableVector(LPUART0_RX_IRQn, KINETIS_UART0_IRQ_PRIORITY);
181#if KINETIS_UART_USE_UART2 == TRUE
184 reqRx = kDmaRequestMux0LPUART1Rx;
185 reqTx = kDmaRequestMux0LPUART1Tx;
186 dmaStreamRx = KINETIS_DMA_STREAM_UART1_RX;
187 dmaStreamTx = KINETIS_DMA_STREAM_UART1_TX;
188 nvicEnableVector(LPUART1_TX_IRQn, KINETIS_UART1_IRQ_PRIORITY);
189 nvicEnableVector(LPUART1_RX_IRQn, KINETIS_UART1_IRQ_PRIORITY);
193#if KINETIS_UART_USE_UART3 == TRUE
196 reqRx = kDmaRequestMux0LPUART2Rx;
197 reqTx = kDmaRequestMux0LPUART2Tx;
198 dmaStreamRx = KINETIS_DMA_STREAM_UART2_RX;
199 dmaStreamTx = KINETIS_DMA_STREAM_UART2_TX;
200 nvicEnableVector(LPUART2_TX_IRQn, KINETIS_UART2_IRQ_PRIORITY);
201 nvicEnableVector(LPUART2_RX_IRQn, KINETIS_UART2_IRQ_PRIORITY);
209 static const int defaultBaudRate = 115200;
218 nvicEnableVector(DMA0_IRQn + dmaStreamRx, KINETIS_UART_DMA_IRQ_PRIORITY);
219 nvicEnableVector(DMA0_IRQn + dmaStreamTx, KINETIS_UART_DMA_IRQ_PRIORITY);
236#ifdef UART_USE_RING_BUFFER
254 if (uartp->
state == UART_READY) {
258#if KINETIS_UART_USE_UART1 == TRUE
260 nvicDisableVector(LPUART0_TX_IRQn);
261 nvicDisableVector(LPUART0_RX_IRQn);
267#if KINETIS_UART_USE_UART2 == TRUE
269 nvicDisableVector(LPUART1_TX_IRQn);
270 nvicDisableVector(LPUART1_RX_IRQn);
276#if KINETIS_UART_USE_UART3 == TRUE
278 nvicDisableVector(LPUART2_TX_IRQn);
279 nvicDisableVector(LPUART2_RX_IRQn);
302 xfer.
data = (uint8_t *)txbuf;
340 xfer.
data = (uint8_t *)rxbuf;
343#ifdef UART_USE_RING_BUFFER
344 size_t receivedBytes = 0U;
368 uint32_t numReceived = 0;
369#ifdef UART_USE_RING_BUFFER
void uart_lld_start_send(UARTDriver *uartp, size_t n, const void *txbuf)
Starts a transmission on the UART peripheral.
void uart_lld_blocking_send(UARTDriver *uartp, size_t n, const void *txbuf)
void uart_lld_start(UARTDriver *uartp)
Configures and activates the UART peripheral.
UARTDriver UARTD1
UART1 driver identifier.
void uart_lld_init(void)
Low level UART driver initialization.
static void uart_enter_rx_idle_loop(UARTDriver *uartp)
Puts the receiver in the UART_RX_IDLE state.
size_t uart_lld_stop_send(UARTDriver *uartp)
Stops any ongoing transmission.
void uart_lld_start_receive(UARTDriver *uartp, size_t n, void *rxbuf)
Starts a receive operation on the UART peripheral.
size_t uart_lld_stop_receive(UARTDriver *uartp)
Stops any ongoing receive operation.
void uart_lld_stop(UARTDriver *uartp)
Deactivates the UART peripheral.
void uart_lld_callback(LPUART_Type *base, void *handle, status_t status, void *userData)
static void DMAMUX_DisableChannel(DMAMUX_Type *base, uint32_t channel)
Disables the DMAMUX channel.
static void DMAMUX_SetSource(DMAMUX_Type *base, uint32_t channel, uint32_t source)
Configures the DMAMUX channel source.
static void DMAMUX_EnableChannel(DMAMUX_Type *base, uint32_t channel)
Enables the DMAMUX channel.
void EDMA_CreateHandle(edma_handle_t *handle, DMA_Type *base, uint32_t channel)
Creates the eDMA handle.
int32_t status_t
Type used for all status and error return values.
@ kStatus_NoTransferInProgress
void LPUART_TransferCreateHandle(LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_callback_t callback, void *userData)
Initializes the LPUART handle.
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.
void LPUART_Deinit(LPUART_Type *base)
Deinitializes a LPUART instance.
lpuart_parity_mode_t parityMode
void LPUART_TransferAbortReceive(LPUART_Type *base, lpuart_handle_t *handle)
Aborts the interrupt-driven data receiving.
void LPUART_TransferStartRingBuffer(LPUART_Type *base, lpuart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize)
Sets up the RX ring buffer.
void(* lpuart_transfer_callback_t)(LPUART_Type *base, lpuart_handle_t *handle, status_t status, void *userData)
LPUART transfer callback function.
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.
lpuart_stop_bit_count_t stopBitCount
void LPUART_GetDefaultConfig(lpuart_config_t *config)
Gets the default configuration structure.
void LPUART_EnableInterrupts(LPUART_Type *base, uint32_t mask)
Enables LPUART interrupts according to a provided mask.
status_t LPUART_TransferGetReceiveCount(LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count)
Gets the number of bytes that have been received.
void LPUART_WriteBlocking(LPUART_Type *base, const uint8_t *data, size_t length)
Writes to the transmitter register using a blocking method.
static void LPUART_EnableRxDMA(LPUART_Type *base, bool enable)
Enables or disables the LPUART receiver DMA.
lpuart_data_bits_t dataBitsCount
@ kLPUART_RxDataRegFullInterruptEnable
@ kLPUART_RxOverrunInterruptEnable
@ kStatus_LPUART_FramingError
@ kStatus_LPUART_RxRingBufferOverrun
@ kStatus_LPUART_NoiseError
@ kStatus_LPUART_BaudrateNotSupport
@ kStatus_LPUART_ParityError
@ kStatus_LPUART_RxHardwareOverrun
status_t LPUART_SendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer)
Sends data using eDMA.
status_t LPUART_TransferGetReceiveCountEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, uint32_t *count)
Gets the number of received bytes.
void LPUART_TransferAbortSendEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle)
Aborts the sent data using eDMA.
void LPUART_TransferCreateHandleEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_edma_transfer_callback_t callback, void *userData, edma_handle_t *txEdmaHandle, edma_handle_t *rxEdmaHandle)
Initializes the LPUART handle which is used in transactional functions.
void(* lpuart_edma_transfer_callback_t)(LPUART_Type *base, lpuart_edma_handle_t *handle, status_t status, void *userData)
LPUART transfer callback function.
status_t LPUART_ReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle, lpuart_transfer_t *xfer)
Receives data using eDMA.
void LPUART_TransferAbortReceiveEDMA(LPUART_Type *base, lpuart_edma_handle_t *handle)
Aborts the received data using eDMA.
LPUART configuration structure.
LPUART transfer structure.
uint16_t cr1
Initialization value for the CR1 register.
uint16_t cr2
Initialization value for the CR2 register.
Structure representing an UART driver.
lpuart_edma_handle_t dmaHandle
LPUART common eDMA channel handle.
edma_handle_t lpuartRxEdmaHandle
eDMA transfer handles.
uartrxstate_t rxstate
Receiver state.
int pendingRxIrq
Used to trigger the IRQ from our software handler. See uart_lld_callback() and UART_USE_RING_BUFFER.
lpuart_handle_t rxHandle
Used for the RingBuffer mode or to handle UART errors in EDMA mode.
const UARTConfig * config
Current configuration data.
uartstate_t state
Driver state.
UART_DRIVER_EXT_FIELDS LPUART_Type * lpuart
Pointer to the USART registers block.
uint8_t rxRingBuffer[KINETIS_UART_RX_RING_BUFFER_SIZE]
uarttxstate_t txstate
Transmitter state.
edma_handle_t lpuartTxEdmaHandle