How printf() is calling up the UART driver

I am newbie to freertos, please help me understand how printf() is hooked/landed up to UART driver API. I have seen reference driver serial driver, in general serial drivers are implementing, XXXserialinit(), XXXserialgetchar(), XXXserialputchar(), XXXserialput_string() APIs. Could some please explain how printf() call flows to UART driver? Also please point me to reference driver.

How printf() is calling up the UART driver

If I’m not mistaken, this happens in printf-stdarg.c If snprintf() is called with NULL as as buffer, the function vOutputChar() will be called for every byte: ~~~~~ extern void vOutputChar( const char cChar, const TickType_t xTicksToWait ); /* here the logging function is called printk() (just like Linux). It calls print() with a NULL pointer: */ int printk(const char *format, …) { va_list args;
    va_start( args, format );
    return print( 0, format, args );
} ~~~~~ This function vOutputChar(), which should be provided by the application, shall forward the byte to a serial console or whatever. “printf-stdarg.c” never got a standard location in projects, you’ll find it in the home directory of many projects. The above method of logging is very economic: each byte formatted goes straight to the serial driver. You’ll get a smoother output when XXXserialput_string() is used for a whole string. Regards.

How printf() is calling up the UART driver

Low driver functions are interfacing this feature. standard output/input function stdput, STDget , this is function pointers , have to be set as serial driver functions uartput, uartget

How printf() is calling up the UART driver

Really this question falls outside the scope of FreeRTOS support as it is completely dependent on the development environment you are using – and FreeRTOS support more than 18. As per Radoslav’s comment – first you need the low level driver functions to perform outout to whichever interface you want (UART, CDC, TCP, etc.) so make sure that is working. Then you need to read the library section of the documentation for whichever development environment you are using to find out how you connect that to the libraries. Sometimes it is as easy as providing your won write() function that calls your low lever drivers, sometimes it is not that easy. As per Hein’s reply there is a file printf_stdarg.c that can be used, but this is not part of the kernel itself – just included in lots of different demos. If you choose that you can replace the sprintf/printf function provided by your library with a much simpler, leaner, and so also less powerful and slower version (the big advantage of is it uses very little stack) and follow Hein’s example. Regards.