{"id":2761,"date":"2017-05-30T01:07:35","date_gmt":"2017-05-30T08:07:35","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=2761"},"modified":"2017-05-30T01:07:35","modified_gmt":"2017-05-30T08:07:35","slug":"debugging-nodemcu-firmware-over-jtag","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/esp8266\/nodemcu\/jtag\/","title":{"rendered":"Debugging NodeMCU Firmware over JTAG"},"content":{"rendered":"<p>This tutorial shows how to debug ESP8266 firmware running on your NodeMCU board using JTAG. We will show how to setup the necessary connections and configure the software to automatically program the FLASH memory and debug the firmware.<\/p>\n<p>In this tutorial we will use the Olimex ARM-USB-OCD-H JTAG debugger. Other JTAG debuggers may work as well, however they may need slightly different configuration.<\/p>\n<p>Before you begin, install VisualGDB 5.2 or later.<\/p>\n<ol>\n<li>The first step will be to connect the JTAG pins of the ESP8266 chip on the NodeMCU to your JTAG debugger. The relevant pins are VCC, GND, TDI, TDO, TMS, TCK and RESET. For NodeMCU v1, they should be connected as follows (see <a href=\"https:\/\/raw.githubusercontent.com\/nodemcu\/nodemcu-devkit\/master\/Documents\/NODEMCU_DEVKIT_SCH.png\">NodeMCU schematic<\/a> and <a href=\"https:\/\/mintbox.in\/media\/esp-12e.pdf\">ESP-12 schematic<\/a>):<br \/>\n<table>\n<tbody>\n<tr>\n<td>ESP8266 Signal<\/td>\n<td>ESP8266 Pin<\/td>\n<td>NodeMCU Signal<\/td>\n<td>NodeMCU Pin<\/td>\n<td>JTAG20 Signal<\/td>\n<td>JTAG20 Pin<\/td>\n<\/tr>\n<tr>\n<td>VDDPST<\/td>\n<td>17<\/td>\n<td>VDD3V<\/td>\n<td>1 on J2<\/td>\n<td>VDD<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>VDD<\/td>\n<td>PAD<\/td>\n<td>GND<\/td>\n<td>2 on J2<\/td>\n<td>GND<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>MTDI<\/td>\n<td>10<\/td>\n<td>GPIO12<\/td>\n<td>7 on J2<\/td>\n<td>TDI<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<td>MTMS<\/td>\n<td>9<\/td>\n<td>GPIO14<\/td>\n<td>8 on J2<\/td>\n<td>TMS<\/td>\n<td>7<\/td>\n<\/tr>\n<tr>\n<td>MTCK<\/td>\n<td>12<\/td>\n<td>GPIO13<\/td>\n<td>6 on J2<\/td>\n<td>TCK<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>MTDO<\/td>\n<td>13<\/td>\n<td>GPIO15<\/td>\n<td>5 on J2<\/td>\n<td>TDO<\/td>\n<td>13<\/td>\n<\/tr>\n<tr>\n<td>EXT_RSTB<\/td>\n<td>32<\/td>\n<td>RST<\/td>\n<td>3 on J1<\/td>\n<td>nTRST or nSRST<\/td>\n<td>3 (Olimex) or 15 (Segger)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/pinout.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2771\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/pinout.jpg\" alt=\"pinout\" width=\"1200\" height=\"675\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/pinout.jpg 1200w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/pinout-300x169.jpg 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/pinout-1024x576.jpg 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/li>\n<li>Once you have connected all the pins, start Visual Studio and open the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-wizard.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2770\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-wizard.png\" alt=\"01-wizard\" width=\"941\" height=\"653\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-wizard.png 941w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-wizard-300x208.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-wizard-392x272.png 392w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-wizard-130x90.png 130w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/li>\n<li>Proceed with the default &#8220;Embedded binary&#8221; setting:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/02-emb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2769\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/02-emb.png\" alt=\"02-emb\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/02-emb.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/02-emb-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Select the ESP8266 toolchain and the regular ESP8266 device:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/03-device5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2768\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/03-device5.png\" alt=\"03-device\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/03-device5.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/03-device5-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>On the Sample Selection page choose &#8220;LEDBlink (RTOS SDK)&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/04-blink1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2767\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/04-blink1.png\" alt=\"04-blink\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/04-blink1.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/04-blink1-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>On the Debug Setings page choose OpenOCD. Then connect your NodeMCU and the JTAG debugger via USB and click &#8220;Detect&#8221; to automatically detect the interface:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/05-debug3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2766\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/05-debug3.png\" alt=\"05-debug\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/05-debug3.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/05-debug3-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Click &#8220;Test&#8221; to automatically test the connection between the JTAG debugger and NodeMCU:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2765\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-test.png\" alt=\"06-test\" width=\"649\" height=\"536\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-test.png 649w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-test-300x248.png 300w\" sizes=\"(max-width: 649px) 100vw, 649px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to generate your project. On NodeMCU the LED is connected to the special GPIO16 pin that is controlled differently from regular GPIO, so replace user_init() and LEDBlinkTask() with the following code:\n<pre class=\"\">static void RAMFUNC LEDBlinkTask(void *pvParameters)\r\n{\r\n\u00a0\u00a0 \u00a0for (int tick = 0;;tick++)\r\n\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0vTaskDelay(300 \/ portTICK_RATE_MS);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0gpio16_output_set(1);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0vTaskDelay(300 \/ portTICK_RATE_MS);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0gpio16_output_set(0);\r\n\u00a0\u00a0 \u00a0}\r\n}\r\n\r\nvoid RAMFUNC user_init(void) \u00a0\r\n{\r\n\u00a0\u00a0\u00a0 gpio16_output_conf();\r\n\r\n\u00a0\u00a0 \u00a0xTaskCreate(LEDBlinkTask, (signed char *)\"LEDBlinkTask\", 256, NULL, 2, NULL);\r\n}<\/pre>\n<\/li>\n<li>Press Ctrl-Shift-B to build your project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-build1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2764\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-build1.png\" alt=\"07-build\" width=\"1008\" height=\"692\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-build1.png 1008w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-build1-300x206.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-build1-130x90.png 130w\" sizes=\"(max-width: 1008px) 100vw, 1008px\" \/><\/a><\/li>\n<li>Now press F5 to start debugging. The blue LED on NodeMCU should begin blinking:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/jtag.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2772\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/jtag.jpg\" alt=\"jtag\" width=\"700\" height=\"421\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/jtag.jpg 700w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/jtag-300x180.jpg 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/a><\/li>\n<li>Set a breakpoint in the LEDBlinkTask and ensure it hits:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-stop.png\"> <img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2763\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-stop.png\" alt=\"08-stop\" width=\"1008\" height=\"692\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-stop.png 1008w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-stop-300x206.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-stop-130x90.png 130w\" sizes=\"(max-width: 1008px) 100vw, 1008px\" \/><\/a><\/li>\n<li>If the LED does not start blinking after programming, try experimenting with the &#8220;Reset mode&#8221; setting in VisualGDB Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-reset.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2762\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-reset.png\" alt=\"09-reset\" width=\"1043\" height=\"822\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-reset.png 1043w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-reset-300x236.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-reset-1024x807.png 1024w\" sizes=\"(max-width: 1043px) 100vw, 1043px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to debug ESP8266 firmware running on your NodeMCU board using JTAG. We will show how to<\/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,143],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2761"}],"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=2761"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2761\/revisions"}],"predecessor-version":[{"id":2773,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2761\/revisions\/2773"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=2761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=2761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=2761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}