2010-09-28 13:10:25 Problem with SPORT to UART emulation
Olivier STOCK (FRANCE)
Message: 93924
Hi,
Today we have done some tests with various devices connected to UART ttySS1 (which is the UART from SPORT 1 emulation).
There are receive errors on the SPORT receiver (corrupted caracters) when baudrate of the device connected is lower than the baudrate of the SPORT.
We have measured the SPORT baudrate precisely (with scope) at 57670. Then we open the /dev/ttySS1 port for reading. If the device connected to our board sends caracters at 57800bauds, everything is OK. Now, if the device sends caracters at 57600bauds, the received chars are corrupted.
Our test setup:
-> kernel 2.6.34 (2010beta1)
-> driver bfin_sport_uart compiled and loaded on SPORT 1 (creates the device /dev/ttySS1)
-> test baudrate : 57600 8N1
Does anyone have ever seen this problem ? It seems that all PC based hardware have faster baudrate than 57600 so it doesn't trigger the problem ...
Note: we found someone with a similar problem here : www.koders.com/c/fid3696790ADD2585BC88B7F09D674DF0E7F5718E02.aspx?s=crc
To overcome the sampling problem explained by "Axel Alatalo", is it possible to set the receive baudrate of the SPORT emulation slightly lower than the exact one ?
Thanks for your help,
Xavier
QuoteReplyEditDelete
2010-09-28 13:31:52 Re: Problem with SPORT to UART emulation
Mike Frysinger (UNITED STATES)
Message: 93926
i'm not sure why you expect to be able to have two devices work when they arent using the same baud rate
if the device is configured for 57800, why arent you configuring the SPORT to be 57800 ?
i have no idea where that source is coming from or what the exact change is, but if you read the whole comment, it is talking about single bit sampling and clock drifts. that is not the same thing as using different speeds.
QuoteReplyEditDelete
2010-09-29 01:02:21 Re: Problem with SPORT to UART emulation
Sonic Zhang (CHINA)
Message: 93940
The sport clock is divided from the system clock. When you ask for 57600, the actually clock could be some value arround 57600. You can adjust the DIV in the driver.
QuoteReplyEditDelete
2010-09-29 03:35:04 Re: Problem with SPORT to UART emulation
Olivier STOCK (FRANCE)
Message: 93955
Hi,
Thanks for your fast comments. Here are some more explanations.
Clock shift and slightly different baud rates are the same thing. Remember that we are talking about asynchronous communications. Furthermore according to Sonic, baud rate tends to target the 57600 due to divisor values so ones may be slightly over 57600 and others sligtly upper (2% speed difference is very current).
In the test we carry yesterday we find out that if baudrate is under the SPORT emulation exact baud rate (57670) , receive errors happen. ( we have made a test wit a custom variable baud rate generartor, SPORT is working when generator baud is at 57671 and exhibits errors when sport is at 57669 || Here we are in clock shift domain, right ?)
So to overcome this bug, we have the idea to set systematically in the driver the RX sport baud rate below ( let's say 2 to 3%) the TX target baud rate the user ask for.
Hope our explanation is more clear, looking fwd your comments.
Regards, Olivier.
QuoteReplyEditDelete
2010-09-29 04:29:15 Re: Problem with SPORT to UART emulation
Julien Vermillard (FRANCE)
Message: 93959
I think I stumbled on the same problem. I had corrupt chars with SPORT UART emulation and never figured why. I'll take a look at the *exact* baud rate of my devices. It's perhaps the same issue.
QuoteReplyEditDelete
2010-09-29 04:50:22 Re: Problem with SPORT to UART emulation
Olivier STOCK (FRANCE)
Message: 93964
If you do the measure, be sure to take care of the pulse width distortion of the RS232 driver (ie "0" state doesn't have the exact same width as the "1" state on the wires, especially at high baudrate).
To be more accurate, we have measured, the duration between the edges of start and stop bit then we have divided the measured value by 9 to get the baudrate.
Xavier
QuoteReplyEditDelete
2010-09-29 05:00:36 Re: Problem with SPORT to UART emulation
Sonic Zhang (CHINA)
Message: 93965
You may try following patch to see if it helps.
Index: drivers/serial/bfin_sport_uart.c
===================================================================
--- drivers/serial/bfin_sport_uart.c (revision 9161)
+++ drivers/serial/bfin_sport_uart.c (working copy)
@@ -131,7 +131,7 @@
pr_debug("%s RCR1:%x, RCR2:%x\n", __func__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up));
tclkdiv = sclk / (2 * baud_rate) - 1;
- rclkdiv = sclk / (2 * baud_rate * 2) - 1;
+ rclkdiv = sclk / (2 * baud_rate * 2);
SPORT_PUT_TCLKDIV(up, tclkdiv);
SPORT_PUT_RCLKDIV(up, rclkdiv);
SSYNC();
QuoteReplyEditDelete
2010-09-29 05:37:52 Re: Problem with SPORT to UART emulation
Olivier STOCK (FRANCE)
Message: 93966
Hi,
Thanks for your patch. In the same way, we propose the following improved patch we have just tested :
--- bfin_sport_uart_original.c 2010-09-27 18:15:53.866125283 +0200
+++ bfin_sport_uart.c 2010-09-29 11:29:49.128294770 +0200
@@ -134,7 +138,7 @@
pr_debug("%s RCR1:%x, RCR2:%x\n", __func__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up));
tclkdiv = sclk/(2 * baud_rate) - 1;
- rclkdiv = sclk/(2 * baud_rate * 2) - 1;
+ rclkdiv = sclk/(2 * (baud_rate * 97 / 100) * 2) - 1;
SPORT_PUT_TCLKDIV(up, tclkdiv);
SPORT_PUT_RCLKDIV(up, rclkdiv);
SSYNC();
When configured at 57600 bauds, It works with input baudrate from 56250 to 59094 (about +- 2.4% tolerance). It needs to be tested at other baudrates ...
Regards,
Xavier
QuoteReplyEditDelete
2010-09-29 06:51:17 Re: Problem with SPORT to UART emulation
Sonic Zhang (CHINA)
Message: 93970
Doesn't my patch work?
Why do you think 97% is better than enlarge 1 step in divisor?
QuoteReplyEditDelete
2010-09-29 07:44:20 Re: Problem with SPORT to UART emulation
Olivier STOCK (FRANCE)
Message: 93972
Dear Sonic,
Yes your patch may work but adding 1 to divisor is not enough, with 3% lowering, rclkdiv divisor is set at 447 instead of 433 (nominal value).
Regards, Olivier.
QuoteReplyEditDelete
2010-09-30 04:08:05 Re: Problem with SPORT to UART emulation
Sonic Zhang (CHINA)
Message: 94061
You said in former comments that the SPORT RX clock should be at least one clock slower than the input data clock. If you ask for 57600, the original formular sets the actual RX sample rate to 57670*2 by divisor 433. With my patch, the RX sample rate is set to 57537*2 by divisor 434, which meets your requirement.
So, why an extra 3% lowing is necessary?
QuoteReplyEditDelete
2010-09-30 04:14:06 Re: Problem with SPORT to UART emulation
Sonic Zhang (CHINA)
Message: 94062
OK, I see your point. The TX clock of some uart device may be 2% slower than asked.
But, if it is 2% faster while bfin_sport_uart is set to 3% slower, there is actually 5% difference in worst case. Is this setting still work?
QuoteReplyEditDelete
2010-09-30 13:03:48 Re: Problem with SPORT to UART emulation
Olivier STOCK (FRANCE)
Message: 94081
Dear Sonic,
In fact we set it to 3% lower and test precisely the limits of the sport emulation @57600bds; Our tests state that sport_uart is error free if incoming bitrate is at 57600 +- 2.4%. According to your remark, this tolerance is quite restrictive regarding to a true UART hardware which will sample each bit three times approximatively in the expected middle of the bit time. Thus exhibitng a +- 5% datarate tolerance. Hope you'll integrate our patch in this code.
Regards, Olivier.
QuoteReplyEditDelete
2010-10-25 09:54:47 Re: Problem with SPORT to UART emulation
Julien Vermillard (FRANCE)
Message: 95138
With the last trunk update my aren't scrambled anymore !
I suppose it was the same baudrate problem.
Thanks
Julien