Adding flow control to UART0 on MK22FN512 and FreeRTOS

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Adding flow control to UART0 on MK22FN512 and FreeRTOS

跳至解决方案
1,491 次查看
davepfaltzgraff
Senior Contributor I

I have an application that uses the UART_RTOS_Receive() and associated functions. Currently this is implemented in MCUXpresso with FreeRTOS. But now I would like to implement hardware flow control using RTS/CTS.

Is there an API that supports this? If not what would be the "correct" way to manipulate the UART0_MODEM and associated registers?

As a minimum, I need to be able to drive RTS low (seems default is high) to get the transfer kicked off.

Thanks for any pointers, Dave

标签 (1)
0 项奖励
回复
1 解答
1,423 次查看
davepfaltzgraff
Senior Contributor I

I was unable to find any support APIs (such as HAL_Read_UART_Config()) and ended up inserting the following code:

========================================================

// Taken from fsl_uart.c (around line 315)

// Set tx/rx FIFO watermark
UART0->TWFIFO = 0;
UART0->RWFIFO = 1;

// Enable tx/rx FIFO
UART0->PFIFO |= (UART_PFIFO_TXFE_MASK | UART_PFIFO_RXFE_MASK);

// Flush FIFO
UART0->CFIFO |= (UART_CFIFO_TXFLUSH_MASK | UART_CFIFO_RXFLUSH_MASK);

// Enable receiver RTS(request-to-send) function.
UART0->MODEM |= UART_MODEM_RXRTSE_MASK;
// Enable transmitter CTS(clear-to-send) function.
UART0->MODEM |= UART_MODEM_TXCTSE_MASK;

========================================================

This pulled the control lines to their correct values and the serial link is now operational. In order to "de-initialize" these lines, the last two lines of code become:

UART0->MODEM &= ~UART_MODEM_RXRTSE_MASK;
UART0->MODEM &= ~UART_MODEM_TXCTSE_MASK;

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,424 次查看
davepfaltzgraff
Senior Contributor I

I was unable to find any support APIs (such as HAL_Read_UART_Config()) and ended up inserting the following code:

========================================================

// Taken from fsl_uart.c (around line 315)

// Set tx/rx FIFO watermark
UART0->TWFIFO = 0;
UART0->RWFIFO = 1;

// Enable tx/rx FIFO
UART0->PFIFO |= (UART_PFIFO_TXFE_MASK | UART_PFIFO_RXFE_MASK);

// Flush FIFO
UART0->CFIFO |= (UART_CFIFO_TXFLUSH_MASK | UART_CFIFO_RXFLUSH_MASK);

// Enable receiver RTS(request-to-send) function.
UART0->MODEM |= UART_MODEM_RXRTSE_MASK;
// Enable transmitter CTS(clear-to-send) function.
UART0->MODEM |= UART_MODEM_TXCTSE_MASK;

========================================================

This pulled the control lines to their correct values and the serial link is now operational. In order to "de-initialize" these lines, the last two lines of code become:

UART0->MODEM &= ~UART_MODEM_RXRTSE_MASK;
UART0->MODEM &= ~UART_MODEM_TXCTSE_MASK;

0 项奖励
回复
1,412 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I agree with you that there is not hal function to configure the hardware flow control mode, you have to write register yourself.

BR

Xiangjun Rong

0 项奖励
回复
1,461 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

For hardware flow control, this is the uart signals:

RXD: input data pin

TXD:output data pin

RTS:output request transmit signal

CTS:input clear to send signal.

So if you want to two uart(Uart0 and Uart1) to communicate with hardware flow control, the RTS of Uart0 must be connected to CTS of Uart1, the CTS of Uart0 must be connected to RTS of Uart1.

From software, you just need to enable the flow control by configuring the UARTx_MODEM register.

 

xiangjun_rong_0-1718601968574.png

Hope it can help you

BR

XiangJun Rong

0 项奖励
回复