serial device on Linux hangs after few minutes of data transmission

2.6k Views Asked by At

I am using openwrt (an embedded linux that runs on routers). I am using a USB-to-serial converter that shows up as /dev/ttyACM0.

[ 2430.460000] usb 1-1: new full-speed USB device number 4 using ehci-platform
[ 2430.630000] cdc_acm 1-1:1.0: This device cannot do calls on its own. It is not a modem.
[ 2430.630000] cdc_acm 1-1:1.0: ttyACM0: USB ACM device

I wrote a small code for openwrt which opens the given serial port, /dev/ttyACMO, waits on a select() system call for read/write events on the serial port fd.
Whenever a read event occurs the message is dumped to stdout.
I have not enabled the hardware flow control on the serial port.

I made the connected peripheral send some predefined message every 2 second on the serial link.
Now when I run my code in openwrt to print the serial message, I am able to see the message coming from the peripheral.
The problem is after few minutes the serial link drops dead. There are no more read events on the serial interface.
Resetting the peripheral also does not help. The only way to make it work again is to completely remove the peripheral from the USB and start again.
The same setup works perfectly fine on my Ubuntu box. I use the same driver interface, i.e. usb-acm (in /dev/ttyACM0). Here the system keeps running forever without the serial hangup.

Any idea or suggestion on what's happening?

2

There are 2 best solutions below

0
On

i would try: using serial at slower speed 9600, you might want to try to reproduce the problem using some terminal emulator on the wrt side - you ssh into it and try:

(while :;do echo .;sleep 1m;done) >> /dev/serialdevicename

i have one more tip: try to bind some program to the serial console using inittab

you might want to think about other approaches to your original problem, and look for alternatives which doesn't use serial at all (if it's possible)

when the connection breaks...

  • are there messages in dmesg?
  • if your usb plug has leds for rx/tx they should blink a bit every 2 sec...after the hang it blinks or not?

possibliy no-op hint: ground is connected correctly? check with multimeter

0
On

If you're using an AR9331-based router (very common), there's a well-known issue with CDC ACM devices via USB. The scenario is USB connected at "Full Speed" 12Mbps AND Wifi is configured as a client AND is not associated with an AP. The USB will hang. This is apparently a hardware bug in the AR9331 for which there is no software work-around.

Turning off the wifi interface should solve this, a work-around that retains wifi is to use a USB 2.0 hub to effectively convert the connection speed to the AR9331 up to USB2.0 High Speed (480Mbps); the only problem you may encounter is that some USB 2.0 hubs are inferior so you might need to try one or two.