Squash Your ESP-8266 Bugs With ESP-gdbstub

We hope we’re not insulting you by suggesting this, but it’s possible that even the best among us may be faced with bugs in our embedded code from time to time. And while we’re great fans of printf debugging over the serial port, and its high-speed equivalent — flipping a GPIO pin — there’s a time when your bug is so deep that having a real debugger is the best way to dig it out.

[slaff] has been doing some great work documenting C/C++ programming on the ESP-8266, mostly using Eclipse and some of the Arduino libraries. In the fourth part of his series of posts, he walks through using a couple debugger options for the ESP. What makes this all work is the ESP-gdbstub code from Espressif themselves. gdbstub looks great — it works both with the standard SDK as well as with FreeRTOS, so you can debug your ESP-8266 code whether it’s in an OS or on the bare metal. And all this just using the standard serial connection that’s used for programming.

Now, this still may not help with timing-related bugs. ESP-gdbstub uses the serial port, after all. But having the ability to set breakpoints and interactively inspect what’s going on in the chip’s memory is priceless, and doing so with no extra hardware connections is brilliant.

When the shat hits the fin, and you really need to JTAG up on your ESP, there’s also been a bunch of work recently on OpenOCD for the ESP-8266 target. In particular, this fork on GitHub has full support for breakpoints, interrupts, watchdog handling, and continuation. But for day-to-day debugging, it’s hard to beat the simplicity of gdbstub.

And if you just want to see what all this debugging hubbub is about, check out our own [Mike Szczys]’s great video demo of using OCD to fix a problem in his snake code.

14 thoughts on “Squash Your ESP-8266 Bugs With ESP-gdbstub

    1. The hardware debug from OpenOCD is good news. It uses up a lot of I/O, but it is the last resort when the software approach won’t help you. Good to have both alternatives.

      This part is looking better and better for the open source community.

      1. Thanks for the tip. I had missed the RST (though I figured it’d be internally pulled up). Still though, no joy. I get it to boot up properly maybe one out of ten times I disconnect and re-connect power. I think my module is simply bugged out.

  1. Same here, bought a few ESP01 from AliExpress, and leave them on. After a few hours or days, the module state looks like it was a reset in the meantime. No firmware upgrade or power supply could fix the random reset. All the ESP modules have the same issue.

    Can anybody please report if an ESP8266 can work reliably for a whole week or so? I start to doubt this is possible at all.


  2. I’ve quite a few of these running for months without a glitch. The key is to provide sufficient power, lets say 300mA at least. I’m placing ~470uF caps for peace of mind too. Next is to ensure your software id free of memory leaks

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.