tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

Control CTS and DSR lines

Open reiser4 opened this issue 3 years ago • 12 comments

Is your feature request related to a problem? Please describe. Hi, I'm trying to use an rp2040 to create an hardware project which should control the CTS and DSR lines of a CDC port. I see the current CDC code doesn't support them.

Describe the solution you'd like I'd like to know how to implement CTS and DSR control in tinyusb. I'm also able to read DTR, but RTS is not updated. Host is Windows 11/10. Thanks

reiser4 avatar Apr 03 '22 12:04 reiser4

to speed up the support, do you know

  1. on PC host, which API is used to get cts and dsr, preferably with python script
  2. And which CDC-ACM request that host issue when (1) is called to get CTS and DSR from device

hathach avatar Apr 04 '22 07:04 hathach

Hi, I don't have those information. I'm using comtestserial to interact with the CDC port. I had success moving DSR with this function:


void set_dsr(uint8_t itf, bool value) {

    cdcd_interface_t* p_cdc = &_cdcd_itf[itf];

    uint8_t packet[10];

    packet[0] = 0xA1;                        //   bmRequestType
    packet[1] = CDC_NOTIF_SERIAL_STATE;                //   bNotification
    packet[2] = 0x00;                        //   wValue
    packet[3] = 0x00;
    packet[4] = 0x00;                        //   wIndex
    packet[5] = 0x00;
    packet[6] = 0x02;                        //   wLength
    packet[7] = 0x00;
    packet[8] = value ?  0x02 : 0x00; 
    packet[9] = 0x00;

    usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_notif, packet, 10);

}

with this code, CTS is always High. Before calling this function, I see it as low. Thanks

reiser4 avatar Apr 04 '22 07:04 reiser4

thanks for info, though it doesn't answer the 1st question, which script/API you run on windows to get CTS DSR state

hathach avatar Apr 04 '22 08:04 hathach

On Windows 10/11 I open this software to read the serial port state: https://www.microridge.com/comtestserial.htm

reiser4 avatar Apr 04 '22 09:04 reiser4

Thanks, I don't use windows, but I could give it a try on my VM when I have the time to work on this later on.

hathach avatar Apr 04 '22 10:04 hathach

Thanks, I can try something on Linux and OSX to verify my code, which platform are you working on?

reiser4 avatar Apr 04 '22 10:04 reiser4

I am on Linux

hathach avatar Apr 04 '22 10:04 hathach

The pin state can be checked with pySerial

Something along these lines

import serial

tty = serial.Serial(port = '/dev/AMA0', baudrate = baud, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS, xonxoff = True, timeout = 2.0)

if (tty.getCTS()):
   print("CTS")

You can also use coolterm under Linux for a checking the state of the cts/dsr pins with a nice GUI.

just-jason avatar Aug 26 '22 13:08 just-jason

Hi I want to implement the same of having CTS flow control with pre existing RTS. Have you got it to work if yes can u share them please.

AKASHWORLD614 avatar Aug 05 '23 11:08 AKASHWORLD614