Reputation: 503
Due to development of IoT, I need a stable USB CDC ACM firmware in certain microcontroller. However I find the same device/firmware are not working well in all Linux OS.
I have tested the following boards/firmware:
And I tried to connect these boards to:
And firmware #1 doesn't work for #1/2/3 OS, while some other hardware may work with most of the OS. I have tried different tools, including gtkterm/echo/cat/stty/minicom/usbmon, python serial and lua.io. The result is same.
It seems both firmware and OS have issues. However, in some cases, we can not change too much in OS. But how to identify the root cause and get it fixed.
I pasted my tracking record here.
[ 217.735609] usb 1-2: new full-speed USB device number 3 using ohci_hcd
[ 218.232189] usb 1-2: New USB device found, idVendor=1f00, idProduct=2012
[ 218.232195] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 218.232199] usb 1-2: Product: CDC DEVICE
[ 218.232202] usb 1-2: Manufacturer: mbed.org
[ 218.232205] usb 1-2: SerialNumber: 0123456789
[ 218.298612] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
[ 218.320171] usbcore: registered new interface driver cdc_acm
[ 218.320179] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 003: ID 1f00:2012
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 1f00:2012
Couldn't open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 2 Communications
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x1f00
idProduct 0x2012
bcdDevice 1.00
iManufacturer 1
iProduct 2
iSerial 3
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 75
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 100mA
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 0
bInterfaceCount 2
bFunctionClass 2 Communications
bFunctionSubClass 2 Abstract (modem)
bFunctionProtocol 0 None
iFunction 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 2 Communications
bInterfaceSubClass 2 Abstract (modem)
bInterfaceProtocol 1 AT-commands (v.25ter)
iInterface 0
CDC Header:
bcdCDC 1.10
CDC Call Management:
bmCapabilities 0x03
call management
use DataInterface
bDataInterface 1
CDC ACM:
bmCapabilities 0x06
sends break
line coding and serial state
CDC Union:
bMasterInterface 0
bSlaveInterface 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 16
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 10 CDC Data
bInterfaceSubClass 0 Unused
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
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 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
/dev/bus
/dev/bus/usb
/dev/bus/usb/001
/dev/bus/usb/001/003
/dev/bus/usb/001/002
/dev/bus/usb/001/001
ll /sys/bus/usb/devices
总用量 0
drwxr-xr-x 2 root root 0 1月 26 19:34 ./
drwxr-xr-x 4 root root 0 1月 26 19:34 ../
lrwxrwxrwx 1 root root 0 1月 26 19:34 1-0:1.0 -> ../../../devices/pci0000:00/0000:00:06.0/usb1/1-0:1.0/
lrwxrwxrwx 1 root root 0 1月 26 19:34 1-1 -> ../../../devices/pci0000:00/0000:00:06.0/usb1/1-1/
lrwxrwxrwx 1 root root 0 1月 26 19:34 1-1:1.0 -> ../../../devices/pci0000:00/0000:00:06.0/usb1/1-1/1-1:1.0/
lrwxrwxrwx 1 root root 0 1月 26 19:38 1-2 -> ../../../devices/pci0000:00/0000:00:06.0/usb1/1-2/
lrwxrwxrwx 1 root root 0 1月 26 19:41 1-2:1.0 -> ../../../devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/
lrwxrwxrwx 1 root root 0 1月 26 19:41 1-2:1.1 -> ../../../devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.1/
lrwxrwxrwx 1 root root 0 1月 26 19:34 usb1 -> ../../../devices/pci0000:00/0000:00:06.0/usb1/
cd /sys/bus/usb/devices/1-2
ll
ll
总用量 0
drwxr-xr-x 6 root root 0 1月 26 19:38 ./
drwxr-xr-x 7 root root 0 1月 26 19:34 ../
drwxr-xr-x 5 root root 0 1月 26 19:38 1-2:1.0/
drwxr-xr-x 5 root root 0 1月 26 19:38 1-2:1.1/
-rw-r--r-- 1 root root 4096 1月 26 19:54 authorized
-rw-r--r-- 1 root root 4096 1月 26 19:54 avoid_reset_quirk
-r--r--r-- 1 root root 4096 1月 26 19:38 bcdDevice
-rw-r--r-- 1 root root 4096 1月 26 19:54 bConfigurationValue
-r--r--r-- 1 root root 4096 1月 26 19:38 bDeviceClass
-r--r--r-- 1 root root 4096 1月 26 19:54 bDeviceProtocol
-r--r--r-- 1 root root 4096 1月 26 19:54 bDeviceSubClass
-r--r--r-- 1 root root 4096 1月 26 19:54 bmAttributes
-r--r--r-- 1 root root 4096 1月 26 19:54 bMaxPacketSize0
-r--r--r-- 1 root root 4096 1月 26 19:54 bMaxPower
-r--r--r-- 1 root root 4096 1月 26 19:54 bNumConfigurations
-r--r--r-- 1 root root 4096 1月 26 19:54 bNumInterfaces
-r--r--r-- 1 root root 4096 1月 26 19:38 busnum
-r--r--r-- 1 root root 4096 1月 26 19:54 configuration
-r--r--r-- 1 root root 65553 1月 26 19:38 descriptors
-r--r--r-- 1 root root 4096 1月 26 19:54 dev
-r--r--r-- 1 root root 4096 1月 26 19:38 devnum
-r--r--r-- 1 root root 4096 1月 26 19:54 devpath
lrwxrwxrwx 1 root root 0 1月 26 19:38 driver -> ../../../../../bus/usb/drivers/usb/
drwxr-xr-x 3 root root 0 1月 26 19:54 ep_00/
-r--r--r-- 1 root root 4096 1月 26 19:38 idProduct
-r--r--r-- 1 root root 4096 1月 26 19:38 idVendor
-r--r--r-- 1 root root 4096 1月 26 19:54 ltm_capable
-r--r--r-- 1 root root 4096 1月 26 19:38 manufacturer
-r--r--r-- 1 root root 4096 1月 26 19:54 maxchild
lrwxrwxrwx 1 root root 0 1月 26 19:54 port -> ../1-0:1.0/port2/
drwxr-xr-x 2 root root 0 1月 26 19:54 power/
-r--r--r-- 1 root root 4096 1月 26 19:38 product
-r--r--r-- 1 root root 4096 1月 26 19:54 quirks
-r--r--r-- 1 root root 4096 1月 26 19:38 removable
--w------- 1 root root 4096 1月 26 19:54 remove
-r--r--r-- 1 root root 4096 1月 26 19:38 serial
-r--r--r-- 1 root root 4096 1月 26 19:38 speed
lrwxrwxrwx 1 root root 0 1月 26 19:38 subsystem -> ../../../../../bus/usb/
-rw-r--r-- 1 root root 4096 1月 26 19:38 uevent
-r--r--r-- 1 root root 4096 1月 26 19:54 urbnum
-r--r--r-- 1 root root 4096 1月 26 19:54 version
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat authorized
1
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat avoid_reset_quirk
0
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bcdDevice
0100
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bConfigurationValue
1
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bDeviceClass
02
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bDeviceProtocol
00
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bDeviceSubClass
00
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bmAttributes
80
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bMaxPacketSize0
64
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bMaxPower
100mA
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bNumConfigurations
1
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat bNumInterfaces
2
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat busnum
1
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat configuration
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat descriptors
@ K�2
$$$$�@
�@@allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat dev
189:2
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat devnum
3
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat devpath
2
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat idProduct
2012
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat idVendor
1f00
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat ltm_capable
no
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat manufacturer
mbed.org
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat maxchild
0
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat product
CDC DEVICE
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat quirks
0x0
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat removable
unknown
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat remove
cat: remove: 权限不够
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat serial
0123456789
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat speed
12
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat uevent
MAJOR=189
MINOR=2
DEVNAME=bus/usb/001/003
DEVTYPE=usb_device
DRIVER=usb
PRODUCT=1f00/2012/100
TYPE=2/0/0
BUSNUM=001
DEVNUM=003
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat urbnum
138
allankliu@allankliu-VirtualBox:/sys/bus/usb/devices/1-2$ cat version
1.10
crw-rw---- 1 root dialout 166, 0 1月 26 19:38 ttyACM0
sudo ls /sys/kernel/debug/usb/usbmon
[sudo] password for allankliu:
0s 0u 1s 1t 1u
sudo cat /sys/kernel/debug/usb/devices
...
T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 3 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=02(comm.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1f00 ProdID=2012 Rev= 1.00
S: Manufacturer=mbed.org
S: Product=CDC DEVICE
S: SerialNumber=0123456789
C:* #Ifs= 2 Cfg#= 1 Atr=80 MxPwr=100mA
A: FirstIf#= 0 IfCount= 2 Cls=02(comm.) Sub=02 Prot=00
I:* If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=cdc_acm
E: Ad=81(I) Atr=03(Int.) MxPS= 64 Ivl=16ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm
E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
/dev/ttyACM0 is generated as soon as the device is plugged in.
The device can be opened, but not output, regardless the baudrate.
So far, based upon data, I can not find big differences or error from OS, but it has no output anyway, but it has output in Windows/Ubuntu 15 or later.
Next step, I will use wireshark/tcpdump to find out.
After some labs, I found actually this STM32F103C8 (so-called bluepill) has already successfully emuerated. And the USB dongle has been supported in OpenWRT/Ubuntu12.04/14.04/16.04/18.04, but sometimes the device stalls for a while. After such pause, the communication is back to normal.
Pure firmware issue.
Upvotes: 1
Views: 7542
Reputation: 87486
dmesg
and look for messages from Linux's cdc-acm driver when you plug the device in. You can find out what kernel version you are running with uname -a
and then look at the source code of the cdc-acm module in that kernel version.lsusb -v
and make sure they are valid./dev
entry was not being created, that is a different type of problem than if your reads and writes to the port were failing.Using the above methods you should be able to figure out what is wrong and fix it. This is almost certainly a firmware problem, not a hardware problem. I suspect there is something wrong with your USB descriptors so I'd start looking there first.
Upvotes: 0