# Directing the printf stream

**URL:** <https://forums.freertos.org/t/directing-the-printf-stream/5349>\
**Category:** Kernel\
**Created:** [April 14, 2008, 4:51pm UTC](https://forums.freertos.org/t/directing-the-printf-stream/5349 "2008-04-14T16:51:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 14, 2008, 4:51pm UTC](https://forums.freertos.org/t/directing-the-printf-stream/5349/1 "2008-04-14T16:51:49Z")

</div>

**[billy\_rafferty](https://sourceforge.net/u/billy_rafferty/)** wrote on [Monday, April 14, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/ee535333/#422f):

Hi there,

This is probably a very silly question, but I have been unable to figure it out.

I am using the ARM7\_AT91SAM7X256\_Eclipse demo and I want to use simple printf statements to help me debug my program.&nbsp; How can I use the printf function it to write to one of the serial ports?&nbsp; Must I write my own implantation of putchar() etc to implement this functionality, or has this low level stuff been included with the OS?

Many thanks,

Billy

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 15, 2008, 2:03am UTC](https://forums.freertos.org/t/directing-the-printf-stream/5349/2 "2008-04-15T02:03:40Z")

</div>

**[mmeade](https://sourceforge.net/u/mmeade/)** wrote on [Tuesday, April 15, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/ee535333/#422f/5e6a):

[http://www.arm.com/support/faqdev/3824.html](http://www.arm.com/support/faqdev/3824.html)

Take a look at “retarget.c”… I was able to use this file to get stdio printf’s to the debug serial port.

You need to implement two functions:

char UART\_read(void);  
void UART\_write(char);

My implementation looks something like this:  
/\*-----------------------------------------------------------\*/  
void UART\_write(char x)  
{  
&nbsp;&nbsp; xSerialPutChar( debugComPortHandle, x, mainUART\_BLOCK\_TIME );  
}

/\*-----------------------------------------------------------\*/  
char UART\_read(void)  
{  
&nbsp;&nbsp; signed portCHAR rx;

&nbsp;&nbsp; if ( xSerialGetChar( debugComPortHandle, &rx, mainUART\_BLOCK\_TIME ) == pdTRUE )  
&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return rx;&nbsp;&nbsp;  
&nbsp;&nbsp; }  
&nbsp;&nbsp; else  
&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return NULL;&nbsp;&nbsp;  
&nbsp;&nbsp; }  
}

where "debugComPortHandle" is initialized as follows:

&nbsp;&nbsp; debugComPortHandle = xSerialPortInitMinimal( 115200, 100 );

This worked for me, but it was compiled using the latest Keil toolchain.&nbsp; I’m not sure if it will work with the Eclipse demo, but hopefully this points you in the right direction.

– Mark

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 16, 2008, 2:27pm UTC](https://forums.freertos.org/t/directing-the-printf-stream/5349/3 "2008-04-16T14:27:01Z")

</div>

**[billy\_rafferty](https://sourceforge.net/u/billy_rafferty/)** wrote on [Wednesday, April 16, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/ee535333/#422f/5e6a/ec02):

Hi Mark,

I had a strange feeling I was going to have to implent a few functions.

Many thanks for the advice.

Cheers,

Billy

---

<div class="post-metadata">

**Author:** ![chaalar](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@chaalar](https://forums.freertos.org/u/chaalar)\
**Post date:** [April 16, 2008, 2:46pm UTC](https://forums.freertos.org/t/directing-the-printf-stream/5349/4 "2008-04-16T14:46:53Z")

</div>

**[chaalar](https://sourceforge.net/u/chaalar/)** wrote on [Wednesday, April 16, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/ee535333/#422f/bc2f):

For gcc you need to modify syscalls.c file and call your serial write/send routine there. I guess  
you know this already 🙂

Another possibility is to use sprintf instead printf in your debug macros. Then you can send  
that buffer via your serial,usb,ethernet,etc “send” functions, at least this is what I’m doing  
now. Just in case…

Regards,  
Caglar
