I’ve tried to reproduce your problem. But I was successful debugging and failed at reproducing with all projects I tried. So try the following things:
1. Check and recheck the wiring
It’s essential that TDI, TDO, TCK, TMS and GND are connected to the right pins and have a reliable connection. Furthermore, shorter cables are better (no more than 30cm).
2. Use the FT232H/ESP-Prog for upload
In platformio.ini
, add:
upload_protocol = esp-prog
This will quickly show if the JTAG connection works before the complex debug session starts. Furthermore, you can leave the serial monitor connected at all times as it is not needed for upload.
3. Lower the adapter speed
Try to lower the adapter speed by editing the file /Users/xxx/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/board/esp-wroom-32.cfg
and changing the value for adapter_khz
. The default value is 20000
(20MHz). Try 10000
or 5000
.
4. Use a matching board description
For your firmware, it’s important that you have 16MB of flash. For the debugger I’m not sure. I don’t know where it gets the memory layout information from. But try to use a matching board description anyway.
There are a few board descriptions in /Users/xxx/.platformio/platforms/espressif32/boards
for boards/modules with 16MB. If none fits, copy one of the .json files to /Users/xxx/.platformio/boards
and adapt it to your needs.
5. Connect the serial monitor before you start debugging
When you connect the serial monitor to the device, it will first reset it. That’s a problem during a debugging session. So connect it early.
I don’t know what serial monitor you are using. I find it convenient to use a program separate from Visual Studio Code.
6. Stop in app_main
Instead of the line shown in the Medium article, use:
debug_init_break = tbreak app_main
This tells the debugger to initially stop in the app_main
function. That’s the better choice for ESP-IDF but will probably not be the cause of the problem. (The article uses setup
instead which is preferred for use with the Arduino framework.)
Further observation
Many system cannot make reliable serial connections at 921,600 bps. Unfortunately, it’s the default for all ESP32 boards. I have to lower it to 460,800 as well.