Skip to content

Debug ESP32-C3 using JTAG over USB on Arduino IDE 2.x #8353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KurtE opened this issue Jun 26, 2023 · 6 comments
Closed

Debug ESP32-C3 using JTAG over USB on Arduino IDE 2.x #8353

KurtE opened this issue Jun 26, 2023 · 6 comments
Assignees
Labels
IDE: Arduino IDE Issue relates to Arduino IDE Resolution: Expired More info wasn't provided Type: Question Only question

Comments

@KurtE
Copy link

KurtE commented Jun 26, 2023

Board

ESP32-C3-DevKitC-02 and ESP32-C3-DevkitM-1 and LuotOS.com/t/esp32C3

Device Description

I have tried 3 different setups for ESP32-C3

image

For the: ESP32-C3-DevKitC-02 and ESP32-C3-DevkitM-1 I use breadboard, to a USB breakout board.

For LuotOS version, the USB connector is actually connected to pins IO18 and IO19. More details about this board up at: https://m.media-amazon.com/images/I/91S2q9qyLcL.pdf

Hardware Configuration

Nothing other than mentioned above where IO18 and IO19 connected to USB connector.

Version

2.0.9

IDE Name

Arduino IDE 2.1 and and nightly build 20230625

Operating System

Windows 11

Flash frequency

80mhz

PSRAM enabled

yes

Upload speed

921600

Description

Using the Arduino IDE 2.x debug facility on the ESP32-C3 does not appear to work. Initially it looks like the debugger starts up. But trying to do anything causes it to hang or crash.

Note: this is related to #8334 by @mjs513 but that issue started off as more of a question or issue on how to setup the JTAG for the ESP32-C3 and programming, and this one has more to do once the JTAG over USB is setup, and it appears like the debugger starts up. You soon find that nothing appears to work.

If you feel like this is a duplicate, feel free to close it as such. Some groups like to group things together and others like each specific thing broken out as a new issue.

Sketch

Any sketch will do, but current one:

#include "Freenove_WS2812_Lib_for_ESP32.h"

#define LEDS_COUNT  1
#define LEDS_PIN	8
#define CHANNEL		0

Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, LEDS_PIN, CHANNEL, TYPE_GRB);

void setup() {
  strip.begin();
  strip.setBrightness(20);  
}

void loop() {
  for (int j = 0; j < 255; j += 2) {
    for (int i = 0; i < LEDS_COUNT; i++) {
      strip.setLedColorData(i, strip.Wheel((i * 256 / LEDS_COUNT + j) & 255));
    }
    strip.show();
    delay(10);
  }  
}

Debug Message

Not sure what to include here.

Did include a lot of debug information in the steps to reproduce.

Other Steps to Reproduce

Build your sketch: Note: I have sketch->Opmtimize for debug turned on:
I have JTAG using USB as the image below shows.
image

I build and upload the sketch,
I then press the debug button and it looks like the debugger comes up:
image

The debug console window comes up:

Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-w64-mingw32 --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
    .
For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: 'set target-async', an alias for the command 'set mi-async', is deprecated.
Use 'set mi-async'.
0x40000000 in ?? ()
Program stopped, probably due to a reset and/or halt issued by debugger
JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Reset cause (3) - (Software core reset)
Hardware assisted breakpoint 1 at 0x4200004c: file C:\Users\kurte\Documents\Arduino\Rainbow/Rainbow.ino, line 9.

The gdb-server data: (removed most as text too long)
Debug: 6476 11256 gdb_server.c:404 gdb_log_outgoing_packet(): [esp32c3] sending packet: $#2
Debug: 6477 11324 gdb_server.c:390 gdb_log_incoming_packet(): [esp32c3] received packet: m3fc95774,4
Debug: 6478 11324 gdb_server.c:1533 gdb_read_memory_packet(): addr: 0x000000003fc95774, len: 0x00000004
Debug: 6479 11324 target.c:2522 target_read_buffer(): reading buffer of 4 byte at 0x3fc95774
Debug: 6480 11327 riscv-013.c:2859 log_mem_access_result(): Succeeded to read memory via system bus.
Debug: 6481 11327 gdb_server.c:407 gdb_log_outgoing_packet(): [esp32c3] sending packet: $00000000#80
Debug: 6482 11648 gdb_server.c:390 gdb_log_incoming_packet(): [esp32c3] received packet: m3fc95774,4
Debug: 6483 11649 gdb_server.c:1533 gdb_read_memory_packet(): addr: 0x000000003fc95774, len: 0x00000004
Debug: 6484 11649 target.c:2522 target_read_buffer(): reading buffer of 4 byte at 0x3fc95774
Debug: 6485 11654 riscv-013.c:2859 log_mem_access_result(): Succeeded to read memory via system bus.
Debug: 6486 11655 gdb_server.c:407 gdb_log_outgoing_packet(): [esp32c3] sending packet: $00000000#80
Debug: 6487 11655 gdb_server.c:390 gdb_log_incoming_packet(): [esp32c3] received packet: m3fc95774,4
Debug: 6488 11655 gdb_server.c:1533 gdb_read_memory_packet(): addr: 0x000000003fc95774, len: 0x00000004
Debug: 6489 11655 target.c:2522 target_read_buffer(): reading buffer of 4 byte at 0x3fc95774
Debug: 6490 11658 riscv-013.c:2859 log_mem_access_result(): Succeeded to read memory via system bus.
Debug: 6491 11658 gdb_server.c:407 gdb_log_outgoing_packet(): [esp32c3] sending packet: $00000000#80

So I decide to maybe set breakpoint at the strip.show line and click on the left of the 19 

The debug window shows the red filled circle, and new messages to the console tab:

JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Reset cause (3) - (Software core reset)
Hardware assisted breakpoint 1 at 0x4200004c: file C:\Users\kurte\Documents\Arduino\Rainbow/Rainbow.ino, line 9.

I hit the continue button:
And it looked like maybe the code went to line 9, with a few more lines output to debug console tab:

Note: automatically using hardware breakpoints for read-only addresses.
[New Thread 1070463660]
[New Thread 1070177460]
[New Thread 1070169048]
[New Thread 1070174784]
[Switching to Thread 1070463660]
Thread 2 "loopTask" hit Temporary breakpoint 1, setup () at C:\Users\kurte\Documents\Arduino\Rainbow/Rainbow.ino:9
9 void setup() {

Tried hitting continue this time, tried step other times... But nothing worked at this point:
Then looked at the gdb-server tab and it was going nuts with continuous output, which I could only stop it by killing the debugger (hit the stop debug button).

Here is an extract from the end of this debug information:

Debug: 348949 743354 riscv.c:3893 register_get(): [esp32c3] read 0x40387716 from pc (valid=0)
Debug: 348950 743354 gdb_server.c:407 gdb_log_outgoing_packet(): [esp32c3] sending packet: $000000004a773840e0bfc93f00c2c83f3032c93f0e8905400f000000000000004e0000420000000003010000e4bfc93f0100000000000000020000000100000000000000000000000020033c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016773840#4b
Debug: 348951 743365 gdb_server.c:390 gdb_log_incoming_packet(): [esp32c3] received packet: qXfer:threads:read::0,1000
Debug: 348952 743365 gdb_server.c:404 gdb_log_outgoing_packet(): [esp32c3] sending packet: $#12
Debug: 348953 743366 gdb_server.c:390 gdb_log_incoming_packet(): [esp32c3] received packet: z1,4200007a,2
Debug: 348954 743366 gdb_server.c:1745 gdb_breakpoint_watchpoint_packet(): [esp32c3]
Debug: 348955 743366 riscv.c:930 remove_trigger(): [0] Stop using resource 0 for bp 2
Debug: 348956 743366 riscv-013.c:4087 riscv013_get_register(): [esp32c3] reading register tselect
Debug: 348957 743366 riscv-013.c:800 execute_abstract_command(): command=0x2207a0; access register, size=32, postexec=0, transfer=1, write=0, regno=0x7a0
Debug: 348958 743367 riscv-013.c:1504 register_read_direct(): {0} tselect = 0x0
Debug: 348959 743367 riscv.c:3539 riscv_get_register(): [esp32c3] tselect: 0
Debug: 348960 743368 riscv.c:3482 riscv_set_register(): [esp32c3] tselect <- 0
Debug: 348961 743368 riscv-013.c:4116 riscv013_set_register(): [0] writing 0x0 to register tselect
Debug: 348962 743368 riscv-013.c:1315 register_write_direct(): {0} tselect <- 0x0
Debug: 348963 743368 riscv-013.c:800 execute_abstract_command(): command=0x2307a0; access register, size=32, postexec=0, transfer=1, write=1, regno=0x7a0
Debug: 348964 743369 riscv.c:3501 riscv_set_register(): [esp32c3] wrote 0x0 to tselect valid=0
Debug: 348965 743369 riscv.c:3482 riscv_set_register(): [esp32c3] tdata1 <- 0
Debug: 348966 743369 riscv-013.c:4116 riscv013_set_register(): [0] writing 0x0 to register tdata1
Debug: 348967 743369 riscv-013.c:1315 register_write_direct(): {0} tdata1 <- 0x0
Debug: 348968 743370 riscv-013.c:800 execute_abstract_command(): command=0x2307a1; access register, size=32, postexec=0, transfer=1, write=1, regno=0x7a1
Debug: 348969 743370 riscv.c:3501 riscv_set_register(): [esp32c3] wrote 0x0 to tdata1 valid=0
Debug: 348970 743370 riscv.c:3482 riscv_set_register(): [esp32c3] tselect <- 0
Debug: 348971 743370 riscv-013.c:4116 riscv013_set_register(): [0] writing 0x0 to register tselect
Debug: 348972 743370 riscv-013.c:1315 register_write_direct(): {0} tselect <- 0x0
Debug: 348973 743372 riscv-013.c:800 execute_abstract_command(): command=0x2307a0; access register, size=32, postexec=0, transfer=1, write=1, regno=0x7a0
Debug: 348974 743373 riscv.c:3501 riscv_set_register(): [esp32c3] wrote 0x0 to tselect valid=0
Debug: 348975 743373 breakpoints.c:291 breakpoint_free(): free BPID: 2 --> 0
Debug: 348976 743373 gdb_server.c:407 gdb_log_outgoing_packet(): [esp32c3] sending packet: $OK#9a
Debug: 348977 743373 gdb_server.c:390 gdb_log_incoming_packet(): [esp32c3] received packet: m3fc9bfc0,40
Debug: 348978 743373 gdb_server.c:1533 gdb_read_memory_packet(): addr: 0x000000003fc9bfc0, len: 0x00000040
Debug: 348979 743374 target.c:2522 target_read_buffer(): reading buffer of 64 byte at 0x3fc9bfc0
Debug: 348980 743379 riscv-013.c:2859 log_mem_access_result(): Succeeded to read memory via system bus.
Debug: 348981 743379 gdb_server.c:407 gdb_log_outgoing_packet(): [esp32c3] sending packet: $a5a5a5a5a5a5a5a5a5a5a50a01000000000000000000000000000000000000000100000001000000000000004e0000420020033c0050c93f7cc0c93f00820042#6c
Debug: 348982 743383 gdb_server.c:390 gdb_log_incoming_packet(): [esp32c3] received packet: m3fc9c040,40
Debug: 348983 743383 gdb_server.c:1533 gdb_read_memory_packet(): addr: 0x000000003fc9c040, len: 0x00000040
Debug: 348984 743383 target.c:2522 target_read_buffer(): reading buffer of 64 byte at 0x3fc9c040
Debug: 348985 743387 riscv-013.c:2859 log_mem_access_result(): Succeeded to read memory via system bus.
Debug: 348986 743387 gdb_server.c:407 gdb_log_outgoing_packet(): [esp32c3] sending packet: $a5a5a5a5a5a5a5a5a5a5a5a582809235a5a5a5a5a5a5a5a5a5a5a5a5000000000100000000000000b0c0c93fe2850042a5a5a5a5a5a5a5a5a5a5a5a500000000#e2
Debug: 348987 743528 gdb_server.c:228 gdb_get_char_inner(): GDB connection closed by the remote client
Debug: 348988 743529 gdb_server.c:1115 gdb_connection_closed(): GDB Close, Target: esp32c3, state: halted, gdb_actual_connections=0
Debug: 348989 743529 target.c:1847 target_call_event_callbacks(): target event 8 (gdb-end) for core esp32c3
Debug: 348990 743529 esp32c3.c:177 esp32c3_handle_target_event(): 8
Debug: 348991 743531 esp_riscv.c:356 esp_riscv_handle_target_event(): 8
Debug: 348992 743531 target.c:1847 target_call_event_callbacks(): target event 23 (gdb-detach) for core esp32c3
Debug: 348993 743531 esp32c3.c:177 esp32c3_handle_target_event(): 23
Debug: 348994 743531 esp_riscv.c:356 esp_riscv_handle_target_event(): 23
Info : 348995 743531 server.c:569 server_loop(): dropped 'gdb' connection
[2023-06-26T14:24:38.569Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...







### I have checked existing issues, online documentation and the Troubleshooting Guide

- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@KurtE KurtE added the Status: Awaiting triage Issue is waiting for triage label Jun 26, 2023
@me-no-dev
Copy link
Member

did you try adding a breakpoint in the loop and hitting the resume button for debug?

@SuGlider SuGlider added Type: Question Only question IDE: Arduino IDE Issue relates to Arduino IDE and removed Status: Awaiting triage Issue is waiting for triage labels Jun 27, 2023
@KurtE
Copy link
Author

KurtE commented Jun 27, 2023

did you try adding a breakpoint in the loop and hitting the resume button for debug?
Yes as well as other locations.

image

The debug starts up. I press the continue button, it get to setup:
Debug tab pane shows:

Hardware assisted breakpoint 1 at 0x4200004c: file C:\Users\kurte\Documents\Arduino\Rainbow/Rainbow.ino, line 9.
Note: automatically using hardware breakpoints for read-only addresses.
[New Thread 1070463660]
[New Thread 1070177460]
[New Thread 1070169048]
[New Thread 1070174784]
[Switching to Thread 1070463660]
Thread 2 "loopTask" hit Temporary breakpoint 1, setup () at C:\Users\kurte\Documents\Arduino\Rainbow/Rainbow.ino:9
9	void setup() {

I hit the continue button and the looks like nothing happened, The screen looks the same as the image I showed above.

I restarted this. I exited the IDE, turned off power to the ESP32-C3 and then turned on did a fresh upload, and then started up the debugger again
Here is the whole debug console and gdb server startup stuff...
Debug Console:

    ENOENT means program not found. If that is not the issue, please report this problem.
Launching gdb-server: "C:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\openocd-esp32\\v0.11.0-esp32-20221026/bin/openocd" -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s "c:\\Users\\kurte\\Documents\\Arduino\\Rainbow" -f "C:/arduino-ide_nightly/resources/app/plugins/cortex-debug/extension/support/openocd-helpers.tcl" -f debug.cfg -d3
    Please check TERMINAL tab (gdb-server) for output from C:\Users\kurte\AppData\Local\Arduino15\packages\esp32\tools\openocd-esp32\v0.11.0-esp32-20221026/bin/openocd
Finished reading symbols from objdump: Time: 26 ms
Finished reading symbols from nm: Time: 24 ms
Reading symbols from C:/Users\kurte\AppData\Local\Temp\arduino\sketches\E0082B7BB48CD9EC5B948DE681BAB496\Rainbow.ino.elf...
GNU gdb (esp-gdb) 11.2_20220823
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
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-w64-mingw32 --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
    .
For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: 'set target-async', an alias for the command 'set mi-async', is deprecated.
Use 'set mi-async'.
0x40000000 in ?? ()
Program stopped, probably due to a reset and/or halt issued by debugger
JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Reset cause (3) - (Software core reset)
Hardware assisted breakpoint 1 at 0x4200004c: file C:\Users\kurte\Documents\Arduino\Rainbow/Rainbow.ino, line 9.
Note: automatically using hardware breakpoints for read-only addresses.

The server stuff is longer so included file instead:
gdb-server-startup.txt

I did the continue button (twice)... The only new stuff in debug console:

[New Thread 1070463660]
[New Thread 1070177460]
[New Thread 1070169048]
[New Thread 1070174784]
[Switching to Thread 1070463660]
Thread 2 "loopTask" hit Temporary breakpoint 1, setup () at C:\Users\kurte\Documents\Arduino\Rainbow/Rainbow.ino:9

And the GDB server one was again going endless with data, until I told the debugger to stop.
gdb-server-aborted.txt

Note: I see in my temp directory a file that looks like the complete gdb log:
"C:\Users\kurte\AppData\Local\Temp\gdb-server-console-58868.log"
Which I thought about including here, but it is 10739kb in size and has 109K lines of text in it.
And probably not really needed as this is easy to reproduce.

Let me know if you need any additional information,
Kurt

@VojtechBartoska
Copy link
Contributor

Please help with triage of this ticket @me-no-dev, thanks

@VojtechBartoska VojtechBartoska added the Status: Awaiting triage Issue is waiting for triage label Aug 18, 2023
@me-no-dev
Copy link
Member

This is much the same as I explained in another thread. The debugger stopped the ESP in setup(), but the IDE interface did not update and does not show that. Hitting the little green arrow to continue the execution should run through setup and hit the loop() breakpoint.

@VojtechBartoska
Copy link
Contributor

Hello, closing this as expired, if needed you can reopen.

@VojtechBartoska VojtechBartoska closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2023
@VojtechBartoska VojtechBartoska added Resolution: Expired More info wasn't provided and removed Status: Awaiting triage Issue is waiting for triage labels Dec 12, 2023
@eddiem3
Copy link

eddiem3 commented Jan 6, 2024

Is there any advice on resolving this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDE: Arduino IDE Issue relates to Arduino IDE Resolution: Expired More info wasn't provided Type: Question Only question
Projects
None yet
Development

No branches or pull requests

5 participants