Debugging ESP8266 / NodeMCU devices within VSCODE using cheap JTAG adapter


The subject says it all. I already have one of the eBay cheapies (like these )

Can they be used instead of the ESP-Prog boards for debugging ?


Interesting question. PlatformIO has no native support for JTAG debugging of an ESP8266, information and support for that has been sparse in the past. In theory, PlatformIO is able to use any program that is able to open a GDB server to the ESP8266.

I would suggest you try and compile GitHub - sysprogs/esp8266-openocd: A stable ESP8266 port of OpenOCD. (Working on Linux is the easiest way here). Once the openocd executable is created, you can to find the pinout for the debugger (“MX-AVR JTAG ICE”), e.g. here if I’m not mistaken.

Then you need to connect those to the JTAG pins of the ESP8266 (as listed in the datasheet with MTMS, MTDI, MTCK, MTDO, EXT_RSTB (as reset)). Pinouts are also posted here. Of course for that, your ESP8266 module has to expose all these internal pins.

Then you can try to connect to your chip with the needed configuration files. target/esp8266.cfg exists for the target and for the AVR JTAG ICE interface, accroding to this, the interface/cmsis-dap.cfg file may be used, so your total command would look something look openocd -s <path to script folder> -f interface/cmsis-dap.cfg -f target/esp8266.cfg . If that succeed and openocd is connected to the ESP8266 via the debugger interface, the hard part is done, and a openocd should open a GDB server at localhost port 4444.

If you’re at that stage, you can merge the work with the platformio.ini by specifying where the GDB server is located, using debug_tool (docs) and related commands.

debug_tool = custom
debug_port = localhost:4444
; if openocd fails to load the firmware to the target 
; -- upload normally via bootloader and enable the manual
; option which disables loading via openocd
;debug_load_mode = manual
debug_server =
  <script path>

and if all goes well, debugging should now be normaly callable.