vscode-esp-idf-extension: ESP32-C3-DevKitC-02 flash using Internal JTAG but debug fails (OCD-401) (VSC-740)

Environment

  • Development Kit: ESP32-C3-DevKitC-02
  • Module or chip used: ESP32-C3-WROOM-02
  • Debug Adapter: ESP32-C3 Internal JTAG
  • OpenOCD version: v0.10.0-esp32-20210721
  • Operating System: Windows 10
  • Using an IDE?: VS Code
  • ESP-IDF version: v4.3

Problem Description

Steps to reproduce the behavior:

  1. Build ESP-IDF blink example
  2. Flash and verify ESP32-C3 using Internal JTAG
  3. Disconnect Internal JTAG and verify blink running using devkit COM port.
  4. Disconnect COM port, reconnect internal JTAG and use F5 to start debug.
  5. Debug fails with VS Code connection refusal message: connect ECONNREFUSED 127.0.0.1:43474

Debug Logs

OpenOCD log:

Open On-Chip Debugger  v0.10.0-esp32-20210721 (2021-07-21-13:35)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Warn : Transport "jtag" was already selected
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 40000 kHz
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : datacount=2 progbufsize=16
Info : Examined RISC-V core; found 1 harts
Info :  hart 0: XLEN=32, misa=0x40101104
Info : Listening on port 3333 for gdb connections

Terminal log:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS D:\Dropbox\DATA\DEVELOPMENT\ESP32C3\blink> C:\Users\nicol\.espressif\python_env\idf4.3_py3.8_env\Scripts\python.exe C:\Users\nicol\esp\esp-idf\tools\idf.py -p COM9 monitor
Executing action: monitor
Running idf_monitor in directory d:\dropbox\data\development\esp32c3\blink
Executing "C:\Users\nicol\.espressif\python_env\idf4.3_py3.8_env\Scripts\python.exe C:\Users\nicol\esp\esp-idf\tools/idf_monitor.py -p COM9 -b 115200 --toolchain-prefix riscv32-esp-elf- --decode-panic backt
d:\dropbox\data\development\esp32c3\blink\build\blink.elf -m 'C:\Users\nicol\.espressif\python_env\idf4.3_py3.8_env\Scripts\python.exe' 'C:\Users\nicol\esp\esp-idf\tools\idf.py' '-p' 'COM9'"...
--- WARNING: GDB cannot open serial ports accessed as COMx
--- Using \\.\COM9 instead...
--- idf_monitor on \\.\COM9 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x42005a5e
0x42005a5e: cpu_ll_waiti at C:/Users/nicol/esp/esp-idf/components/hal/esp32c3/include/hal/cpu_ll.h:156
 (inlined by) esp_pm_impl_waiti at C:/Users/nicol/esp/esp-idf/components/esp_pm/pm_impl.c:827

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x1778
load:0x403ce000,len:0x8d4
load:0x403d0000,len:0x293c
entry 0x403ce000
I (24) boot: ESP-IDF v4.3-dirty 2nd stage bootloader
I (24) boot: compile time 16:00:58
I (25) boot: chip revision: 3
I (27) boot.esp32c3: SPI Speed      : 80MHz
I (31) boot.esp32c3: SPI Mode       : DIO
I (36) boot.esp32c3: SPI Flash Size : 4MB
I (41) boot: Enabling RNG early entropy source...
I (46) boot: Partition Table:
I (50) boot: ## Label            Usage          Type ST Offset   Length
I (57) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (64) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (72) boot:  2 factory          factory app      00 00 00010000 00100000
I (79) boot: End of partition table
I (83) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=05fa8h ( 24488) map
I (96) esp_image: segment 1: paddr=00015fd0 vaddr=3fc89a00 size=01a90h (  6800) load
I (101) esp_image: segment 2: paddr=00017a68 vaddr=40380000 size=085b0h ( 34224) load
I (115) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=15b1ch ( 88860) map
I (131) esp_image: segment 4: paddr=00035b44 vaddr=403885b0 size=013a0h (  5024) load
I (132) esp_image: segment 5: paddr=00036eec vaddr=50000000 size=00010h (    16) load
I (140) boot: Loaded app from partition at offset 0x10000
I (143) boot: Disabling RNG early entropy source...
I (160) cpu_start: Pro cpu up.
I (172) cpu_start: Pro cpu start user code
I (172) cpu_start: cpu freq: 160000000
I (172) cpu_start: Application information:
I (175) cpu_start: Project name:     blink
I (207) cpu_start: App version:      1
I (207) cpu_start: Compile time:     Aug 29 2021 16:59:10
I (208) cpu_start: ELF file SHA256:  f3c5fe14c0f6c604...
I (214) cpu_start: ESP-IDF:          v4.3-dirty
I (219) heap_init: Initializing. RAM available for dynamic allocation:
I (226) heap_init: At 3FC8C2D0 len 00033D30 (207 KiB): DRAM
I (232) heap_init: At 3FCC0000 len 0001F060 (124 KiB): STACK/DRAM
I (239) heap_init: At 50000010 len 00001FF0 (7 KiB): RTCRAM

Debug launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "espidf",
      "name": "Launch",
      "request": "launch",
      "debugPort": 43474,
      "logLevel": 2,
      "mode": "manual",
      "skipVerifyAppBinBeforeDebug": false,
      "initGdbCommands": [
        "target remote :3333",
        "symbol-file D:/Dropbox/DATA/DEVELOPMENT/ESP32C3/blink/build/blink.elf",
        "mon reset halt",
        "flushregs",
        "thb app_main"
      ],
      "env": {
        "CUSTOM_ENV_VAR": "SOME_VALUE"
      }
    }
  ]
}

Expected behavior

Debugging of flashed program.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 34 (13 by maintainers)

Most upvoted comments

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "espidf",
      "name": "Launch",
      "request": "launch",
      "skipVerifyAppBinBeforeDebug": true
    }
  ]
}

The "skipVerifyAppBinBeforeDebug": true fix was reported a few days ago https://esp32.com/viewtopic.php?t=23190

Big thanks bro, I followed your tips, it works smoothly. it also resolved the invalid issue when restart the debug, the details are as below: JTAG_Buit-in_Reset_work_well

@brianignacio5 Bro, I think you need to do some modifies about debugging to clarifying the debug issue when using the following configuration:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "espidf",
      "name": "Launch",
      "request": "launch",
      "debugPort": 9998,
      "logLevel": 2,
      "mode": "manual",
      "skipVerifyAppBinBeforeDebug": false,
      "initGdbCommands": [
        "target remote :3333",
        "symbol-file F:/Project/blink/build/blink.elf",
        "mon reset halt",
        "flushregs",
        "thb app_main"
      ],
      "env": {
        "CUSTOM_ENV_VAR": "SOME_VALUE"
      }
    }
  ]
}

@NicolSpies Bro, regarding the monitor you mentioned, it is not mandatory when debugging, you can close it here as below:

image

Upgrading to latest ESP-IDF (Master branch, version 4.4) fixed the debugging problem using internal JTAG problem as reported. Debugging works as expected except the problem previously reported regarding the serial monitoring of ESP32c3 via the JTAG UART while debugging or running without debugging.

Upgrade was done by deleting the .espressif and esp-idf folders and reconfiguring the ESP-IDF extension in VS Code.

Appended more information here, I tried to return back from v0.10.0-esp32-20210721 to v0.10.0-esp32-20210401and type in the same commands you mentioned above with git(bash), not powershell(windows 10), it works well and can stop at app_main() , the details as follows:

  1. OpenOCD
PS F:\BLE_WIFI\Espressif\SDK\blink\blink> F:\Tools\Espressif\IDF_Tools\.espressif\tools\openocd-esp32\v0.10.0-esp32-20210401\openocd-esp32\bin\openocd.exe -f board/esp32c3-builtin.cfg -d3 -l oocd.log
Open On-Chip Debugger  v0.10.0-esp32-20210401 (2021-04-01-15:46)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
User : 13 4 options.c:57 configuration_output_handler(): debug_level: 3
User : 14 10 options.c:57 configuration_output_handler():
Debug: 15 17 command.c:143 script_debug(): command - log_output log_output oocd.log
  1. GDB
$ F:\\Tools\\Espressif\\IDF_Tools\\.espressif\\tools\\riscv32-esp-elf\\1.24.0.123_64eb9ff-8.4.0\\riscv32-esp-elf\\bin\\riscv32-esp-elf-gdb.exe -x gdbinit build/blink.elf
GNU gdb (crosstool-NG 1.24.0.123_64eb9ff) 8.3.1.20191211-git

Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from build/blink.elf...
app_main () at ../main/blink.c:74
74          configure_led();
JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Hardware assisted breakpoint 1 at 0x420059fc: file ../main/blink.c, line 74.

Thread 2 hit Temporary breakpoint 1, app_main () at ../main/blink.c:74
74          configure_led();
(gdb)

However, it still cannot work when using the esp-idf-extension even if using the v0.10.0-esp32-20210401, also it is the same as I mentioned above when typing in the same commands in the powershell(windows 10) that is nothing happens.

so based on lots of test results above, my summaries as follows:

  1. there is one bug for debugging when using v0.10.0-esp32-20210726, but it can be used for flashing with JTAG, while v0.10.0-esp32-20210401 can be used for debugging , but not flashing
  2. v0.10.0-esp32-20210401 plus GDB are only available in git(bash) or other terminals (similar with linux) not powershell(windows10)
  3. v0.10.0-esp32-20210401 plus vscode plus esp-idf-extension, it cannot work:
    • mode: auto image
    • mode: manual image
  4. the log information is as shown above

However, I tried to type in the same commands from powershell to git(bash), it seems that there is some difference, as below:

For OpenOCD

wireless_tech@LAPTOP-GUPHVV02 MINGW64 /f/BLE_WIFI/Espressif/SDK/blink/blink
$  F:\\Tools\\Espressif\\IDF_Tools\\.espressif\\tools\\openocd-esp32\\v0.10.0-esp32-20210721\\openocd-esp32\\bin\\openocd.exe -s tcl -f board/esp32c3-builtin.cfg
Open On-Chip Debugger  v0.10.0-esp32-20210721 (2021-07-21-13:35)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Warn : Transport "jtag" was already selected
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 40000 kHz
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : datacount=2 progbufsize=16
Info : Examined RISC-V core; found 1 harts
Info :  hart 0: XLEN=32, misa=0x40101104
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Warn : No symbols for FreeRTOS!
Error: Algorithm timed out after 40001 ms.
Error: ra = 0x0
Error: sp = 0x3fc84890
Error: gp = 0x3fc89c00
Error: tp = 0x3fc8879c
Error: t0 = 0x80000000
Error: t1 = 0x0
Error: t2 = 0x0
Error: s0 = 0x600d0170
Error: s1 = 0x46a303
Error: a0 = 0x5
Error: a1 = 0xffffffff
Error: a2 = 0x3fc848ac
Error: a3 = 0x3fc8eb28
Error: a4 = 0x3fc8b470
Error: a5 = 0x600c4000
Error: a6 = 0x0
Error: a7 = 0x403816d6
Error: s2 = 0xbfe1c34c
Error: s3 = 0x0
Error: s4 = 0x0
Error: s5 = 0x0
Error: s6 = 0x0
Error: s7 = 0x0
Error: s8 = 0x0
Error: s9 = 0x0
Error: s10 = 0x0
Error: s11 = 0x0
Error: t3 = 0x0
Error: t4 = 0x0
Error: t5 = 0x0
Error: t6 = 0x0
Error: pc = 0x40380000
Error: mstatus = 0x1800
Error: mepc = 0x40380000
Error: mcause = 0x2
Error: Failed to wait algorithm (-302)!
Error: Algorithm run failed (-302)!
Error: Failed to run flasher stub (-302)!
Warn : Failed to get flash mappings (-302)!
Error: Target is already running an algorithm
Error: Failed to start algorithm (-4)!
Error: Failed to run flasher stub (-4)!
Warn : not enough working area available(requested 7640)
Error: no working area available, can't alloc space for stub code!
Error: Failed to run flasher stub (-308)!
Error: Failed to probe flash, size 0 KB
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.
Error: attempted 'gdb' connection rejected

For GDB

wireless_tech@LAPTOP-GUPHVV02 MINGW64 /f/BLE_WIFI/Espressif/SDK/blink/blink
$ F:\\Tools\\Espressif\\IDF_Tools\\.espressif\\tools\\riscv32-esp-elf\\1.24.0.123_64eb9ff-8.4.0\\riscv32-esp-elf\\bin\\riscv32-esp-elf-gdb.exe -x gdbinit build/blink.elf
GNU gdb (crosstool-NG 1.24.0.123_64eb9ff) 8.3.1.20191211-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from build/blink.elf...
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Ignoring packet error, continuing...
gdbinit:1: Error in sourced command file:
Remote replied unexpectedly to 'vMustReplyEmpty': timeout
(gdb)

while nothing happens when using the powershell with the same commands.

@NicolSpies In manual mode you need to start both DebugAdapter script and OpenOCD yourself.

  1. Run OpenOCD
  2. Run DebugAdapter as python3 debug_adapter_main.py -e blink.elf -ip localhost -dn esp32c3 -d 5 -ln. debug_adapter_main.py should be somewhere in VsCode IDF plugin dir.
  3. Start debug session in VsCode.

@brianignacio5 Please correct me.