UART0 Connection to PC via USB-Serial-F Cable Fails

Started by miroR, August 30, 2020, 09:33:16 PM

Previous topic - Next topic

miroR

Note: some of the dates are redacted, because some of the time I was anonymous online with the machine I took those logs on. But I tried to keep them consistent, i.e. relatively correctly chronological.

I attached the right endpoints, TX, RX and GND correctly to the UART0 of my LIME2. Upon attaching the USB-serial cable to the common-type USB-slot of my PC, I get this in the /var/log/syslog:

With stock Debian kernel[1], I get this:
2020-08-30T04:50:34.560059+00:00 gdO smartd[3303]: file /var/run/smartd.pid written containing PID 3303
2020-08-30T05:30:13.169462+00:00 gdO kernel: [  208.191142] usb 8-2: new full-speed USB device number 2 using ohci-pci
2020-08-30T05:30:13.361361+00:00 gdO kernel: [  208.386246] usb 8-2: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 3.00
2020-08-30T05:30:13.361382+00:00 gdO kernel: [  208.386254] usb 8-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
2020-08-30T05:30:13.361386+00:00 gdO kernel: [  208.386259] usb 8-2: Product: USB-Serial Controller
2020-08-30T05:30:13.361388+00:00 gdO kernel: [  208.386262] usb 8-2: Manufacturer: Prolific Technology Inc.
2020-08-30T05:30:13.452426+00:00 gdO kernel: [  208.477996] usbcore: registered new interface driver usbserial_generic
2020-08-30T05:30:13.452450+00:00 gdO kernel: [  208.478020] usbserial: USB Serial support registered for generic
2020-08-30T05:30:13.469419+00:00 gdO kernel: [  208.492916] usbcore: registered new interface driver pl2303
2020-08-30T05:30:13.469465+00:00 gdO kernel: [  208.492947] usbserial: USB Serial support registered for pl2303
2020-08-30T05:30:13.469468+00:00 gdO kernel: [  208.492986] pl2303 8-2:1.0: pl2303 converter detected
2020-08-30T05:30:13.493361+00:00 gdO kernel: [  208.515369] usb 8-2: pl2303 converter now attached to ttyUSB0

I get these devices created:

ls -ltr /dev/ | tail
crw--w---- 1 root tty       4,   2 2020-08-30 05:29 tty2
crw--w---- 1 root tty       4,   1 2020-08-30 05:29 tty1
crw--w---- 1 root tty       4,   4 2020-08-30 05:29 tty4
crw--w---- 1 root tty       4,   3 2020-08-30 05:29 tty3
crw--w---- 1 root tty       4,   6 2020-08-30 05:29 tty6
crw-rw-rw- 1 root kvm      10, 232 2020-08-30 05:29 kvm
crw-rw---- 1 root dialout 188,   0 2020-08-30 05:30 ttyUSB0
drwxr-xr-x 4 root root          80 2020-08-30 05:30 serial
drwxr-xr-x 2 root root        3200 2020-08-30 05:30 char
crw------- 1 root tty       4,   5 2020-08-30 05:32 tty5

ls -ltr /dev/char | tail
lrwxrwxrwx 1 root root  8 2020-08-30 05:29 7:133 -> ../vcsa5
lrwxrwxrwx 1 root root  8 2020-08-30 05:29 7:132 -> ../vcsa4
lrwxrwxrwx 1 root root  8 2020-08-30 05:29 7:130 -> ../vcsa2
lrwxrwxrwx 1 root root  8 2020-08-30 05:29 7:70 -> ../vcsu6
lrwxrwxrwx 1 root root  7 2020-08-30 05:29 7:6 -> ../vcs6
lrwxrwxrwx 1 root root  8 2020-08-30 05:29 7:134 -> ../vcsa6
lrwxrwxrwx 1 root root  8 2020-08-30 05:29 7:131 -> ../vcsa3
lrwxrwxrwx 1 root root  6 2020-08-30 05:29 10:232 -> ../kvm
lrwxrwxrwx 1 root root 10 2020-08-30 05:30 188:0 -> ../ttyUSB0
lrwxrwxrwx 1 root root 18 2020-08-30 05:30 189:898 -> ../bus/usb/008/003

# cu -l /dev/ttyUSB0
cu: open (/dev/ttyUSB0): Permission denied
cu: /dev/ttyUSB0: Line in use

ls -ltrR /dev/serial
/dev/serial:
total 0
drwxr-xr-x 2 root root 60 2020-08-30 05:30 by-path
drwxr-xr-x 2 root root 60 2020-08-30 05:30 by-id

/dev/serial/by-path:
total 0
lrwxrwxrwx 1 root root 13 2020-08-30 05:30 pci-0000:00:12.0-usb-0:2:1.0-port0 -> ../../ttyUSB0

/dev/serial/by-id:
total 0
lrwxrwxrwx 1 root root 13 2020-08-30 05:30 usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0 -> ../../ttyUSB0

Obviously, it's not a ttyACM0, which would work. It is a ttyUSB0, which doesn't work.

This is what the device that I get looks like (I take notice of the Endpoint, gives me a vague hint about the debugging with my own kernel, planned to paste in the next post):

# lsusb -v -D /dev/bus/usb/008/002

Bus 008 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x067b Prolific Technology, Inc.
  idProduct          0x2303 PL2303 Serial Port
  bcdDevice            3.00
  iManufacturer           1 Prolific Technology Inc.
  iProduct                2 USB-Serial Controller
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0027
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x000a  1x 10 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0000
  (Bus Powered)

And, with my own kernel that I am running currently[...]:
# uname -a
Linux gdOv 5.8.5 #1 SMP Sat Aug 30 10:44:05 UTC 2020 x86_64 GNU/Linux
[...]

But there's already a lot of stuff for one post. I'll make a new post.

---
[1] I don't currently run it (so can't provide uname -a, because I need debugging, i.e. I needed to compile my own kernel, but the package is linux-image-5.7.0-3-amd64, with the acoompanying headers and possibly libc.

miroR

So this is my own freshly compiled kernel that I am running currently:
# uname -a
Linux gdOv 5.8.5 #1 SMP Sat Aug 30 10:44:05 UTC 2020 x86_64 GNU/Linux
 
I used to get more or less the same ttyUSB0 device created instead of ttbACM0:

2020-08-30T17:30:36.977634+00:00 sohk kernel: [  116.447216] usb 8-2: USB disconnect, device number 2
2020-08-30T17:30:36.977656+00:00 sohk kernel: [  116.449304] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0
2020-08-30T17:30:36.980825+00:00 sohk kernel: [  116.451218] pl2303 8-2:1.0: device disconnected
2020-08-30T17:30:38.808890+00:00 sohk kernel: [  118.278409] usb 8-2: new full-speed USB device number 3 using ohci-pci
2020-08-30T17:30:39.006587+00:00 sohk kernel: [  118.473528] usb 8-2: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 3.00
2020-08-30T17:30:39.006610+00:00 sohk kernel: [  118.475686] usb 8-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
2020-08-30T17:30:39.006612+00:00 sohk kernel: [  118.477794] usb 8-2: Product: USB-Serial Controller
2020-08-30T17:30:39.006615+00:00 sohk kernel: [  118.479940] usb 8-2: Manufacturer: Prolific Technology Inc.
2020-08-30T17:30:39.011034+00:00 sohk kernel: [  118.482556] pl2303 8-2:1.0: pl2303 converter detected
2020-08-30T17:30:39.036904+00:00 sohk kernel: [  118.506638] usb 8-2: pl2303 converter now attached to ttyUSB0
and similarly, ttbACM0 just not there in /dev/.

However, I compiled dynamic debugging in this kernel, and figuring out the driver is from source cdc-acm.c, I find the following.

So now the debugging.

And this is in real time, but no need for redacting, no timestamps:
# grep cdc /proc/dynamic_debug/control
drivers/usb/core/message.c:2268 [usbcore]cdc_parse_cdc_header =_ "Ignoring descriptor: type %02x, length %ud\012"
drivers/usb/class/cdc-acm.c:1325 [cdc_acm]acm_probe =_ "interfaces are valid\012"
drivers/usb/class/cdc-acm.c:1320 [cdc_acm]acm_probe =_ "The data interface has switched endpoints\012"
drivers/usb/class/cdc-acm.c:1303 [cdc_acm]acm_probe =_ "The data interface isn't available\012"
drivers/usb/class/cdc-acm.c:1289 [cdc_acm]acm_probe =_ "Your device has switched interfaces.\012"
drivers/usb/class/cdc-acm.c:1261 [cdc_acm]acm_probe =_ "Separate call control interface. That is not fully supported.\012"
drivers/usb/class/cdc-acm.c:1254 [cdc_acm]acm_probe =_ "no interfaces\012"
drivers/usb/class/cdc-acm.c:1238 [cdc_acm]acm_probe =_ "No union descriptor, giving up\012"
drivers/usb/class/cdc-acm.c:1227 [cdc_acm]acm_probe =_ "No union descriptor, using call management descriptor\012"
drivers/usb/class/cdc-acm.c:1208 [cdc_acm]acm_probe =_ "Seeking extra descriptors on endpoint\012"
drivers/usb/class/cdc-acm.c:1086 [cdc_acm]acm_tty_set_termios =_ "%s - set line: %d %d %d %d\012"
drivers/usb/class/cdc-acm.c:879 [cdc_acm]acm_tty_break_ctl =_ "%s - send break failed\012"
drivers/usb/class/cdc-acm.c:515 [cdc_acm]acm_read_bulk_callback =_ "%s - nonzero urb status received: %d\012"
drivers/usb/class/cdc-acm.c:508 [cdc_acm]acm_read_bulk_callback =_ "%s - cooling babbling device\012"
drivers/usb/class/cdc-acm.c:501 [cdc_acm]acm_read_bulk_callback =_ "%s - urb shutting down with status: %d\012"
drivers/usb/class/cdc-acm.c:485 [cdc_acm]acm_read_bulk_callback =_ "%s - disconnected\012"
drivers/usb/class/cdc-acm.c:363 [cdc_acm]acm_ctrl_irq =_ "%s - nonzero urb status received: %d\012"
drivers/usb/class/cdc-acm.c:358 [cdc_acm]acm_ctrl_irq =_ "%s - urb shutting down with status: %d\012"
drivers/usb/class/cdc-acm.c:333 [cdc_acm]acm_process_notification =_ "%s - unknown notification %d received: index %d len %d\012"
drivers/usb/class/cdc-acm.c:301 [cdc_acm]acm_process_notification =_ "%s - calling hangup\012"
drivers/usb/class/cdc-acm.c:297 [cdc_acm]acm_process_notification =_ "%s - serial state: 0x%x\012"
drivers/usb/class/cdc-acm.c:291 [cdc_acm]acm_process_notification =_ "%s - malformed serial state\012"
drivers/usb/class/cdc-acm.c:285 [cdc_acm]acm_process_notification =_ "%s - network connection: %d\012"
drivers/usb/class/cdc-acm.c:124 [cdc_acm]acm_ctrl_msg =_ "%s - rq 0x%02x, val %#x, len %#x, result %d\012"

We've already seen the string endpoint in post one of this topic. Actually also we've seen string descriptor. But I still keep digesting pointers and structs when I once or twice a year can't resist and try and study C for a few days, and I still find them hard to understand, so the code (currently) at:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/usb/class/cdc-acm.c?h=v5.8.5
or, possibly more permanently, but with possibility to change in the future:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/usb/class/cdc-acm.c
so I can't wrap my head around this. Tried hard...

I thought maybe it was the USB-serial driver that is causing this wrong setup, and so I removed CONFIG_USB_SERIAL config entry and recompiled. But now I only get this:

2020-08-30T17:47:30.933277+00:00 sohk kernel: [47261.940437] usb 4-2: USB disconnect, device number 5
2020-08-30T17:47:32.318293+00:00 sohk kernel: [47263.325227] usb 4-2: new full-speed USB device number 6 using ohci-pci
2020-08-30T17:47:32.481239+00:00 sohk kernel: [47263.488393] usb 4-2: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 3.00
2020-08-30T17:47:32.481260+00:00 sohk kernel: [47263.488399] usb 4-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
2020-08-30T17:47:32.481265+00:00 sohk kernel: [47263.488402] usb 4-2: Product: USB-Serial Controller
2020-08-30T17:47:32.481268+00:00 sohk kernel: [47263.488405] usb 4-2: Manufacturer: Prolific Technology Inc.

and still no /dev/ttyACM0.

I have a few more guesses what this could be but they're too far fetched to bother with them...

Pls. if anybody understands this, help me understand and get my UART0 usable for me.

miroR

This is all with the latest Buster from:
http://images.olimex.com/release/a20/
i.e.:
http://images.olimex.com/release/a20/A20-OLinuXino-bionic-base-20200731-135750.img.7z
on the Lime2 revision K (forgot to say).

Just in the (very unlikely, but not impossible) case something is the matter with the image I downloaded, the not PGP-signed, unverifiable MD5 of the image is:
$ cat A20-OLinuXino-buster-base-20200731-135406.img.md5
70d54feb00e1c12629fee80a96b84778  A20-OLinuXino-buster-base-20200731-135406.img
and it:
$ md5sum -c A20-OLinuXino-buster-base-20200731-135406.img.md5
A20-OLinuXino-buster-base-20200731-135406.img: OK
verifies correctly here.
That's just in case (network recorded, let's have SSL-keys to confirm the exact MD5sum posted here..).

JohnS


miroR

Quote from: JohnS on August 31, 2020, 04:16:25 PMI think you need to change udev info.
Well, thanks for looking this up, but I don't think I am able to figure out what you mean by changing udev info.

miroR

This is what I run:
# apt-cache policy eudev
eudev:
  Installed: 3.2.9-7
  Candidate: 3.2.9-7
  Version table:
 *** 3.2.9-7 500
        500 tor://devuanfwojg73k6r.onion/devuan ceres/main amd64 Packages
        500 tor://devuanfwojg73k6r.onion/merged ceres/main amd64 Packages
        100 /var/lib/dpkg/status
Devuan's packages are around 99% just pure Debian packages. It's Debian without systemd, sysvinit-continued Debian.

eudev is a replacement for udev, by a Gentoo developer:
https://github.com/gentoo/eudev
and it's my choice. I haven't had issues with it, yet.

Is that the link in the chain which you suspect is causing this misconfiguration of USB-Serial-F connection on my PC side?

miroR

Thanks again @JohnS. Well, get more debugging by another kernel recompile, with debugfs this time around, as per:
https://www.kernel.org/doc/Documentation/admin-guide/dynamic-debug-howto.rst

and if I manage to figure out a little more, open a bug report and ask at Eudev github, I guess...
That might take me time, I don't like to bother anybody without doing the research myself the best I can.
I've figured more about USB and USB-to-serial, here the links if anybody else should find them useful:

https://en.wikipedia.org/wiki/USB#System_design
that's where endpoints, descriptors, classes are explained

https://en.wikipedia.org/wiki/USB_communications_device_class
the cdc driver class, applies to USB-serial-F

and, in bottom of the CDC page:

http://ww1.microchip.com/downloads/en/appnotes/doc4322.pdf
CDC (Communications Device Class) ACM (Abstract Control Model) to emulate serial ports over USB

That's the cdc-acm.ko module (with the stock Debian kernel) from cdc-acm.c source which I linked in the second post, it is explained as was introduced, sometime end of last century.

JohnS

I'm using more standard things, so udev, and it lets me set VID & PID to get ttyUSB or ttyACM.  I find ttyUSB works OK, so just stick to that but also have used ttyACM and that worked too.

John

miroR

#8
Quote from: JohnS on August 31, 2020, 10:16:16 PMI'm using more standard things, so udev, and it lets me set VID & PID to get ttyUSB or ttyACM.  I find ttyUSB works OK, so just stick to that but also have used ttyACM and that worked too.

John
Do you mean that ttyUSB will work with A20-Lime2? Is that your board and it works?
I believed that it must be ttyACM, because in the manual it says so, see, under chapter "LIME2-SERVER software installation":
https://github.com/OLIMEX/OLINUXINO/blob/master/DOCUMENTS/LIME2-SERVER/LIME2-SERVER-User-Manual.pdf
it says there:
Quotethe port must be a ttyACMx

But if ttyUSB is fine, I might try and see how to get it to work...
If it can't, then I need to try and understand what exact role eudev plays there, and to debug it, but I haven't had enough time to understand the related kernel debugging, to be able to do it. (It requires some reall understanding of C, which I lack.)

So, ttyUSB works on A20-Lime2?

miroR

Well, it probably works. Searched for the VID and PID that JohnS mentioned, with little avail.

But this is probably the solution:

Ubuntu - How do I connect to TTY_COM
https://www.youtube.com/watch?v=874XnIGjEjM

Even the text there is also likely sufficient.

miroR

#10
Quote from: miroR on September 07, 2020, 07:07:59 PM
Quote from: JohnS on August 31, 2020, 10:16:16 PM[...]
so udev, and it lets me set VID & PID to get ttyUSB or ttyACM.  I find ttyUSB works OK
[...]

John
ttyUSB works perfect with A20-Lime2.

and BTW VID means VendorID and PID means ProductID in JohnS's post.

But I believed the docs were clear enough to the contrary!
Quote from: miroR on September 07, 2020, 07:07:59 PMI believed that it must be ttyACM, because in the manual it says so, see, under chapter "LIME2-SERVER software installation":
https://github.com/OLIMEX/OLINUXINO/blob/master/DOCUMENTS/LIME2-SERVER/LIME2-SERVER-User-Manual.pdf
it says there:
Quote from: undefinedthe port must be a ttyACMx
[...]
And that is worth another bug report (I already reported a non-irrelevant, but neither very important typo on OLIMEX github).
However, this is not just incomplete documentation, as it says, at this time, this is misleading documentation. I'll try and find time and report this issue.

I'll make another topic to show how to use picocom with LIME2.

miroR

Issue filed:

Misleading information on connecting to UART0 via USB-serial connection #85
https://github.com/OLIMEX/OLINUXINO/issues/85

miroR

Quote from: miroR on September 09, 2020, 03:06:42 PMIssue filed:

Misleading information on connecting to UART0 via USB-serial connection #85
https://github.com/OLIMEX/OLINUXINO/issues/85

For which issue I quickly got this reply:
QuoteHi miroR,

Note that the document you quote do not require external USB-SERIAL-F cable.

If you boot the board and connect normal USB cable to the USB OTG port of LIME2 it will create ttyACMx on your Linux PC or
+COMx port on your Windows machine.

And sure you can use any other serial program like minicom etc instead of cu.
What is written in this document is simple example which works if you follow it step by step.
There may be many variations.

Please read again "Lime2 Server software installation" page, it's not written to use USB-SERIAL-F but to connect USB cable to
+the USB-OTG port and in this case ttyACMx will be created!

Best regards
Tsvetan
I see!
The document I quoted (and linked) does not require external USB-SERIAL-F cable.
Indeed, that example is written for USB-OTG.

And I didn't read it carefully enough, and came to wrong conclusion. My bad.

JohnS