overflo
Posts: 4
Joined: Wed Apr 17, 2013 11:49 am

USB Serial Problem

Wed Apr 17, 2013 12:35 pm

Hi,

I traced a bug pretty deep down to the USB of raspberry pi (unless i did something wrong on the way).
It seems like the pi drops USB frames without notice.

I wrote a testprogramm on an arduino

Code: Select all

setup()
{
 Serial.begin(9600);
}

loop()
{
 Serial.print("mux: 1 pin: 2 ticks: 3\n");
}
no external components attached to the arduino, powered over USB from the raspberry itself.
the arduino sends the string over the onboard FTDI chip serial over usb to the computer.
this works without a problem on my workstation and on a macbook.


on a raspberry pi i loose characters every 100-4000 lines.
there is no pattern visible to me.
it seems like the parts of the data just do not arrive on the raspberry pi.

i wrote a testprogram in python that utilizes pyserial.
this program works on the testmachines but produces the same errors on the rpi.
running screen on the /dev/ttyACM0 reproduces the problem and proves that it exists independent of the software used to talk to the serial.

changing the baud rate, the cable, the powersupply and the raspberry itself did not resolve this bug.
i tested it on 2 rpi with different sdcards and up-to-date releases of wheezy.

i will probably remove the arduino and make everything directly on the rpi as a solution, but this is a very strange bug and needs to be resolved.
i am interested if you know about it or have any idea how to resolve this or where to look for answers. so far i found only similar issues but not the exact same problems.

overflo
Posts: 4
Joined: Wed Apr 17, 2013 11:49 am

Re: USB Serial Problem

Wed Apr 17, 2013 1:22 pm

i just got his reply when i asked at my local hackerspaces mailinglist for help.

sum up: the recommendation is to use an even slower baudrate and see if that changes anything


so i tried 2400 baud. it works.

this is frustrating.. but at least the problem is kind of solved.



reply (warning: german ahead)

Kann sein, dass die flow control nicht funktioniert oder nicht implementiert ist.
Über die serielle schickst Du dem FTDI Daten, die er wieder los werden muss.
Ohne flow control kann er's nicht bremsen.
Auf der USB-Seite wird der FTDI per bulk endpoint gepollt.
Da kann er nur so viele Daten loswerden, wie der host abholt.
Dazwischen hängt ein Buffer. Wenn der überläuft, dann gehen Daten verloren.

Der Raspberry Pi ist etwas langsamer als der Durchschnitts-PC. Es kann also durchaus sein, dass er manchmal wegen grosser Last das Pollen der USB Devices verlangsamt, oder dass der Prozess, der die Daten auf der Host-Seite bearbeitet, nicht nachkommt.

Wenn eine sehr langsame baudrate auch nix nutzt, dann wird wahrscheinlich das Pollen auf längere Zeit aufgehalten oder der User-Prozess, der die Daten abholt, steht für einige Zeit.

Zähl' einmal einen Counter hoch und schau', wieviel da jedes Mal verloren geht. Vielleicht geht eh weniger verloren, wenn die baudrate kleiner ist.

--
DI Christian Starkjohann
OBJECTIVE DEVELOPMENT Software GmbH

obcd
Posts: 917
Joined: Sun Jul 29, 2012 9:06 pm

Re: USB Serial Problem

Wed Apr 17, 2013 1:26 pm

What kernel are you using?
uname -a
might give you that information.
There are known issues with the Pi Usb, but recently a fix came out that should fix them for usb2serial
devices.
I asked if the fix could possibly cause packets to be lost and got a negative answer.
If you already use a kernel with that patch, it would mean that indeed some packets might get lost.
The last pages of the usb redux show the progres that was made.

stijn.ghesquiere
Posts: 26
Joined: Sat May 19, 2012 9:44 pm

Re: USB Serial Problem

Wed Apr 17, 2013 1:43 pm

Have you tried adding:
dwc_otg.speed=1
to /boot/cmdline.txt?

It set the USB to slower speed and for me it fixed the dropping packets. If you can live with slower USB (network,wifi,usb harddisks), it might work for you. I can use 115200baud through an USBtoRS232 adapter.

overflo
Posts: 4
Joined: Wed Apr 17, 2013 11:49 am

Re: USB Serial Problem

Wed Apr 17, 2013 1:53 pm

obcd wrote:What kernel are you using?.

The problem is there for

Linux powerpi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux

AND for

Linux powerpi 3.6.11+ #371 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux


as well.
changing the baudrate to 2400 "solved" the problem for now.. but this is of course not an acceptable solution.

obcd
Posts: 917
Joined: Sun Jul 29, 2012 9:06 pm

Re: USB Serial Problem

Wed Apr 17, 2013 3:40 pm

You should send your data in bursts for a normal test. Adding a delay of 0.2 sec after every datablock should give the receiver (pi) time to catch up with the datastream of the transmitting device, and no data should get lost like that, even without handshaking.
The previous proposed solution changes the Pi usb system to usb 1.1 speed. It should solve the issue but it also limits the network troughput as that also uses the usb.
The latest kernels should be 3.6 rev. 400+. You can use the hexxeh updater to obtain them. There also is a 3.8 branch, but that's still experimental.

Return to “Troubleshooting”