cancel
Showing results for 
Search instead for 
Did you mean: 

How to use printf() to output to UART

gerhard
Associate II

I have been using printf() to output to UART for many years on a STM32L052

All these projects still compile and printf() to UART, no problem.

I started a NEW project with CubeMX, but now printf() does NOT print to UART.

I use the same int fputc(int ch, FILE *f) as in ALL the other projects, but still no UART output. (Plese see attached code)

I looked at other solutions, but they seem to be doing similar int fputc(int ch, FILE *f)

Any help appreciated

12 REPLIES 12

That is a very severely limited printf(). In case the full implementation with a reasonable resource usage is needed, I would recommend nanoprintf of LwPRINTF.

That is kind-of the point. This will work on stm32L053 with OS added. The others ... not so much; Also, this is more of an 'inspire' example to roll your own.

Of, course everything is OK if it solves some problem and fits the target. I also just reminded that Newlib's 12+ KB FLASH and 2+ KB RAM monster with a malloc() and global variables is not the only option of full implementations. The nanoprintf takes 1-3 KB of FLASH and does not use any heap or global variables - therefore it is completely reentrant. :)