U(s)arts not properly working at 115200 on at91sam9g25

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

misarm
Location: EUROPE
Posts: 18
Joined: Wed Oct 03, 2007 9:31 am

U(s)arts not properly working at 115200 on at91sam9g25

Thu May 22, 2014 10:58 am

I have custom board with at91sam9g25 - linux kernel 3.13.5, tried also 3.15-rc5 with same results. I am using device tree based on at91sam9g25.

In default state (DMA off) - I can see overruns (missing characters on Rx).
If I enable DMA (using device tree) Driver (# cat /proc/tty/driver/atmel_serial) shows no overruns, but I can see corrupted stream - 3-xx characters - like very old data come from serial line instead of new (like reading old DMA buffer).
If I enable DMA only on Rx side, corruption is more massive...
I tested it with external source, also with Rx-Tx pins connected (connected in external FPGA).
Ideally I want to use DMA + higher baudrates than 115200 for two ports... (for slip interface).

DMA+external loopback test (tx+rx connected in FPGA) - Tested on ssh terminals:
terminal1 :

Code: Select all

# cat /dev/ttyS3  > /tmp/test
terminal2 :

Code: Select all

# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS3

# cat /tmp/test
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<m
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:nm
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}bnm
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{vbnm
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|cvbnm
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+xcvbnm
then break cat in terminal 1 and run it again


then in terminal 2 :

Code: Select all

# echo 'qwertyuiopasdfghjklzxcvbnm' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm' > /dev/ttyS3
# echo 'qwertyuiopasdfghjklzxcvbnm' > /dev/ttyS3

# cat /tmp/test
qwertyuiopasdfghjklzxcvbnm1qwertyuiopasdfghjklzxDFGHJKqwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnm1qwertyuiopasdfghjklzSDFGHJK#
Where we can see wrong characters FROM OLD INPUT.
It seems like DMA buffers underflow/overflow or something...

serial port setting:

Code: Select all

# stty -F /dev/ttyS3 -g
0:0:18b2:0:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
# stty -F /dev/ttyS3 -a
speed 115200 baud;stty: /dev/ttyS3
 line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>;
start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel
-iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke
Have somebody also problems with atmel_serial driver?
I have tried it also at lower baud rates and with DMA, both usarts(in uart mode)/uarts - it also don't work.
What else should i try?

Thanks
Martin
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: U(s)arts not properly working at 115200 on at91sam9g25

Fri May 23, 2014 4:00 am

misarm wrote:I have tried it also at lower baud rates and with DMA, both usarts(in uart mode)/uarts - it also don't work.
So have you gotten these serial ports to work under any conditions?
IIRC the 2.6.39-at91 release at Linux4SAM officially supported DMA for the serial ports on SAM9x5.
Maybe you should build a minimal-configuration kernel of this version as a sanity test for your board?

FWIW USART1 in ext loopback mode on my G25 board passed your first test at 115200 baud w/PIO. I've never tried to test with DMA.

Code: Select all

# stty -F /dev/ttyS2 
speed 115200 baud; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
#
# cat /dev/ttyS2  > /tmp/test &
#
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# echo 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>' > /dev/ttyS2
# cat test
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+|{}:<>
# uname -a
Linux buildroot 3.12.9 #1 PREEMPT Fri Mar 7 00:28:33 PST 2014 armv5tejl GNU/Linux
#
Also try reading these threads: discussions/viewtopic.php/f,9/t,21497/
and
discussions/viewtopic.php/f,12/t,21144/

Regards
misarm
Location: EUROPE
Posts: 18
Joined: Wed Oct 03, 2007 9:31 am

Re: U(s)arts not properly working at 115200 on at91sam9g25

Fri May 23, 2014 10:09 am

Thank you,
blue_z wrote:So have you gotten these serial ports to work under any conditions?
I have two ports working OK at 19200 baud w/PIO.
115200 baud without DMA works - with some data loss (oe: are reported by driver). In stress conditions it losses about 2-5 bytes in ten seconds.
I have patched atmel_serial.c to see overruns in console and :
if output (cat /dev/ttySX) is done to ssh console overruns happens significantly more often (20x) than in serial console or output is to file (tested through ethernet and USB gadget - almost same).
With DMA it works worse (data corruption is higher also at lower baud rates).
blue_z wrote: IIRC the 2.6.39-at91 release at Linux4SAM officially supported DMA for the serial ports on SAM9x5.
Maybe you should build a minimal-configuration kernel of this version as a sanity test for your board?
I have downloaded sources (git clone git://github.com/linux4sam/linux-at91.git)
and see in /drivers/tty/serial/atmel_serial.c, that there is no locking/ dma channel management (like in 3.x kernels) - so I supposed that DMA is for 9260/3 only... but not newer 9g25, so I didn't compile it...
also in devicetree dma is enabled by default only for 9260/3 and 9g45

if I tried only atmel,use-dma-rx; atmel,use-dma-tx; options in 3.X kernel, without dmas = xx,xx; and dma-names = "tx","rx";
kernel hanged with first attempt to access serial port...
blue_z wrote: FWIW USART1 in ext loopback mode on my G25 board passed your first test at 115200 baud w/PIO. I've never tried to test with DMA.
Your(my) echo test sometimes runs OK for my board w/PIO, sometimes there are overruns (tested 10 times, 3 of them failed), with DMA on - all failed.
Could you please test it more times / send bigger file through serial line and diff input/output files, or check cat /proc/tty/driver/atmel_serial if some oe: are present?
Thanks
blue_z wrote: Also try reading these threads: discussions/viewtopic.php/f,9/t,21497/
and
discussions/viewtopic.php/f,12/t,21144/
Thanks, I have read them previously,...

Maybe now I try to compile git version of linux-at91 to check whether problems will be the same (I assume that DMA will not work), problem is that I need to compile also my drivers for FPGA fitting, for loopback (fpga does external loopback)...

my kernel version is

Code: Select all

# uname -a
Linux MM 3.13.5 #27 PREEMPT Tue May 20 12:41:43 CEST 2014 armv5tejl GNU/Linux
my DMA setting in device tree dtb/dtsi is for usart2 (ttyS3)
and usart3 (ttyS4) - without DMA

Code: Select all

      usart2: serial@f8024000 {
        compatible = "atmel,at91sam9260-usart";
        reg = <0xf8024000 0x200>;
        interrupts = <7 IRQ_TYPE_LEVEL_HIGH 5>;
        atmel,use-dma-tx;
        atmel,use-dma-rx;
        dmas = <&dma1 1 AT91_DMA_CFG_PER_ID(12)>,
               <&dma1 1 AT91_DMA_CFG_PER_ID(13)>;
        dma-names = "tx","rx";
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_usart2>;
        status = "disabled";
      };
      usart3: serial@f8028000 {
        compatible = "atmel,at91sam9260-usart";
        reg = <0xf8028000 0x200>;
        interrupts = <8 IRQ_TYPE_LEVEL_HIGH 5>;
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_usart3>;
        status = "disabled";
      };
Regards
blue_z
Location: USA
Posts: 1560
Joined: Thu Apr 19, 2007 10:15 pm

Re: U(s)arts not properly working at 115200 on at91sam9g25

Sat May 24, 2014 3:08 am

misarm wrote:if output (cat /dev/ttySX) is done to ssh console overruns happens significantly more often (20x) than in serial console or output is to file (tested through ethernet and USB gadget - almost same).
That's expected.
You could play around with bus matrix priorities to try to lessen that.
misarm wrote:Could you please test it more times / send bigger file through serial line and diff input/output files, or check cat /proc/tty/driver/atmel_serial if some oe: are present?
I did (as large as 700KB), and all transferred okay.
But I did notice rather slow transfer times (as much as 2.5 times slower than expected).
So I undid the loopback and connected to a serial port on a PC. In each direction, on the first transfer there would be overrun errors (oe count was only 2 on the G25) and data loss (almost 50%). But subsequent transfers, 20 transfers of 4KB, were perfect.
The PC would send the 4KB of data in 0.387 seconds, just a tad more than the minimal 0.379 seconds for 4362 bytes.
The Atmel USART on the G25 using PIO required 0.74 seconds to send the same data.
So receiving with PIO seems to work at 115200, but transmitting at 115200 with PIO will introduce intercharacter delays.

Regards
misarm
Location: EUROPE
Posts: 18
Joined: Wed Oct 03, 2007 9:31 am

Re: U(s)arts not properly working at 115200 on at91sam9g25

Tue May 27, 2014 10:22 am

Thank you blue_z,
so because I need to cooperate with other devices at 115200 I think I need to use DMA, which should solve fifo overrun issues.
Please is anybody who have working U(S)ARTs with DMA on at91sam9g25?
Thanks.
Martin
misarm
Location: EUROPE
Posts: 18
Joined: Wed Oct 03, 2007 9:31 am

Re: U(s)arts not properly working at 115200 on at91sam9g25

Fri Jun 20, 2014 3:24 pm

Nobody?
drzile
Posts: 9
Joined: Thu Mar 26, 2015 11:42 am

Re: U(s)arts not properly working at 115200 on at91sam9g25

Thu Mar 26, 2015 5:34 pm

Hello,

Did you solve this issue with U(S)ART? I have similar problem
discussions/viewtopic.php/f,33/t,23902.html

Regards,
misarm
Location: EUROPE
Posts: 18
Joined: Wed Oct 03, 2007 9:31 am

Re: U(s)arts not properly working at 115200 on at91sam9g25

Mon Sep 26, 2016 8:41 am

We have made a new project and I have tried it again now with 4.1.0 kernel from github and U(S)ARTs seems to work properly (with DMA switched on).
Thank you.
Martin
misarm
Location: EUROPE
Posts: 18
Joined: Wed Oct 03, 2007 9:31 am

Re: U(s)arts not properly working at 115200 on at91sam9g25

Wed Jul 19, 2017 2:41 pm

After some stress tests we have found, that it is not OK, some of ports are still producing errors (it depends on overall system load - we are intensively using SPI, mdc , four uarts and less intensively eth0), but it is better than on older kernel.
misarm
Location: EUROPE
Posts: 18
Joined: Wed Oct 03, 2007 9:31 am

Re: U(s)arts not properly working at 115200 on at91sam9g25

Fri Aug 18, 2017 9:30 am

Thank you,
I can see it...
I have missing

Code: Select all

        atmel,use-dma-rx;
        atmel,use-dma-tx;
lines in DT, so uarts didn't use DMA...

now it seems to work OK.

Return to “Linux”

Who is online

Users browsing this forum: Google [Bot] and 1 guest