r/esp8266•
getout

Question on serial debugging

Hi folks,

I'm new to esp8266 firmware programming. I'm trying to start off by writing simple programs.

I'm using ubuntu linux with the esp-open-sdk. I can compile and flash simple programs (like blink) but I'm really stumped with printing debugging info to the console via the os_printf() function.

I have a simple user_init() function which includes two function calls.

  1. uart_init(115200,115200);
  2. os_printf("hello world");

I am expecting to see "hello world" printed on /dev/ttyUSB0 when I use the command "cat /dev/ttyUSB0".

I've already used stty to setup the serial port. I have it setup as such: "stty -F /dev/ttyUSB0 raw" and "stty -F /dev/ttyUSB0 115200".

I have my esp8266 wired properly to a ftdi usb to serial converter. Any ideas on what is going on?

Posted Apr 28, 2015, 3:30 AM UTC

49
luffintlimme•

If you want to use os_printf(), you're going to have to ask Espressif why it doesn't work. (Its their BS closed library.)

I just moved on and use uart_sendStr() (found it from some other websites.)

And currently, I've moved on to Arduino/esp8266. (Because "higher level" C libraries are nice, this also lets me call lower level direct esp8266 functions when needed.)

2
getoutOP•

Thanks for the reply. What library did you find uart_sendStr()?Couldn't find it anywhere.

Thanks.

1
luffintlimme•

I wouldn't bother. Arduino esp8266 ftw. https://github.com/esp8266/Arduino

2
unfoundbug•

I use this in the start of my initialisation routine, I have had no issues at all with it

uart_div_modify(0, UART_CLK_FREQ / 115200); os_printf("Hello!\n\r");

Not sure where that uart_init() is defined, as I don't have access to my codebase at the moment to see why it isnt working

1
getoutOP•

Thanks for the reply. I tried your code and it 'kind of' works.

My serial output does include "Hello!" however it also contains a line of gibberish characters. Any idea on that?

1
unfoundbug•

If its on powerup, thats the SDK itself, it dumps out a load of system information at a default baudrate when you startup

1
getoutOP•

Yeah. I'm seeing that now.

Any call to os_printf inside of the user_init() has a bit of garbage.

All of my os_printf() calls that are put in tasks and timer function callbacks work perfectly though.

Thanks a lot.

BTW, any idea on how to disable the default debug information that the esp spits out?

1
unfoundbug•

Not a clue unfortunately, the SDK is a set of closed libraries, unless we get the source code to build it there's not much that can be done.

1
matthew-james•

I had all sorts of trouble getting serial debugging working. I just uploaded a simple example here of what ended up working.

Basically, I ended up using ets_uart_printf. However, that doesn't work unless you add extern int ets_uart_printf(const char *fmt, ...) at the beginning of the file.

I found the info about the second bit in the comments at Peter Scargill's blog.

1