cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ierkiaga
Participant
Participant
11,246 Views
Registered: ‎11-13-2012

UART Modem Control (RTS/CTS)

Jump to solution

Hi,

 

I would like to use modem control signals (RTS/CTS) in my ZYNQ MIO peripherals, but I'm not sure about how to enable these features in my embedded design.

 

Uart0 is used as RS232 (RTS/CTS) and Uart1 as RS485 (RTS controlling driver):

 

8     ps7_uart_0: uartps@e0000000 {
209       compatible = "xlnx,ps7-uart-1.00.a", "xlnx,xuartps";
210       current-speed = <115200>;
211       device_type = "serial";
212       interrupt-parent = <&ps7_scugic_0>;
213       interrupts = < 0 27 4 >;
214       reg = <0xe0000000 0x1000>;
215       xlnx,has-modem = <0x1>;
216       xlnx,uart-clk-freq-hz = <0x5f5e100>;
217       linux,rs485-enabled-at-boot-time;
218       rs485-rts-delay = <10 10>;
219     };
220 
221     ps7_uart_1: uartps@e0001000 {
222       compatible = "xlnx,ps7-uart-1.00.a", "xlnx,xuartps";
223       current-speed = <115200>;
224       device_type = "serial";
225       interrupt-parent = <&ps7_scugic_0>;
226       interrupts = < 0 50 4 >;
227       port-number = <1>;
228       reg = < 0xe0001000 0x1000 >;
229       xlnx,has-modem = <0x1>;
230       xlnx,uart-clk-freq-hz = <0x5f5e100>;
231     };

Serial ports has been registered properly in the system and both tty ports (/dev/ttyPS0 & /dev/ttyPS1) can be accessed throught linux terminal.

 

Making an echo to the ttyPS0 port I can see that there is activity in the TX line. However RTS signal is not used by device driver. Looking in the uartps driver, I see that has-modem property is not used and it seems that modem control signals are not controlled by this code.

 

How can I configure the tty port to use modem signals?? Is posible to use them when using the serial port as linux console??

0 Kudos
1 Solution

Accepted Solutions
ierkiaga
Participant
Participant
15,116 Views
Registered: ‎11-13-2012

Thanx Ralph,

 

I made a little rework in the xuartps driver and I solve the problem partialy. The code is not as good as I would like but it is working, so enough for now jejeje

 

I'll try to improve the code a little bit more and I'll post it on this board.

 

- Ibai

View solution in original post

0 Kudos
9 Replies
rfs613
Scholar
Scholar
11,215 Views
Registered: ‎05-28-2013

I have not tried this, but some thoughts:

 

* the TRM indicates that modem control signals are only available on EMIO, not MIO. So you will need to route them explicitly in your bitstream.

 

* to enable use of serial modem control, you would normally use "stty -F ttyPSS0 crtscts"

 

Cheers

-Ralph

0 Kudos
ierkiaga
Participant
Participant
11,189 Views
Registered: ‎11-13-2012

Hi,

 

My modem control signals and data signlas are routed through EMIO, so there is not problem in this case.

 

I tried to enable modem control signal with stty (using your command) but RTS signal is not dessaserted when trying to transmit data ( 'echo test > /dev/ttyPS0' ).

 

I'm developing a little C app, using termios interface to control modem signals but it doesn't work as expected jejeje

 

......

tty_fd=open("/dev/ttyPS0", O_RDWR | O_NOCTTY  | O_NDELAY | O_NONBLOCK );

if (tty_fd < 0 )
  return EXIT_FAILURE;

if (tcgetattr(tty_fd, &tty) < 0)
  return EXIT_FAILURE;

printf("RS485 Test App\r\n");

if (tcsetattr(tty_fd, TCSANOW, &tty) < 0)
  return EXIT_FAILURE;

if (ioctl(tty_fd, TIOCMGET, &status) < 0) /* get the serial port status */
  return EXIT_FAILURE;

  //status |= TIOCM_RTS;
  status &= ~TIOCM_RTS;

if (ioctl(tty_fd, TIOCMSET, &status) < 0) /* set the serial port status */
  return EXIT_FAILURE;

while (1)
{
  write(tty_fd, Buffer, sizeof(Buffer));
  sleep(1);
}

....
close(tty_fd);

 

Any idea???

0 Kudos
ierkiaga
Participant
Participant
11,185 Views
Registered: ‎11-13-2012

Hi everybody,

 

I was looking driver's source code and I saw the following code in the modem control methods:

/**
* xuartps_get_mctrl - Get the modem control state
*
* @port: Handle to the uart port structure
*
* Returns the modem control state
*
**/
static unsigned int xuartps_get_mctrl(struct uart_port *port)
{
return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
}

static void xuartps_set_mctrl(struct uart_port *port, unsigned int mctrl)
{
/* N/A */
}

 I'm not expert in linux driver development, but it seems that it is not possible to control modem signals.... Anyone knows more about it??

0 Kudos
rfs613
Scholar
Scholar
11,179 Views
Registered: ‎05-28-2013
Great detective work! Looks like it hasn't been implemented.

If you want to give it a go yourself, compare the function serial8250_set_mctrl() in drivers/tty/serial/8250/8250_core.c and adjust it to write to the Zynq registers.

-Ralph
0 Kudos
ierkiaga
Participant
Participant
15,117 Views
Registered: ‎11-13-2012

Thanx Ralph,

 

I made a little rework in the xuartps driver and I solve the problem partialy. The code is not as good as I would like but it is working, so enough for now jejeje

 

I'll try to improve the code a little bit more and I'll post it on this board.

 

- Ibai

View solution in original post

0 Kudos
wyorin
Newbie
Newbie
10,892 Views
Registered: ‎12-20-2013

Is the code available I do I have to reinvent the wheel?

0 Kudos
marcelo7911
Visitor
Visitor
7,788 Views
Registered: ‎05-06-2015

Hi.

Could you help me with the code to activate the driver 485 .

thanks

 

0 Kudos
martin.kiepfer
Visitor
Visitor
6,218 Views
Registered: ‎02-04-2016

Has someone successfully used the automatic flow control?

Accordung to the documentation, the UART should be able to control modem signals, espcially RTS, automaticially. But again it looks like this feature isn't implemented yet.

 

Toggeling RTS manually is to slow in my application (RS485 communication).

 

Any hint would be useful.

0 Kudos
martin.kiepfer
Visitor
Visitor
6,209 Views
Registered: ‎02-04-2016

Ok, after studying the manual again I needed to realize that toggling RTS for RS485 communcation isn't possible with automatic flow control as RTS is coupled to RX fifo!

So I decided to adapt the driver to toggle RTS manually in rs485 mode. Unfortunatly I need to poll TActive flag in a tasklet after TX has finished. Anyway, it seems to work properly now. 

0 Kudos