Directing the printf stream

billy_rafferty wrote on Monday, April 14, 2008:

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.  How can I use the printf function it to write to one of the serial ports?  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,


mmeade wrote on Tuesday, April 15, 2008:

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)
   xSerialPutChar( debugComPortHandle, x, mainUART_BLOCK_TIME );

char UART_read(void)
   signed portCHAR rx;

   if ( xSerialGetChar( debugComPortHandle, &rx, mainUART_BLOCK_TIME ) == pdTRUE )
      return rx;  
      return NULL;  

where "debugComPortHandle" is initialized as follows:

   debugComPortHandle = xSerialPortInitMinimal( 115200, 100 );

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

– Mark

billy_rafferty wrote on Wednesday, April 16, 2008:

Hi Mark,

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

Many thanks for the advice.



chaalar wrote on Wednesday, April 16, 2008:

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

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…