Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: can't get printf() to print on UART0 with GNU

2005-02-24 by ntfreak2000

--- In lpc2000@yahoogroups.com, "tiogate" <gate@t...> wrote:
> 
> Hello, gentlemen,
> 
>    I am experiencing something that does not make sense to me. To 
> make my debugging easier I wish to use the printf function to send 
> formatted output to UARTO. 
> 
>    Fine. As far as I can see, I did everything right: I rewrote the 
> putchar function so it writes to UART0, and the putchar function 
> works OK. 
> 
>    However, when I use the printf function, it does not output to 
> UART0 (if it outputs to something at all), and I can't understand 
> why not.
> 
>    Checking the .MAP file, I see the compiler takes the putchar 
> function that is in my main.o and the remaining functions that 
> printf uses (such as puts, fflush, etc) it takes from libc.a .
> 
>    If I DO NOT write my putchar, I see from the .MAP file that the 
> compiler takes putchar.o from libc.a -- and then I understand why 
it 
> wouldn't send anything to the UART0. But why doesn't printf send to 
> the UART0 if my putchar function tells it to?
> 
> Hoping for some enlightening from you gurus,
> 
> Fernando

All depends on what c library you are using, with  newlib you need to 
override _write or _write_r (reentrant version) eg.

int _write_r(void *reent, int fd, char *ptr, size_t len)
{
   // send data via uart
   UART_DataSend( UART0, ptr, len );
   return len;
}

unlike other c libs newlib does not use putchar.
Look in the newlib docs for other system overdides.

Regards
Spen

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.