ESP32 JTAG debugging with PlatformIO and only one USB connection
I've been working with the ESP32 microcontroller for a few weeks now. As a development environment I use Visual Studio Code with the PlatformIO extension. In the meantime, however, the programs are becoming more and more complex and at some point there comes the moment where pure logging to the console is no longer sufficient for debugging. But in order to be able to do real hardware debugging with the ESP32, you need a so-called JTAG debugger.
I chose the Espressif ESP Prog Board. You can get that from AliExpress for around 17 euros. There are numerous instructions on the web on how to connect the ESP-Prog board to the ESP32 board and which drivers are required on the PC. However, these instructions all assume that the ESP32 is also connected to the PC via USB. Debugger and ESP32 occupy two USB ports, the JTAG and the program interface. However, the latter is not absolutely necessary. Therefore the ESP32 board must be connected to the ESP-Prog board via 6 lines:
In addition, the voltage must be set on the ESP-Prog Board. Since I have connected other components to the ESP32, some of which require a voltage of 5V, I set the board to 5V and connected the line to the 5V pin of the ESP32 accordingly.
Now PlatformIO only has to be configured so that the debugger uses the JTAG interface to upload the program code. To do this, the platform.ini file is adapted as follows:
[env:esp32dev] platform = espressif32 board = esp32dev framework = espidf ;monitor_port = COM3 ;monitor_speed = 115200 ; Verbose build_flags = -DCORE_DEBUG_LEVEL=5 ; Debug debug_tool = esp-prog ; Set optimization level and amount of debug information generated by the compiler debug_build_flags = -O0 -ggdb3 -g3 upload_protocol = esp-prog upload_speed = 921600 upload_port = COM6
The last three lines ensure that PlatformIO no longer uses the program interface for the upload, but the JTAG interface. The configuration for the monitor is no longer necessary.
With this setup, only one USB interface is required for development and debugging. Unfortunately, this solution also has a catch. Since the program interface is no longer available, the log files are no longer output. The Espressif tools such as esptool.py also no longer work for the same reason, since they only work via the program interface and the associated serial port.