retarget printf to uart?

Jesper Vestergaard openocd@jespervestergaard.dk
Thu May 28 08:39:00 GMT 2009


Hi Creaig

The newline trick did its magic.
Thanks a bunch. I have used quite a long time with this problem.

Regards Jesper

Howland Craig D (Craig) wrote:
> Jesper:
>      stdout is line buffered by default, so printing to the output
> device does not happen until either a newline is put into the buffer
> or fflush() is called.  So try printf("testing\n"), instead.  (Unlike
> a hosted application on your PC, which flushes all streams on exit,
> your embedded application likely never exits, and therefore never calls
> the hidden flush that happens on the hosted version.)
>      In the unlikely case that that is not the problem, take a look at
> the Syscalls section Newlib documentation, either
> ftp://sources.redhat.com/pub/newlib/libc.pdf or
> http://sourceware.org/newlib/libc.html#Syscalls, which tells you what
> you need to provide to connect to a system.  Specifically, it calls for
> write() to be provided.  (_write_r() calls write().  But _write_r()
> might not ever be called, itself, depending upon the exact configuration
> with which Newlib was built, as some configurations call write() from
> printf().)  Providing write() instead of _write_r() is likely to fix
> the problem if adding the newline did not.
> 				Craig
>
> -----Original Message-----
> From: newlib-owner@sourceware.org [mailto:newlib-owner@sourceware.org]
> On Behalf Of Jesper Vestergaard
> Sent: Wednesday, May 27, 2009 10:14 AM
> To: newlib@sources.redhat.com
> Cc: rurality.wq@gmail.com
> Subject: Re: retarget printf to uart?
>
> Jesper Vestergaard wrote:
>   
>> Hi guys
>>
>> I have been trying to retarget the printf in newlib so i can use it on
>>     
>
>   
>> a Icnova / Grasshopper avr32 board. I use the avr32 toolchain which 
>> uses newlib 1.16.0.
>>
>> I have read on a forum that i must implement _write_r in my code so 
>> that i use the uart but it doesn't work. How do i proper retarget the 
>> printf?
>>
>> Best regards
>> Jesper
>>
>>
>>     
> Btw i'm using FreeRTOS which i guess should be treated as a standalone 
> application.
>
> Here's a snip of the code i have tried:
>
> int putchar2(int c)
> {
>   return usart_putchar(&AVR32_USART1,c);
> }
>
>
> int _write_r(void *reent, int fd, char *ptr, size_t len)
> {
>
>     size_t i;
>
>     for (i=0; i<len; i++)
>
>     {
>
>         putchar2( ptr[i]);
>
>     }
>
>     return len;
>
> }
>
>
> int main(void)
> {
> printf("testing");
> }
>
>
>
>   



More information about the Newlib mailing list