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

Dusan Ferbas dferbas at etech.cz
Fri Oct 26 23:42:38 CEST 2007


Hi Matthias,

have you tried following ?

         FILE *uart0;
         u_long baud = 115200;
         u_long flags = USART_MF_HALFDUPLEX;

         NutRegisterDevice(&devUsartAvr0, 0, 0);

         uart0 = fopen("uart0", "r+b");          //select binary mode
         _ioctl(_fileno(uart0), UART_SETFLOWCONTROL, &flags);    /* 
due to bug in Nut/OS 3.5.0 do this BEFORE SETSPEED */
         _ioctl(_fileno(uart0), UART_SETSPEED, &baud);

         stdout = stdin = uart0;                 //looks magic, doesn't it ?

Dusan

At 21:35 25.10.2007, you wrote:
>From: Matthias Ringwald <mringwal at inf.ethz.ch>
>To: "Ethernut User Chat (English)" <en-nut-discussion at egnite.de>
>Date: Thu, 25 Oct 2007 19:53:24 +0200
>
>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.


Dusan Ferbas
www.etech.cz 




More information about the En-Nut-Discussion mailing list