Adding flow control to UART0 on MK22FN512 and FreeRTOS

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Adding flow control to UART0 on MK22FN512 and FreeRTOS

ソリューションへジャンプ
1,492件の閲覧回数
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,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 件の賞賛
返信
3 返答(返信)
1,425件の閲覧回数
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,413件の閲覧回数
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,462件の閲覧回数
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 件の賞賛
返信