Linux OTG port screwing up my other host port - linux

I've got a Variscite VAR-SOM-MX6 running a Linux 3.0.35 kernel, with two USB ports. The first port is an OTG port connected to an external mini-OTG jack. The second is an internal host port going to a hub chip, and then to some other devices.
If I've got an OTG cable plugged into the first port, telling it to be a host, then everything works fine. If I have a regular cable, or no cable at all, plugged in, then the second host port doesn't enumerate properly. There doesn't have to be anything at the other end of the cable, so this is a bug related only to whether the OTG is trying to be a host or a device.
For instance, if I plug in an OTG cable and reboot, the kernel log contains the following lines.
usb 2-1: new high speed USB device number 2 using fsl-ehci
usb 2-1: New USB device found, idVendor=0424, idProduct=2534
usb 2-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
hub 2-1:1.0: USB hub found
hub 2-1:1.0: 4 ports detected
usb 2-1.1: new high speed USB device number 3 using fsl-ehci
usb 2-1.1: New USB device found, idVendor=0424, idProduct=9e00
usb 2-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
usb 2-1.2: new high speed USB device number 4 using fsl-ehci
usb 2-1.2: New USB device found, idVendor=0403, idProduct=6011
usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 2-1.2: Product: Quad RS232-HS
usb 2-1.2: Manufacturer: FTDI
If I then yank the OTG cable from port 1, it disconnects everything on port 2:
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
usb 2-1.2: USB disconnect, device number 4
and then tries to re-enumerate everything, but fails miserably:
usb 2-1: new high speed USB device number 5 using fsl-ehci
usb 2-1: new high speed USB device number 6 using fsl-ehci
usb 2-1: new high speed USB device number 7 using fsl-ehci
usb 2-1: device not accepting address 7, error -71
usb 2-1: new high speed USB device number 8 using fsl-ehci
usb 2-1: device not accepting address 8, error -71
hub 2-0:1.0: unable to enumerate USB device on port 1
I suspect that some code is using physical port numbers 1 and 2, irrespective of whether a port is a host or a device, while other code is only looking at actual host ports, and getting the port numbers confused internally. Has anyone seen this bug before? Googling didn't turn anything up. Or is there a more specialized forum where I should post this question?

In case anyone is interested, this turned out to be a hardware design issue. Both USB PHYs are powered off an internal regulator that is powered by +5V from either the host VBUS or the OTG VBUS, whichever is higher. The designer thought these were voltage sensing inputs, and drove the host VBUS with 5V through a 10K resistor. So it ran out of poop when the OTG port wasn't connected. Changing 10K to 0 ohms fixed it.

Related

Understanding linux hub messages in kernel log

I'm having problems with a 4-port USB hub chip attached to a SOM running Linux, and I'm trying to understand the meaning of the various messages in the kernel log pertaining to it. My hub produces the following messages during bootup:
usb 2-1: new high speed USB device number 2 using fsl-ehci
usb 2-1: new high speed USB device number 3 using fsl-ehci
usb 2-1: new high speed USB device number 4 using fsl-ehci
usb 2-1: device not accepting address 4, error -71
usb 2-1: new high speed USB device number 5 using fsl-ehci
usb 2-1: device not accepting address 5, error -71
hub 2-0:1.0: unable to enumerate USB device on port 1
There are a couple of on-board devices connected to this hub, but it's never getting as far as enumerating those. So why does it try to assign multiple USB device numbers to my hub chip? I could understand it failing, and then retrying with the next higher device number, but it's not showing an error for device number 2 or 3. And then what does "unable to enumerate USB device on port 1" mean? Port 1 of what? It's clearly on host port 2, not 1. And why does the final error message come from the hub driver, when it hasn't apparently recognized a hub, and why does it use 2-0 as the device number rather than 2-1? Does any of this make sense?
To get some idea of what I ought to be seeing if it wasn't failing, I tried plugging an external hub into the other host port, and got this:
usb 1-1: new high speed USB device number 7 using fsl-ehci
usb 1-1: New USB device found, idVendor=05e3, idProduct=0608
usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
usb 1-1: Product: USB2.0 Hub
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
usb 1-1.1: new high speed USB device number 8 using fsl-ehci
usb 1-1.1: New USB device found, idVendor=05e3, idProduct=0608
usb 1-1.1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
usb 1-1.1: Product: USB2.0 Hub
hub 1-1.1:1.0: USB hub found
hub 1-1.1:1.0: 4 ports detected
Obviously, this 7-port hub is implemented as a 4-port hub connected to another 4-port hub, and the "x-y.z" construct refers to downstream port z on hub x-y. But what does the construct "1-1:1.0" mean? I've done a lot of Googling to find this out, including looking through kernel source and header files, to no avail. At one point in the code, they are fetched by a function called dev_name(). Could someone point me to some documentation on this?
Turns out the problem is with the other port, the OTG port, so I've asked a different question here:
Linux OTG port screwing up my other host port

USB<>serial communication not working on linux

I'm currently working on a project in which I have to communicate with a custom-made sonar board over an USB<>Serial connection with cts/rts hardware flow control at a baud rate of 4,499,456.
MATLAB code for sending and receiving data is already available and fully tested on Windows.
The problem occurs when trying to execute the MATLAB code on linux (Ubuntu 14.10/15.04). Both the commands for toggling the LED on the board (write) as well as receiving information (read) are not working.
Python ports of the MATLAB code using the pyserial and pylibftdi library do allow writing, but also hang on receiving data.
Does anyone have any idea as to why it does work on Windows but not Ubuntu? Maybe a driver issue? Or something having to do with cts/rts on Linux?
lsusb output
Bus 002 Device 004: ID 0403:6014 Future Technology Devices International, Ltd FT232H Single HS USB-UART/FIFO IC
dmesg output
[11906.209231] usb 2-3: new high-speed USB device number 5 using ehci-pci
[11906.346701] usb 2-3: New USB device found, idVendor=0403, idProduct=6014
[11906.346713] usb 2-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[11906.346720] usb 2-3: Product: USB <-> Serial Converter
[11906.346725] usb 2-3: Manufacturer: FTDI
[11906.346730] usb 2-3: SerialNumber: FT69T4N
[11906.351716] ftdi_sio 2-3:1.0: FTDI USB Serial Device converter detected
[11906.351800] usb 2-3: Detected FT232H
[11906.352234] usb 2-3: FTDI USB Serial Device converter now attached to ttyUSB1
Edit: Just logging my progress in case somebody encounters the same issue. The problem seems to lie in the baudrate; changing it to 115200 allows reading from the device, but messes up sending data to it.
Apparently the FTDI driver doesn't work to well with very high/non-standard baudrates. I ended up solving this by using a baudrate of 3,000,000

Virtual COM driver in Linux to receive data from USB device

I have a USB barcode reader which is developed for Windows only. But one of the developers told me that as soon as the device detects that it is connected to a virtual COM port it is ready to work.
So my question is whether I can create a virtual COM port on Linux and connect the device to this one.
Here the udevadm output when I switch on the device:
udevadm monitor --udev
UDEV [10487.232696] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2 (usb)
UDEV [10487.238105] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0 (usb)
UDEV [10507.430306] add /class/usbmisc (class)
UDEV [10507.453800] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.1 (usb)
UDEV [10507.455899] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.1/2-1.2.1:1.0 (usb)
UDEV [10507.456565] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.1/2-1.2.1:1.1 (usb)
UDEV [10507.459065] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.1/2-1.2.1:1.1/0003:1AC2:0135.0015 (hid)
UDEV [10507.461350] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.1/2-1.2.1:1.1/usbmisc/hiddev0 (usbmisc)
UDEV [10507.461669] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2.1/2-1.2.1:1.1/0003:1AC2:0135.0015/hidraw/hidraw2 (hidraw)
The following is the dmsg output:
dmsg
[10473.572851] usb 2-1.2: New USB device found, idVendor=05e3, idProduct=0610
[10473.572863] usb 2-1.2: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[10473.572869] usb 2-1.2: Product: USB2.0 Hub
[10473.573596] hub 2-1.2:1.0: USB hub found
[10473.573971] hub 2-1.2:1.0: 4 ports detected
[10493.661296] usb 2-1.2.1: new high-speed USB device number 41 using ehci-pci
[10493.754539] usb 2-1.2.1: New USB device found, idVendor=1ac2, idProduct=0135
[10493.754550] usb 2-1.2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[10493.754557] usb 2-1.2.1: Product: *** USB DEVICE
[10493.754562] usb 2-1.2.1: Manufacturer: ***
[10493.754566] usb 2-1.2.1: SerialNumber: 00000017
[10493.757449] hid-generic 0003:1AC2:0135.0015: hiddev0,hidraw2: USB HID v1.10 Device [*** USB DEVICE ] on usb-0000:00:1d.0-1.2.1/input1
I played around with socat already, but I was not really successful. I would very much appreciate if one of you would be able to help me.
Thanks,
Ralf
I think you don't need to be thinking about virtual COM ports. This bar-code reader looks like it is an HID because I see messages about HID in your dmesg output. You could check for sure by looking at the actual USB descriptors of the device using lsusb.
Since it is an HID, the driver setup should be done automatically when you plug it in, and you should be able to just scan a barcode and it will probably show up on your Linux computer as if it were typed by a keyboard.
By the way, I don't think you can really "create" a virtual COM port. Normally the way it works is that the device's USB descriptors say that it has a USB CDC ACM virtual COM port, and the Linux USB drivers read these descriptors and use it to set up the PC side of the virtual COM port.

Smart card reader detection on Linux

I have a smart card reader called SK-284. It support two communication methods, RS232 and USB.
In my case only USB is enable. When I connect this device to my Linux laptop, via USB, It wont get detected. I run '$dmesg' command to check on which ttyUSB port it get detected, I got following output,
[ 2321.208330] usb 2-1.2: new full-speed USB device number 7 using ehci_hcd
[ 2321.384628] generic-usb 0003:8203:8288.0003: hiddev0,hidraw1: USB HID v1.10 Device [\xffffffe6\xffffffb7\xffffffb1\xffffffb7\xffffffb1\xffffffe5\xffffff9c\xffffffb3\xffffff9c\xffffffb3\xffffffe5\xffffff88\xffffff9b\xffffff88\xffffff9b\xffffffe8\xffffff87\xffffffaa\xffffff87\xffffffaa\xffffffe6\xffffff8a\xffffff80\xffffff8a\xffffff80\xffffffe6\xffffff9c\xffffffaf\xffffff9c\xffffffaf\xffffffe6\xffffff9c\xffffff89\xffffff9c\xffffff89\xffffffe9\xffffff99\xffffff90\xffffff99\xffffff90\xffffffe5\xffffff85\xffffffac\xffffff85\xffffffac\xffffffe5\xffffff8f\xffffffb8\xffffff8f\xffffffb8 CRT450 USB 1.1] on usb-0000:00:1d.0-1.2/input0
[ 2326.634925] usb 2-1.2: USB disconnect, device number 7
[ 2326.855479] usb 2-1.2: new full-speed USB device number 8 using ehci_hcd
[ 2326.954303] usb 2-1.2: config index 0 descriptor too short (expected 9, got 0)
[ 2326.954310] usb 2-1.2: can't read configurations, error -22
[ 2327.027211] usb 2-1.2: new full-speed USB device number 9 using ehci_hcd
[ 2327.171371] generic-usb 0003:CEA0:2840.0004: hiddev0,hidraw1: USB HID v1.10 Device [\xffffffe6\xffffffb7\xffffffb1\xffffffb7\xffffffb1\xffffffe5\xffffff9c\xffffffb3\xffffff9c\xffffffb3\xffffffe5\xffffff88\xffffff9b\xffffff88\xffffff9b\xffffffe8\xffffff87\xffffffaa\xffffff87\xffffffaa\xffffffe6\xffffff8a\xffffff80\xffffff8a\xffffff80\xffffffe6\xffffff9c\xffffffaf\xffffff9c\xffffffaf\xffffffe6\xffffff9c\xffffff89\xffffff9c\xffffff89\xffffffe9\xffffff99\xffffff90\xffffff99\xffffff90\xffffffe5\xffffff85\xffffffac\xffffff85\xffffffac\xffffffe5\xffffff8f\xffffffb8\xffffff8f\xffffffb8 CRT284 USB 1.1] on usb-0000:00:1d.0-1.2/input0
My laptop specification:
OS: Ubuntu 12.04
Kernel: 3.2.0-54-generic-pae
When I connect same device to Windows 7 and run device manager, It got detected under Human Interface Device (HID). and some test applications are running fine.
My task is to write a small code on Linux to detect the smart card by device.
So where do I get to know on which ttyUSB port is used by this device, or any other method to get connected to this device.
Thanks in advance.
You may try to change some parameter in usbcore module:
echo y > /sys/module/usbcore/parameters/old_scheme_first
and then replug you usb-device.
As it is full-speed device (not hi-speed) you may also do such thing:
rmmod ehci-hcd
insmod uhci-hcd
insmod ohci-hcd
It seems like there is problem in usb communication. Probably on the usb-device side, because usb-host expects 9 bytes but usb-device sends 0 bytes.

USB host and device functionality on SBC 6845 board using kernel modules

I am working on SBC 6845(Atmel processor) in linux embedded development. My kernel version is 2.6.30.
This board comes with 2 USB ports(Both with Type A), one can be configured as host and other as USB device.
I have configured these USB modules in kernel. I have burned kernel and file system with necessary modules including USB modules. I have loaded these USB modules through /init.d/rcS file.
When board turns on and I type lsmod on console it shows me these modules loaded.
When I connect board to computer, USB is not detected (device functionality).
When I connect pendrive to board, it is not detected (host functionality).
/init.d/rcS Script
#install USB Gadgate mass_storage
modprobe g_file_storage file=/home/mass_storage/backed_storage_file stall=n
losetup -o 4096 /dev/loop0 /home/mass_storage/backed_storage_file
#install USB ehci-hcd
modprobe ehci-hcd
rcS running log
g_file_storage gadget: File-backed Storage Gadget, version: 20 November 2008
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, file: /home/mass_storage/backed_storage_file
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
atmel-ehci atmel-ehci: Atmel EHCI UHP HS
atmel-ehci atmel-ehci: new USB bus registered, assigned bus number 1
atmel-ehci atmel-ehci: irq 22, io mem 0x00800000
atmel-ehci atmel-ehci: USB 2.0 started, EHCI 1.00
usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb1: Product: Atmel EHCI UHP HS
usb usb1: Manufacturer: Linux 2.6.30 ehci_hcd
usb usb1: SerialNumber: atmel-ehci
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
lsmod output
Module Size Used by Not tainted
ehci_hcd 30132 0
g_file_storage 24260 0
Any help is welcome!
Your drivers seem well installed. I don't have a straight answer but I work with software-hardware integration very often. Here is what I would do to get more clues. That kind of processor often have pins that are multipurposes. Sometimes, on an evaluation board, they are not configured the way we want by default. You can look at the documentation but also, you can use an Oscilloscope and probe the D+ and D- of the USB. Are they OK when in IDLE? What happen when you connect a device on your host port? The first few things will be done by the USB controller and involves little even no interaction with the software after the controller is configured. If you see the beginning of a negociation (a bunch of 0s and 1s) then, you know your hardware is configured properly and your basic driver is installed and work properly. The result of this will narrow the scope of the problem.
You are missing upper layer drivers. EHCI is only an interface driver, you need device drivers on top of it. Board<-->PC communication is usually done via serial over USB, so for this you need USB Serial driver. In Kernel config go to Device Drivers -> USB Support -> USB Serial Converter support and select driver according to the chip on your board/cable.
Here's an example dmesg dump seen when board is connected to the Ubuntu laptop:
[ 3469.923779] usb 2-1.2: new full-speed USB device number 5 using
ehci_hcd
[ 3470.019145] cp210x 2-1.2:1.0: cp210x converter detected
[ 3470.091614] usb 2-1.2: reset full-speed USB device number 5 using
ehci_hcd
[ 3470.184995] usb 2-1.2: cp210x converter now attached to ttyUSB0
I believe similar situation is with pendrive too - upper layer driver is missing.

Resources