[En-Nut-Discussion] how to assign stdout, stdin and sterr to the same uart?

Ernst Stippl ernst at stippl.org
Fri Oct 26 10:54:20 CEST 2007


Hi Matthias!

Some time ago (still under Nut/OS 3.9.x) I tried to be able to write to the
uart while possibly receiving input chars, but I never received any input,
even when I knew I was sending chars to the rx uart pin.
I did receive the chars as soon as I disabled the output to the uart and did
not open it for write. 
However, I did not use stdin/stdout, but two "private" fd's.
Eventually, I gave up and worked around the requirement, but I am still
curious if I did something wrong or if the usart driver is just not ready to
do this.

Regards
Ernst

-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von Matthias
Ringwald
Gesendet: Donnerstag, 25. Oktober 2007 19:53
An: Ethernut User Chat (English)
Betreff: [En-Nut-Discussion] how to assign stdout,stdin and sterr to the
same uart?

hi there

after years of using nut/os, I've just stumbled about a newbie  
question/problem.

how do I correctly assign stdout AND stdin to the uart?

the default code in many examples is:

     NutRegisterDevice(&devUsartAvr0, 0, 0);
     freopen(devUsartAvr0.dev_name, "w", stdout);

so far, that's fine. printf works. But when you call e.g. kbhit() it  
never returns as stdin was never assigned.

Browsing the mail archive I've seen people doing it like this:

   NutRegisterDevice(&devUsartAvr0, 0, 0);
   freopen(devUsartAvr0.dev_name, "w", stdout);
   freopen(devUsartAvr0.dev_name, "r", stdin);

this sounds logical, but with the current nut/os code (or the one  
from last year..) this is not perfect / probably incorrect.

_freopen first looks for the proper __iob entry and then calls _open  
for the given device with the given flags.
the usart on the avr is not written to be opened twice, especially  
with different mode flags, everything is reset.

any clues how to do it properly?

cheers,
matthias ringwald

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion



-- 
No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.503 / Virus Database: 269.15.11/1093 - Release Date: 25.10.2007
17:38





More information about the En-Nut-Discussion mailing list