October 17, 2026

First experiences with STM32 CubeMX -- printf

Printf does work, and output appears on the virtual serial port that is set up by the ST-Link gadget that is part of my H743 Nucleo board.

But there are weird issues. Each line needs to be terminated not just by "\n", but by "\n\r" -- which is bizarre. And even then, the output does not act like I am used to -- the cursor is left dangling below the end of the last line as it the "\r" was ignored.

This should be fixed by someone. I looked into it, but it turns out that printf is being supplied by a combination of compiler builtin handling and some version of glibc. This is a peculiar arrangement for embedded software. I have always used the -fno-builtin argument to gcc and have supplied my own printf, puts, and so forth.

At some point the compiler infrastructure just described must call some kind of serial-putchar type function in a H743 specific driver. I have not yet tracked that down, and it is tricky to do so given that the call stack vanishes into glibc, but I may get back to it someday. Hopefully the need the append a "\r" to every '\n' can be handled at the basic driver level -- as it should be.


Have any comments? Questions? Drop me a line!

Tom's software pages / tom@mmto.org