Redirecting printf

paulgcoleman wrote on Friday, May 11, 2012:

Is there an easy way to redirect printf? I’m using the Atmel AVR32 port and it would be nice if I could redirect printf to one of three USARTS, so maybe fprintf with something like…
fprintf(USART_1, “text”);
fprintf(USART_2, “text”);
fprintf(USART_3, “text”);
would be good. However, I’m not sure what I need to modify to accomplish this. Has anybody achieved something similar?

Thanks, Paul.

rtel wrote on Friday, May 11, 2012:

Normally you can implement the low level byte in and byte out functions any way you like, so send them to any device you like.  How this is done is dependent on your compiler, or, more specifically, the libraries provided with your compiler.  Most embedded environments are set up to make it easy to do, and I think the Atmel provided example applications actually are already configured to send printf() output to a UART.

I think you can also implement the low level functions in the low overhead io file being discussed in your other thread this morning.

Regards.

paulgcoleman wrote on Friday, May 11, 2012:

Thanks for the info. After my previous thread I then thought that I could achieve what I wanted by redirecting printf().

I was hoping that fprintf() called down to the _write() function contained in the portable section of FreeRTOS but this doesn’t seem to be the case. This would have been easy as the first parameter to _write() is the file descriptor which I could have checked and then diverted the output accordingly. So, if _write() is not called by fprintf() what does it get called by?

Thanks, Paul.