Adding flow control to UART0 on MK22FN512 and FreeRTOS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding flow control to UART0 on MK22FN512 and FreeRTOS

Jump to solution
1,491 Views
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

Labels (1)
0 Kudos
Reply
1 Solution
1,423 Views
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;

View solution in original post

0 Kudos
Reply
3 Replies
1,424 Views
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 Kudos
Reply
1,412 Views
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 Kudos
Reply
1,461 Views
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 Kudos
Reply