ESP8266 SDK: os_printf() prints garbage, uart_init() doesn’t work…

by kacang bawang

Espressif SDK provides a function os_printf() for printing to the debug uart. However, when used out of the box it prints garbage. What gives?

Consider a default project with the following in user_main.c.

Compile, run, what do you see? That’s right – garbage. Well, it’s not really garbage, it’s actually outputting “hello world” at the default (non standard) baud rate. Ok, easy enough – we’ll just set the baud rate using uart_init() function from the SDK! Oh, wait… that function is not defined in any header that comes with the SDK… Paging Espressif, please pick up the white courtesy telephone!

That’s ok, there’s an easier way – we will use uart_div_modify() to achieve the same result. Change the hello world to this and try again:

Much better! Hat tip to unfoundbug at this reddit thread.