OpenWrt Forum Archive

Topic: microcontroller communication through serial using usb2serial

The content of this topic has been archived on 30 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I wanted to interface with a microcontroller using serial communication from openwrt. I prepared a setup as below
1. I download and flahsed the trunk snapshot firmware for D-LINK DIR 505 from the openwrt website.
2. Then i compiled my own openwrt image from the trunk source. This time i selected some of the usb drivers (usb-acm) and network drivers.
3. I upgrade my router with this new image through sysupgrade.
4. The image comes up and everything works fine.
My micrcontroller board has a usb to serial converter that uses an STM32F chip. This is detected as an acm device. So i
already had installed the kmod-usb-acm module.  When i plug my microcontroller board to the routers usb, In the dmesg
i see that its detected as an acm device and i seee an /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 (here /dev/ttyACMO) waits on a select (system call) on read/write events for the serial ports fd. whenever a read events occurs i dump the message into stdout.
I made the micrcontroller send some predifined 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 microcontroller.
the problem is after few minutes the serial drops dead. There is no more read events on the serial interface.
Restting the micrcontroller also doesnot help. The only way to make it work again is to completely remove the microcontroller board 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 whats happening.

Thanks. It is exactly the problem i was facing.

Dlink DIR-505 uses AR9331 chipset.

The discussion might have continued from here.