{"id":852,"date":"2015-10-14T11:52:36","date_gmt":"2015-10-14T18:52:36","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=852"},"modified":"2017-05-26T10:30:39","modified_gmt":"2017-05-26T17:30:39","slug":"debugging-esp8266-firmware-with-the-uart-gdb-stub","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/esp8266\/gdbstub\/","title":{"rendered":"Debugging ESP8266 firmware with the UART GDB Stub"},"content":{"rendered":"<p>This tutorial shows how to debug the ESP8266 firmware using the UART GDB stub provided by Espressif without any JTAG hardware.<\/p>\n<p>Before you begin, connect the TXD and RXD signals on your ESP8266 board to a USB-to-UART circuit, however the RXD and TXD signals on the Olimex board have levels of 0 to 3.3V and connecting them to a normal UART signals without a <a href=\"http:\/\/datasheets.maximintegrated.com\/en\/ds\/MAX200-MAX213.pdf\">level shifter<\/a> could damage the ESP8266. On the Olimex ESP8266 module the RXD and TXD signals are available on pins 4 and 3 on the MOD-WIFI-ESP8266-DEV module and on pins 4 and 3 on the UEXT connector on the ESP8266-EVB board: <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/00-conn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-853\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/00-conn.png\" alt=\"00-conn\" width=\"1112\" height=\"382\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/00-conn.png 1112w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/00-conn-300x103.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/00-conn-1024x352.png 1024w\" sizes=\"(max-width: 1112px) 100vw, 1112px\" \/><\/a>Once the connection is established, follow the steps below to build and debug a simple HTTP server:<\/p>\n<ol>\n<li>Start Visual Studio and launch the VisualGDB Embedded project Wizard:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-embprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-854\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-embprj.png\" alt=\"01-embprj\" width=\"800\" height=\"474\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-embprj.png 800w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/01-embprj-300x178.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/li>\n<li>On the first page uncheck the &#8220;bin&#8221; checkbox as the ESP8266 projects use their own binary format:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/02-nobin.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-855\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/02-nobin.png\" alt=\"02-nobin\" width=\"702\" height=\"571\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/02-nobin.png 702w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/02-nobin-300x244.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><\/li>\n<li>On the next page select the ESP8266 toolchain, the normal ESP8266 device and enable the UART GDB stub. If the GDB stub checkbox is not shown, install the latest version of the toolchain via VisualGDB Embedded Tools Manager or directly from <a href=\"http:\/\/gnutoolchains.com\/esp8266\/\">gnutoolchains.com<\/a>:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/03-devstub.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-856\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/03-devstub.png\" alt=\"03-devstub\" width=\"702\" height=\"571\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/03-devstub.png 702w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/03-devstub-300x244.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><strong>If the &#8220;Enable UART GDB Stub&#8221; checkbox it not displayed, please update your ESP8266 toolchain via Tools-&gt;Embedded Tools Manager.<\/strong><\/li>\n<li>Select the HTTP Server (RTOS SDK) sample. As the on-board LED is multiplexed with the TxD signal used by the GDB stub to communicate to GDB, it won&#8217;t be possible to debug the LEDBlink samples with the stub:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/04-http.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-857\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/04-http.png\" alt=\"04-http\" width=\"702\" height=\"571\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/04-http.png 702w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/04-http-300x244.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><\/li>\n<li>On the Debug Method page select &#8220;Bootloader + GDB Stub&#8221; and specify the COM port number where the ESP8266 UART is connected. As uploading the image over UART takes longer than over JTAG, you can select &#8220;Program SPI FLASH only if changed&#8221; to skip re-uploading it when the project is not changed. However if you program a different project into your ESP8266, VisualGDB won&#8217;t detect it and will still skip uploading until you change the project or switch back to &#8220;Program Always&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/05-stub.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-858\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/05-stub.png\" alt=\"05-stub\" width=\"702\" height=\"571\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/05-stub.png 702w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/05-stub-300x244.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><\/li>\n<li>Press Finish to create the project and build it with Ctrl-Shift-B:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-859\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-build.png\" alt=\"06-build\" width=\"699\" height=\"664\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-build.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/06-build-300x285.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>Set a breakpoint somewhere in the user_init() function after the call to gdbstub_inif() and press F5 to start debugging. VisualGDB will ask you to boot the ESP8266 board into the bootloader mode:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-load.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-860\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/07-bootldr.png\" alt=\"07-bootldr\" width=\"699\" height=\"662\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/07-bootldr.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/07-bootldr-300x284.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>On the Olimex board this is done by holding the bootloader button, unplugging the power connector and plugging it back:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/reset.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-864\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/reset.jpg\" alt=\"reset\" width=\"700\" height=\"422\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/reset.jpg 700w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/reset-300x181.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/a><\/li>\n<li>Once you boot the board into the bootloader mode, press OK. VisualGDB will start uploading the image:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-load.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-861\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-load.png\" alt=\"08-load\" width=\"699\" height=\"665\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-load.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/08-load-300x285.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>When the upload is complete, the program will automatically start and your breakpoint will be hit:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-862\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-bkpt.png\" alt=\"09-bkpt\" width=\"699\" height=\"663\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-bkpt.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/09-bkpt-300x285.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>You can step through the code normally and use tools like Watch and Call Stack to explore the state of your program:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-eval.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-863\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-eval.png\" alt=\"10-eval\" width=\"699\" height=\"663\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-eval.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/10-eval-300x285.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a>Follow <a href=\"http:\/\/visualgdb.com\/tutorials\/esp8266\/relay\/\">this tutorial<\/a> for an example of controlling a relay on the Olimex ESP8266 evaluation board. Note that as the GDB stub is using the pin that is multiplexed with the LED pin, trying to control the LED manually will disrupt the GDB stub communication. The relay uses a different pin and should not interfere with the GDB stub.<\/li>\n<li>You can use VisualGDB project properties to enable\/disable and configure the GDB stub:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-config.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-865\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-config.png\" alt=\"11-config\" width=\"863\" height=\"752\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-config.png 863w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/09\/11-config-300x261.png 300w\" sizes=\"(max-width: 863px) 100vw, 863px\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug the ESP8266 firmware using the UART GDB stub provided by Espressif without any JTAG<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[142],"tags":[100,101,56,70],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/852"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=852"}],"version-history":[{"count":3,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/852\/revisions"}],"predecessor-version":[{"id":1161,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/852\/revisions\/1161"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}