[En-Nut-Discussion] Multiple UART support

Ulrich Prinz uprinz2 at netscape.net
Tue Sep 21 20:32:55 CEST 2010


Hi Steve,

for me it is exactly sa easy as this:
 >      nr = NutRegisterDevice(&DEV_DEBUG, 0, 0);
 >      freopen(DEV_DEBUG_NAME, "w", stdout);
 >      _ioctl(_fileno(stdout), UART_SETSPEED,&baud);

for another uart just repeat that

/* don't forget this one:*/
FILE *uart0;
FILE *uart1;

rc = NutRegisterDevice( &DEV_USART0, 0, 0);
if( rc)
   something failed;
freopen(DEV_UART0.dev_name, "w", uart0);
_ioctl(_fileno(uart0), UART_SETSPEED,&baud);

rc = NutRegisterDevice( &DEV_USART1, 0, 0);
if( rc)
   something failed;
freopen(DEV_UART1.dev_name, "w", uart1);
_ioctl(_fileno(uart1), UART_SETSPEED,&baud);

In my stm32 port I use 3 or more UARTs in this way.
I haven't checked, if console is a reserved word by the libc or Nut/OS.

But you can put it another way:
Assign the debug to stderr and on of the other UARTs to stdout ( and 
stdin, if you use "r+" instead of "w"). You can reassign to by just do:
stdout = stdin = uart0;

Now printf() goes to uart0 while stderr still goes to dbgu and 12 points 
go to... ups :)

Ah, have a look into the uart example code. It just works fine.

Regards
Ulrich

Am 21.09.2010 18:15, schrieb zonedar:
>
> Hi,
>
>    We're using a AT91SAM7X256-EK in a product.  Currently we have the
> DEV_DEBUG working and assigned to stdio.  Getting lots of useful debug
> messages out to a terminal.
>
>    We'd like to enable a second UART (UART0) to allow us to communicate to an
> internal peripheral.  In the processes of bringing it up I was just going to
> try and set it up similar and have it also send stuff to a terminal.  It
> doesn't seem to be that easy.
>



More information about the En-Nut-Discussion mailing list