Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


How printf() is calling up the UART driver

Posted by shariffmd on December 25, 2014

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

Posted by heinbali01 on December 25, 2014

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.


How printf() is calling up the UART driver

Posted by jradoslav on December 26, 2014

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

Posted by rtel on December 26, 2014

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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists