2010-07-17 11:23:37     serial buffer overflow

Document created by Aaronwu Employee on Aug 22, 2013Last modified by Aaronwu Employee on Aug 22, 2013
Version 2Show Document
  • View in full screen mode

2010-07-17 11:23:37     serial buffer overflow

Howard Gordon (UNITED STATES)

Message: 91395   

 

We're having an issue with lost serial data, with the frequency of errors increasing with higher baud rates.

 

kernel:    Linux release 2.6.28.10-ADI-2009R1.1-svn15, build #22 Tue Jul 13 11:05:36 PDT 2010

toolchain: bfin-uclinux-gcc release gcc version 4.1.2 (ADI svn)

user-dist: release svn-15, build #11 Tue Jul 13 11:05:03 PDT 2010

 

I created a loopback test program using ttyBF1 on the SRV1's 500MHz BF537.  I am changing baud rate from the command prompt using stty and setserial, and my ttytest.c program (attached) just writes a buffer of up to 65536 bytes and reads it back via the same interface.  I have connected UART1TX to UART1RX for loopback.

 

Here are some results:

 

 

 

# stty -F /dev/ttyBF1 115200

stty -F /dev/ttyBF1 115200

# ./ttytest 128

./ttytest 128

buffer size = 128

read successful

# ./ttytest 256

./ttytest 256

buffer size = 256

read failed - only 215 bytes

# ./ttytest 1024

./ttytest 1024

buffer size = 1024

read failed - only 215 bytes

 

# setserial -a /dev/ttyBF1 divisor 9 spd_cust

setserial -a /dev/ttyBF1 divisor 9 spd_cust

# stty -F /dev/ttyBF1 38400

stty -F /dev/ttyBF1 38400

# ./ttytest 128

./ttytest 128

buffer size = 128

read successful

# ./ttytest 256

./ttytest 256

buffer size = 256

read successful

# ./ttytest 1024

./ttytest 1024

buffer size = 1024

read failed - only 512 bytes

# ./ttytest 2048

./ttytest 2048

buffer size = 2048

read failed - only 512 bytes

 

# setserial -a /dev/ttyBF1 divisor 3 spd_cust

setserial -a /dev/ttyBF1 divisor 3 spd_custs

etserial sets custom speed on ttyBF1. This is deprecated.

# stty -F /dev/ttyBF1 38400

stty -F /dev/ttyBF1 38400

# ./ttytest 128

./ttytest 128

buffer size = 128

read successful

# ./ttytest 256

./ttytest 256

buffer size = 256

read successful

# ./ttytest 1024

./ttytest 1024

buffer size = 1024

read failed - only 512 bytes

 

# setserial -a /dev/ttyBF1 divisor 1 spd_cust

setserial sets custom speed on ttyBF1. This is deprecated.

# stty -F /dev/ttyBF1 38400

stty -F /dev/ttyBF1 38400

# ./ttytest 128

./ttytest 128

buffer size = 128

read successful

# ./ttytest 256

./ttytest 256

buffer size = 256

read successful

# ./ttytest 1024

./ttytest 1024

buffer size = 1024

read successful

# ./ttytest 2048

./ttytest 2048

buffer size = 2048

read successful

# ./ttytest 65536

./ttytest 65536

buffer size = 65536

read failed - only 4095 bytes

 

ttytest.c

QuoteReplyEditDelete

 

 

2010-07-17 11:58:14     Re: serial buffer overflow

Howard Gordon (UNITED STATES)

Message: 91396   

 

Here is a modified version that checks integrity of the data.  We're not losing any data along the way, so this is pretty clearly a buffer overflow issue.

 

ttytest.c

QuoteReplyEditDelete

 

 

2010-07-17 14:55:52     Re: serial buffer overflow

Mike Frysinger (UNITED STATES)

Message: 91397   

 

are you using DMA or PIO ?  i thought you were using PIO because you needed GPIO CTS/RTS ?

QuoteReplyEditDelete

 

 

2010-07-17 16:18:21     Re: serial buffer overflow

Howard Gordon (UNITED STATES)

Message: 91399   

 

In this particular configuration, CTSRTS is not enabled on /dev/ttyBF1.  In any case, there isn't any data loss, even at the highest data rates, until the buffer overruns.  It's also interesting that the size of the buffer seems to increase with higher baud rates.

 

In menuconfig, UART Mode is DMA mode.

QuoteReplyEditDelete

 

 

2010-07-19 00:54:29     Re: serial buffer overflow

Sonic Zhang (CHINA)

Message: 91420   

 

You test application is wrong to evaluate the test results. Please man read. "It is not an error if this number is smaller than the number of bytes requested." you should loop read till 0 is returned.

QuoteReplyEditDelete

 

 

2010-07-19 11:00:30     Re: serial buffer overflow

Howard Gordon (UNITED STATES)

Message: 91449   

 

Sonic -  I modified the program as you suggested.  Now I receive the correct number of bytes, but if multiple reads are required, I end up with corrupted data.  Please see attached ...

 

 

 

# stty -F /dev/ttyBF1 115200

# ./ttytest 128

buffer size = 128

read 128 bytes.  total = 128

read successful

data matches

 

# ./ttytest 256

buffer size = 256

read 215 bytes.  total = 215

read 41 bytes.  total = 256

read successful

data mismatch - byte 215

 

# ./ttytest 1024

buffer size = 1024

read 215 bytes.  total = 215

read 229 bytes.  total = 444

read 68 bytes.  total = 512

read 161 bytes.  total = 673

read 228 bytes.  total = 901

read 123 bytes.  total = 1024

read successful

data mismatch - byte 133

 

# setserial -a /dev/ttyBF1 divisor 9 spd_cust

# stty -F /dev/ttyBF1 38400

# ./ttytest 256

buffer size = 256

read 256 bytes.  total = 256

read successful

data matches

 

# ./ttytest 1024

buffer size = 1024

read 512 bytes.  total = 512

read 512 bytes.  total = 1024

read successful

data mismatch - byte 0

 

# ./ttytest 2048

buffer size = 2048

read 512 bytes.  total = 512

read 512 bytes.  total = 1024

read 554 bytes.  total = 1578

read 470 bytes.  total = 2048

read successful

data mismatch - byte 42

 

# setserial -a /dev/ttyBF1 divisor 2 spd_cust

# ./ttytest 1024

buffer size = 1024

read 1024 bytes.  total = 1024

read successful

data matches

 

# ./ttytest 2048

buffer size = 2048

read 1024 bytes.  total = 1024

read 1024 bytes.  total = 2048

read successful

data mismatch - byte 0

 

ttytest.c

QuoteReplyEditDelete

 

 

2010-07-19 11:03:17     Re: serial buffer overflow

Cyril HAENEL (FRANCE)

Message: 91450   

 

Horward, Sonic is right. But I am interested to know the result of the test with the modification. Because I have a problem with a HSDPA modem + pppd on /dev/ttyBF1 (without hardware control, only Tx/Rx) : I have a lot of error in ppp Rx packets, download speed is degraded and I am not able to download successfully a 6Mo file, the modem hangup during connection.

 

With the same modem on my computer, same pppd config file, same speed and no hardware control too, everything is fine...

 

I suspect missing byte in Rx serial port, because at 115200 baud the error rate is ~6% (1000 packet = 60 Rx errors), and at 230400 baud the error rate is ~40% !!

 

Arghhh, I just looked in the kernel configuration, uart are in PIO mode, I try DMA immediately !!

 

 

 

Regards

TranslateQuoteReplyEditDelete

 

 

2010-07-19 11:04:31     Re: serial buffer overflow

Howard Gordon (UNITED STATES)

Message: 91451   

 

Please ignore the previous post.  I didn't move the inbuf pointer so the test isn't valid.

QuoteReplyEditDelete

 

 

2010-07-19 11:09:40     Re: serial buffer overflow

Howard Gordon (UNITED STATES)

Message: 91452   

 

Code is fixed and the errors are gone.  I will have to look elsewhere for the cause of our problem.  Thanks for the help !

 

# ./ttytest 65000

buffer size = 65000

read 4095 bytes.  total = 4095

read 4095 bytes.  total = 8190

read 4095 bytes.  total = 12285

read 4095 bytes.  total = 16380

read 4095 bytes.  total = 20475

read 4095 bytes.  total = 24570

read 4095 bytes.  total = 28665

read 4095 bytes.  total = 32760

read 4095 bytes.  total = 36855

read 4095 bytes.  total = 40950

read 4095 bytes.  total = 45045

read 4095 bytes.  total = 49140

read 4095 bytes.  total = 53235

read 4095 bytes.  total = 57330

read 4095 bytes.  total = 61425

read 3575 bytes.  total = 65000

read successful

data matches

 

ttytest.c

QuoteReplyEditDelete

 

 

2010-07-19 11:13:58     Re: serial buffer overflow

Howard Gordon (UNITED STATES)

Message: 91453   

 

Cyril - I suspect our problem is related to hardware flow control with the Matchport - it occurs when we are sending images from Blackfin to host.  I think the Matchport uart only has a 4 byte fifo so response time with the flow control is critical.  I will probably have to experiment with padding the time between bytes sent to see if I can minimize the data loss.

 

Howard

QuoteReplyEditDelete

 

 

2010-07-19 11:56:57     Re: serial buffer overflow

Cyril HAENEL (FRANCE)

Message: 91455   

 

In my case the problem was the serial port config, with dma mode it work well now, at a baudrate of 230400 bauds !!

 

0 error packet on a 6Mo file transfer, great !

 

 

 

Regards

TranslateQuoteReplyEditDelete

 

 

2010-07-19 12:35:44     Re: serial buffer overflow

Howard Gordon (UNITED STATES)

Message: 91457   

 

That's good news.

 

Somewhat off-topic, but are you running the SRV1 board ?  If so, what linux version are you running, and is video capture working okay for you ?

QuoteReplyEditDelete

Attachments

Outcomes