MattOwnby
Posts: 58
Joined: Thu Aug 16, 2012 7:22 pm

GPIO UART (/dev/ttyAMA0) closes randomly (EOF)

Wed Sep 05, 2012 5:42 pm

(I've searched for AMA and UART before posting this)

So I've recently got /dev/ttyAMA0 working . I use it mainly by calling read (in blocking mode) on it to grab data as fast as possible. I've noticed that it randomly will return a 0 from read(...) which means EOF and any subsequent attempt to call read keeps returning 0. Does anyone know how I can prevent this? I need the port to stay open.

It should be easy to dupe for anyone who has this UART setup.

My source code is right here: http://www.rulecity.com/browse/rpi/sertest.cpp.txt

To build, just do :
g++ sertest.cpp -o sertest

Here is a sample of the output I get when I run it twice.

Code: Select all

pi@raspberrypi /mnt/vldp-hw/src/io $ ./sertest
1008
2001
terminate called after throwing an instance of 'std::runtime_error'
  what():  Got unexpected EOF!
Aborted
pi@raspberrypi /mnt/vldp-hw/src/io $ ./sertest
1008
2008
3008
4008
5008
terminate called after throwing an instance of 'std::runtime_error'
  what():  Got unexpected EOF!
Aborted
The serial port on the other end is continuously sending data at about a rate of 2900 bytes/second so less than the capacity of the 115200 speed setting.

MattOwnby
Posts: 58
Joined: Thu Aug 16, 2012 7:22 pm

Re: GPIO UART (/dev/ttyAMA0) closes randomly (EOF)

Wed Sep 05, 2012 9:08 pm

I've done a little bit more research.

After read returns 0 (EOF), if I close the device and then immediately try to re-open it, open returns -1 and errno is set to (5) which is EIO (I/O error). Waiting a little while and then trying to open again succeeds.

*sigh*

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

Re: GPIO UART (/dev/ttyAMA0) closes randomly (EOF)

Wed Sep 05, 2012 10:08 pm

Have you properly disabled the port as console debug port? I think it also has the serial linux console running at it.
That one should be disabled as well.
There is a thread somewhere describing this 2 actions.
If you already did these 2, simply ignore this writing.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO UART (/dev/ttyAMA0) closes randomly (EOF)

Wed Sep 05, 2012 10:16 pm

obcd wrote:Have you properly disabled the port as console debug port? I think it also has the serial linux console running at it.
That one should be disabled as well.
There is a thread somewhere describing this 2 actions.
If you already did these 2, simply ignore this writing.
i.e. remove mention of /dev/ttyAMA0 from /boot/cmdline.txt and from /etc/inittab.

MattOwnby
Posts: 58
Joined: Thu Aug 16, 2012 7:22 pm

Re: GPIO UART (/dev/ttyAMA0) closes randomly (EOF)

Wed Sep 05, 2012 10:38 pm

joan wrote:i.e. remove mention of /dev/ttyAMA0 from /boot/cmdline.txt and from /etc/inittab.
YES!!! That was it! I had removed it from /boot/cmdline.txt but didn't know I needed to also remove it from /etc/inittab !! *phew*

Thank you thank you thank you!! I was starting to build the kernel in debug mode to try to troubleshoot this! :) Now I don't have to.

Return to “Troubleshooting”