Quality RTOS & Embedded Software

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




Loading

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.

Regards.


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.

Regards.


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




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS