printf using printf-stdarg.c

roujesky wrote on Friday, August 01, 2014:

I had this working on an old mplab8 project running FreeRTOS. But I have a brand new project running the latest version of FreeRTOS on a PIC32MX795. Now, tho, when i call printf, it goes straight to this function in printf-stdarg.c

/* To keep linker happy. /
int write( int i, char
c, int n)
{
return 0;
}

what am I doing wrong? Like I said, this worked for me years ago. I should see it stepping thru all the functions in printf-stdarg.c…

thanks!

rtel wrote on Saturday, August 02, 2014:

printf-stdarg.c contains an extremely light weight version of some of the stdio functions. It is a useful way of keeping the code size of GCC built programs (XC32 is GCC by another name) down as bringing in a lot of GCC libraries can really bloat code and massively increase your stack usage. In printf-stdarg.c you can direct the output of printf() wherever you like (UART, console, USB CDC etc.) or just provide a dummy write() function if you are not actually going to use printf() at all.

If the libraries that come with your compiler (presumably XC32) come with an implementation of write() that does what you want then you can simply remove printf-stdarg.c from the project all together - if you do that I would strongly suggest you have stack overflow checking turned on in FreeRTOSConfig.h.

Regards.

bowerymarc wrote on Saturday, August 02, 2014:

You need to implement the actual output function yourself, or use sprintf and deal with the resultant char array.
So overload write(). Your old project probably did that somewhere.

roujesky wrote on Sunday, August 03, 2014:

thanks! I will implement the necessary code in write().