This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: retarget printf to uart?


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"); }





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]