Debugging ESP8266 firmware with Olimex ARM-USB-OCD-H

This tutorial shows how to use the inexpensive Olimex ARM-USB-OCD-H adapter to debug ESP8266 firmware using VisualGDB and Visual Studio. Before you begin, install VisualGDB 5.0 or later.

Update: our latest ESP8266 toolchain includes an improved OpenOCD port for ESP8266 that is more stable than the xt-ocd tool described here. Please follow this tutorial for detailed instructions on using it.

  1. Setup your JTAG connection as described in the basic ESP8266 tutorial, however leave the reset pin unconnected:connectionIf you connect the reset pin, the ESP8266 GDB stub will not be able to recognize the core correctly and the debugging won’t work. In order to work around this bug, the reset should be left unconnected and the device should be reset manually (e.g. by plugging it out and back in) before each debugging session.
  2. Start Visual Studio and launch the VisualGDB Embedded Project Wizard:01-prjname
  3. Uncheck the “bin” checkbox to avoid generating an extra .bin file (ESP8266 debugging plugin will generate a set of .bin files automatically):02-elf
  4. Select the ESP8266 toolchain and the device from the list:03-toolchain
  5. In order to keep things simple while testing the JTAG functionality we will use the basic LEDBlink sample that does not involve any WiFi functionality: 04-sample
  6. On the last page of the wizard select the FT2232-based interface and pick the olimex-tiny-h layout:05-olimexdev
  7. The Xtensa OCD Daemon does not support the ARM-USB-OCD-H programmer, however it supports a similar olimex-tiny-h programmer, that has identical hardware, but a different ID. We will now show how to change the ID of the ARM-USB-OCD-H programmer to make it compatible with the Xtensa OCD Daemon. Download and launch USBDriverTool, connect your Olimex programmer and install the FTDI CDM driver for both interfaces:06-ftdrv
  8. Ensure that the driver is installed successfully for both interface 00 and 01:07-alldrv
  9. Download, install and launch FT_Prog. Then select “Scan and Parse” to populate the device list:08-ftprog
  10. We will now use FT_Prog to change the product ID of the Olimex USB-OCD-H device. Ensure that the vendor ID is set to 15BA and set the product ID to 002A:09-vidpid
  11. Click the “Program Devices” button:10-program
  12. Finally press the “Program” button to apply the changes:11-program-done
  13. Once the programming is complete, reconnect the device. As the ID has been changed, the drivers won’t be installed anymore: 12-driver
  14. Install the FTDI CDM driver for both interfaces and use the FT_Prog tool to find the serial number of the device:13-serialno
  15. Go back to VisualGDB Embedded Project Wizard and enter the serial number observed in FT_Prog. Also lower the speed to 3MHz:14-settings
  16. Press “Finish” to generate the project. Build it with Ctrl-Shift-B:15-build
  17. Now you can start debugging by pressing F5. Observe how VisualGDB programs the SPI FLASH:16-program
  18. Now you can try setting breakpoints in your code. If the debugging does not work, observe the xt-ocd output for information about the encountered problems. Note that the “Error opening probe … trying with ‘A’ suffix” message is normal:17-bkpt
  19. If you have connected the serial port on the ESP8266 device to the serial port of the Olimex ARM-USB-OCD-H like described in this tutorial, you need to install the USB serial port driver in order to view the output from the COM port. Locate the serial port in Device Manager:18-serport
  20. Check device properties to find the serial port corresponding to interface 01 (it will have &MI_01 at the end of the last hardware ID):19-mi01
  21. Start updating the drivers for that COM port and select “Let me pick a list of device drivers”:20-pickdrv
  22. Click “Have disk” and specify the FTDI CDM driver directory under the directory where you have extracted USBDriverTool:21-havedisk
  23. Select the USB Serial Port driver from the list: 22-serialport
  24. Finally go to VisualGDB Project Properties and enable the Raw Terminal on the newly installed COM port. Ensure you  specify the correct baud rate:23-terminal
  25. Once the Raw Terminal is enabled, you will see the output from the COM port inside Visual Studio once you start debugging. See this tutorial for an example of reading the output from the COM port.