[En-Nut-Discussion] how to assign stdout, stdin and sterr to the same uart?
Matthias Ringwald
mringwal at inf.ethz.ch
Thu Oct 25 19:53:24 CEST 2007
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
More information about the En-Nut-Discussion
mailing list