This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Serial comms


On Wed, Apr 15, 2009 at 02:01:39AM -0700, grahamlab wrote:
> 
> 
> 
> Sergei Gavrikov-4 wrote:
> > 
> > On Tue, Apr 14, 2009 at 03:04:29AM -0700, grahamlab wrote:
> >> 
> >> Hello everyone
> >> I am relatively new to eCos so please forgive me my questions seem naive.
> >> I am developing software targeted at the STM3210e dev board and am trying
> >> to
> >> get serial comms going between this board and a program running under
> >> ubuntu
> >> via virtual box on my PC
> >> I have a serial link between the PC and the dev kit (UART1) that uses
> >> ttyS0
> >> to load the ecos program via gdb. This works, I can download and execute
> >> an
> >> eCos program on the Dev board.
> >> I have another serial link between my PC and the dev kit (UART2).
> >> I have written 2 programs - one using eCos and one to run under ubuntu.
> >> The eCos program opens the /dev/ser1 device and writes a string to that
> >> device and awaits a reply.
> >> The ubuntu opens /dev/ttyS1 and waits for a message and then writes back
> >> an
> >> acknowledgment.
> >> 
> >> When these two programs are run I get the following results.
> >> 
> >> When the ecos program sends its data the ubuntu program receives alot of
> >> data from the Redboot monitor and then the data from the ecos program. It
> >> then blocks on the write. The ecos program has blocked on the read.
> >> 
> >> Why do I get data from the Redboot monitor and why do both programs
> >> block.
> >> I have attached both programs 
> >> http://www.nabble.com/file/p23036433/hello.cpp hello.cpp ,
> >> http://www.nabble.com/file/p23036433/SerialTest.cpp SerialTest.cpp 
> >> 
> >> Thank you for your time
> >> Graham
> > 
> > Graham, it seems for me, your eCos application quite crashes (board
> > resets itself) and you see/get the Redboot's startup screen in your
> > program. Your code is terrible, you do not check return-codes!
> > 
> > hello.cpp:
> > while (1) {
> >     // ...
> >     res = read(fd, buf, 4096);
> >     buf[res] = 0;
> >     // ...
> > }
> > 
> > SerialTest.cpp:
> > while (1) {
> >     // ...
> >     int             b = read(fd, &buf[0], 4096);
> >     buf[b] = '\0';
> >     // ...
> > }
> > 
> > How do you think, What will happy on buf[-1] = 0 ? Read about the return
> > values of read(), write().
> > 
> > man 2 read
> > man 2 write
> > 
> > Your while() blocks are terrible things which will eat all CPU time if
> > they will work at all.
> > 
> > Your hello.cpp is written for PC and that is almost just an echo
> > program.  Why do not use terminal program (minicom, hyperterm) at first
> > to debug the eCos termios program? It seemed for me that you are not
> > only "new" to eCos. Why we took a time to stand up GDB for you? 
> > 
> > Learn programming, learn C 
> > 
> > http://en.wikibooks.org/wiki/C_Programming
> > 
> > Then learn eCos programming.
> > 
> > 
> > Sergei
> > 
> > -- 
> > Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
> > and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
> > 
> > 
> > 
> Sergei
> I have used the mincom program to receive a test string from ecos
> When I use a PC program of my making to read a string I receive data from
> redboot before I receive the test string. I do not know why this is the case
> and would appreciate any explanation
> 
> Graham

On start Redboot (by default) outs own startup screens an both serial
channels. You can see it. Run on two consoles

on 1st console:
stty speed 38400 -F /dev/ttyS0
cat /dev/ttyS0

on 2nd console:
stty speed 38400 -F /dev/ttyS1
cat /dev/ttyS1

connect cables to the board and then press a Reset button. You will see
that data will come on both consoles.

So, when board is reset, Redboot's banner already exists in PC's serial
buffer, but that lines has been not read yet (/dev/ttyS1). When you run
your PC program, it reads that portion of lines and then it read next
incoming data. So, your program should flush serial buffer before to
start that read loop.


Sergei

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]