Skip to content
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

ESP32-C3 JTAG -- incorrect documentation -- unable to debug (IDFGH-4760) (OCD-307) #144

Closed
pjsg opened this issue Feb 18, 2021 · 26 comments
Closed

Comments

@pjsg
Copy link

pjsg commented Feb 18, 2021

I'm trying to port my app to the early esp32-c3 devkit that you mailed me (thanks!). I realize that the JTAG is not available from the USB, but hopefully is available from the pins using an external JTAG device. However, the only documentation that I can find on which pins are which -- https://docs.espressif.com/projects/esp-idf/en/v4.3-beta1/esp32c3/api-guides/jtag-debugging/configure-other-jtag.html -- unfortunately has a table copied from the esp32-s2 page and talks about GPIOs that are way out of range for the ESP32-C3-DevKitM-1 V1.0

Is there a better table somewhere of the pin mapping?

I'm a bit stuck not being able to do any debugging to see what is going wrong...

Thanks.

@github-actions github-actions bot changed the title ESP32-C3 JTAG -- incorrect documentation -- unable to debug ESP32-C3 JTAG -- incorrect documentation -- unable to debug (IDFGH-4760) Feb 18, 2021
@ESP-Marius
Copy link

@pjsg The C3 documention is still a work in progress, so lots of pages are still not properly updated. As for the JTAG pins you can find them in the C3 datasheet

@pjsg
Copy link
Author

pjsg commented Feb 19, 2021

Thanks for that. I have managed to make some progress. When trying to start debugging from eclipse, I got this:

Error in final launch sequence
Failed to execute MI command:
-target-select remote localhost:3333
Error message from debugger back end:
bfd requires xlen 8, but target has xlen 4
Failed to execute MI command:
-target-select remote localhost:3333
Error message from debugger back end:
bfd requires xlen 8, but target has xlen 4
bfd requires xlen 8, but target has xlen 4

For anybody else with this problem, you need to add set arch riscv:rv32 to the GDB Client Setup / Commands entry field.

However, while this gets you further, openocd then throws this error:

(3923) marchid (/32)
(3924) mimpid (/32)
(3925) mhartid (/32)
(4161) priv (/8)

Info : [0] Found 8 triggers
Error: Too large number of threads 1070170064!

and eclipse said

No source available for "(gdb[3].proc[42000].threadGroup[i1],gdb[3].proc[42000].OSthread[1]).thread[1].frame[0]" 

and the terminal showed:

0ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0xc (RTC_SW_CPU_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x400475d8
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x1810
load:0x403ce000,len:0x894
load:0x403d0000,len:0x2bf8
entry 0x403ce000

If I start the board not under the debugger then it gets into my app:

ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0xc (RTC_SW_CPU_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x403839ec
0x403839ec: esp_restart_noos at /home/philip/eclipse-workspace/nodemcu/sdk/esp32-esp-idf/components/esp32c3/system_api_esp32c3.c:137 (discriminator 1)

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x1810
load:0x403ce000,len:0x894
load:0x403d0000,len:0x2bf8
entry 0x403ce000
I (57) boot: ESP-IDF v4.4-dev-4-g73db14240-dirty 2nd stage bootloader
I (57) boot: compile time 19:29:21
I (57) boot: chip revision: 2
I (60) boot_comm: chip revision: 2, min. bootloader chip revision: 0
I (68) boot.esp32c3: SPI Speed      : 80MHz
I (72) boot.esp32c3: SPI Mode       : DIO
...
I (466) spi_flash: detected chip: generic
I (471) spi_flash: flash io: dio
I (475) cpu_start: Starting scheduler.

Mounting flash filesystem...
Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Stack dump detected
Core  0 register dump:
MEPC    : 0x42011d2a  RA      : 0x4201282c  SP      : 0x3fc9ab90  GP      : 0x3fc8fc00  
0x42011d2a: luaH_getstr at /home/philip/eclipse-workspace/nodemcu/components/lua/ltable.c:594

I'm not sure what my next step should be.....

@igrr
Copy link
Member

igrr commented Feb 19, 2021

@pjsg What is the output of openocd --version? I think the OpenOCD version used in ESP-IDF hasn't been updated for ESP32-C3 support yet.

@pjsg
Copy link
Author

pjsg commented Feb 20, 2021

Open On-Chip Debugger v0.10.0-esp32-20201202-14-gde9e630c (2021-02-14-18:40)

This is a version that I built based off the current master in your repo. I need to do this as I need the ftdi driver to be able to drive an altera usb-blaster (which was before I found my jlink!).

@igrr
Copy link
Member

igrr commented Feb 20, 2021

Okay, I'll move the issue to OpenOCD project for further troubleshooting.

@igrr igrr transferred this issue from espressif/esp-idf Feb 20, 2021
@github-actions github-actions bot changed the title ESP32-C3 JTAG -- incorrect documentation -- unable to debug (IDFGH-4760) ESP32-C3 JTAG -- incorrect documentation -- unable to debug (IDFGH-4760) (OCD-307) Feb 20, 2021
@igrr
Copy link
Member

igrr commented Feb 20, 2021

Could you please try running a debugging session from the command line to narrow down the cause of the issue?

  1. Pull latest master branch of openocd-esp32 and build it. We have merged support for resetting the target yesterday, it might help.
  2. Start OpenOCD: src/openocd -s tcl -c interface/jlink.cfg -c target/esp32c3.cfg (assuming you are using JLink now)
  3. Create gdbinit file with the following content:
    target remote :3333
    mon reset halt
    thb app_main
    continue
    
  4. In another terminal, run idf.py flash monitor in your project directory
  5. In yet another terminal, run riscv32-esp-elf-gdb build/app-name.elf -x gdbinit

If that still doesn't work, please add -d3 argument to OpenOCD command line, and post the logs you get (OpenOCD, serial monitor, GDB).

Thanks.

@pjsg
Copy link
Author

pjsg commented Feb 20, 2021

This works much better thank you. I now get:

Error: FreeRTOS uxTaskNumber seems to be corrupted!
Error: FreeRTOS uxTaskNumber seems to be corrupted!
Error: FreeRTOS uxTaskNumber seems to be corrupted!

when stepping through the code. It doesn't seem to interfere with normal use, so I'm happy to ignore it.....

Thank you.

@igrr
Copy link
Member

igrr commented Feb 20, 2021

This warning was added recently in 9c56cb1, possibly there is some bug that it gets printed. @erhankur could you help troubleshoot this part?

@pjsg
Copy link
Author

pjsg commented Feb 20, 2021

I tried to reproduce with debugging turned on, and it didn't reproduce. It doesn't happen in every debugging session. So far I've made it happen twice (with maybe 5 attempts) when not running openocd -d, and never (with maybe 10 attempts) with openocd -d!

I'm driving from eclipse if that makes a difference.

@erhankur
Copy link
Collaborator

Hi @pjsg,

I will try to reproduce the error from the eclipse. In the meantime could you please try again from command line without -d option. Once you see the error you can change openocd debug level from gdb screen with mon debug_level 3
Then please run some commands (step, continue, break etc..) and post the logs you collected.

Thanks

@pjsg
Copy link
Author

pjsg commented Feb 23, 2021

I attach the log from the openocd instance -- it actually reproduced on the first attempt.

openocd.txt

@pjsg
Copy link
Author

pjsg commented Feb 23, 2021

And this was the gdb log:

~/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gdb build/nodemcu.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-build_pc-linux-gnu --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/nodemcu.elf...
(gdb) target remote :3333
Remote debugging using :3333
0x4208b4c8 in esp_pm_impl_waiti ()
    at /home/philip/eclipse-workspace/nodemcu/sdk/esp32-esp-idf/components/hal/esp32c3/include/hal/cpu_ll.h:156
156	    asm volatile ("wfi\n");
(gdb) set remote hardware-watchpoint-limit 2
(gdb) mon reset halt
JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
(gdb) flushregs
Register cache flushed.
(gdb) thb app_main
Hardware assisted breakpoint 1 at 0x420082be: file /home/philip/eclipse-workspace/nodemcu/components/base_nodemcu/user_main.c, line 149.
(gdb) c
Continuing.
[New Thread 1070227208]
[New Thread 1070195484]
[New Thread 1070221580]
[New Thread 1070216412]
[New Thread 1070200532]
[New Thread 1070178176]
[Switching to Thread 1070198136]

Thread 1 hit Temporary breakpoint 1, app_main ()
    at /home/philip/eclipse-workspace/nodemcu/components/base_nodemcu/user_main.c:149
149	  task_init();
(gdb) step
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
task_init () at /home/philip/eclipse-workspace/nodemcu/components/task/task.c:105
105	  pending = xSemaphoreCreateBinary ();
(gdb) mon debug_level 3
debug_level: 3

(gdb) step
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
FreeRTOS uxTaskNumber seems to be corrupted!
xQueueGenericCreate (uxQueueLength=uxQueueLength@entry=1, uxItemSize=uxItemSize@entry=0, 
    ucQueueType=ucQueueType@entry=3 '\003')
    at /home/philip/eclipse-workspace/nodemcu/sdk/esp32-esp-idf/components/freertos/queue.c:384
384			configASSERT( uxQueueLength > ( UBaseType_t ) 0 );
(gdb) quit
A debugging session is active.

	Inferior 1 [Remote target] will be detached.

Quit anyway? (y or n) y
Detaching from program: /home/philip/eclipse-workspace/nodemcu/build/nodemcu.elf, Remote target
Ending remote debugging.
[Inferior 1 (Remote target) detached]

@erhankur
Copy link
Collaborator

Hi @pjsg,

Good news, I have re-produced the issue. Looks like ESP32-C3 rtos integration missing one necessary function call after reset the target. In each reset FreeRTOS uxTaskNumber variable set to zero but openocd does not cleanup rtos related counters. This breaks the synchronization.

Luckily, this is not blocker for debugging. Fix will be ready in the next release.

Thanks for your support.

@dau42
Copy link

dau42 commented Apr 26, 2021

I have a similar issue getting JTAG to work with ESP32C3 using a flyswatter2. The setup works as expected with an ESP32-DevKit-V4. My "board" is an ESP32C3 Wroom with the following connections:
Pin 1 3.3V with some caps to GND for decoupling
Pin 2 Reset 10k pull-up with 1uF to GND
Pin 3 TMS
Pin 4 TDI
Pin 5 TCK
Pin 6 TDO
Pin 9 GND

My eclipse output is...

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
adapter speed: 6000 kHz

force hard breakpoints
Started by GNU MCU Eclipse
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 6000 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!
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
semihosting is enabled

Error: Too large number of threads 4058895555!
Error: Too large number of threads 4058895555!
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
===== RISC-V Registers
(0) zero (/32)
(1) ra (/32)
(2) sp (/32)
(3) gp (/32)
(4) tp (/32)
(5) t0 (/32)
(6) t1 (/32)
(7) t2 (/32)
(8) fp (/32)
(9) s1 (/32)
(10) a0 (/32)
(11) a1 (/32)
(12) a2 (/32)
(13) a3 (/32)
(14) a4 (/32)
(15) a5 (/32)
(16) a6 (/32)
(17) a7 (/32)
(18) s2 (/32)
(19) s3 (/32)
(20) s4 (/32)
(21) s5 (/32)
(22) s6 (/32)
(23) s7 (/32)
(24) s8 (/32)
(25) s9 (/32)
(26) s10 (/32)
(27) s11 (/32)
(28) t3 (/32)
(29) t4 (/32)
(30) t5 (/32)
(31) t6 (/32)
(32) pc (/32)
(833) mstatus (/32)
(834) misa (/32)
(837) mie (/32)
(838) mtvec (/32)
(839) mcounteren (/32)
(868) mhpmevent3 (/32)
(869) mhpmevent4 (/32)
(870) mhpmevent5 (/32)
(871) mhpmevent6 (/32)
(872) mhpmevent7 (/32)
(873) mhpmevent8 (/32)
(874) mhpmevent9 (/32)
(875) mhpmevent10 (/32)
(876) mhpmevent11 (/32)
(877) mhpmevent12 (/32)
(878) mhpmevent13 (/32)
(879) mhpmevent14 (/32)
(880) mhpmevent15 (/32)
(881) mhpmevent16 (/32)
(882) mhpmevent17 (/32)
(883) mhpmevent18 (/32)
(884) mhpmevent19 (/32)
(885) mhpmevent20 (/32)
(886) mhpmevent21 (/32)
(887) mhpmevent22 (/32)
(888) mhpmevent23 (/32)
(889) mhpmevent24 (/32)
(890) mhpmevent25 (/32)
(891) mhpmevent26 (/32)
(892) mhpmevent27 (/32)
(893) mhpmevent28 (/32)
(894) mhpmevent29 (/32)
(895) mhpmevent30 (/32)
(896) mhpmevent31 (/32)
(897) mscratch (/32)
(898) mepc (/32)
(899) mcause (/32)
(900) mtval (/32)
(901) mip (/32)
(993) pmpcfg0 (/32)
(994) pmpcfg1 (/32)
(995) pmpcfg2 (/32)
(996) pmpcfg3 (/32)
(1009) pmpaddr0 (/32)
(1010) pmpaddr1 (/32)
(1011) pmpaddr2 (/32)
(1012) pmpaddr3 (/32)
(1013) pmpaddr4 (/32)
(1014) pmpaddr5 (/32)
(1015) pmpaddr6 (/32)
(1016) pmpaddr7 (/32)
(1017) pmpaddr8 (/32)
(1018) pmpaddr9 (/32)
(1019) pmpaddr10 (/32)
(1020) pmpaddr11 (/32)
(1021) pmpaddr12 (/32)
(1022) pmpaddr13 (/32)
(1023) pmpaddr14 (/32)
(1024) pmpaddr15 (/32)
(2017) tselect (/32)
(2018) tdata1 (/32)
(2019) tdata2 (/32)
(2020) tdata3 (/32)
(2033) dcsr (/32)
(2034) dpc (/32)
(2035) dscratch (/32)
(2881) mcycle (/32)
(2883) minstret (/32)
(2884) mhpmcounter3 (/32)
(2885) mhpmcounter4 (/32)
(2886) mhpmcounter5 (/32)
(2887) mhpmcounter6 (/32)
(2888) mhpmcounter7 (/32)
(2889) mhpmcounter8 (/32)
(2890) mhpmcounter9 (/32)
(2891) mhpmcounter10 (/32)
(2892) mhpmcounter11 (/32)
(2893) mhpmcounter12 (/32)
(2894) mhpmcounter13 (/32)
(2895) mhpmcounter14 (/32)
(2896) mhpmcounter15 (/32)
(2897) mhpmcounter16 (/32)
(2898) mhpmcounter17 (/32)
(2899) mhpmcounter18 (/32)
(2900) mhpmcounter19 (/32)
(2901) mhpmcounter20 (/32)
(2902) mhpmcounter21 (/32)
(2903) mhpmcounter22 (/32)
(2904) mhpmcounter23 (/32)
(2905) mhpmcounter24 (/32)
(2906) mhpmcounter25 (/32)
(2907) mhpmcounter26 (/32)
(2908) mhpmcounter27 (/32)
(2909) mhpmcounter28 (/32)
(2910) mhpmcounter29 (/32)
(2911) mhpmcounter30 (/32)
(2912) mhpmcounter31 (/32)
(3009) mcycleh (/32)
(3011) minstreth (/32)
(3012) mhpmcounter3h (/32)
(3013) mhpmcounter4h (/32)
(3014) mhpmcounter5h (/32)
(3015) mhpmcounter6h (/32)
(3016) mhpmcounter7h (/32)
(3017) mhpmcounter8h (/32)
(3018) mhpmcounter9h (/32)
(3019) mhpmcounter10h (/32)
(3020) mhpmcounter11h (/32)
(3021) mhpmcounter12h (/32)
(3022) mhpmcounter13h (/32)
(3023) mhpmcounter14h (/32)
(3024) mhpmcounter15h (/32)
(3025) mhpmcounter16h (/32)
(3026) mhpmcounter17h (/32)
(3027) mhpmcounter18h (/32)
(3028) mhpmcounter19h (/32)
(3029) mhpmcounter20h (/32)
(3030) mhpmcounter21h (/32)
(3031) mhpmcounter22h (/32)
(3032) mhpmcounter23h (/32)
(3033) mhpmcounter24h (/32)
(3034) mhpmcounter25h (/32)
(3035) mhpmcounter26h (/32)
(3036) mhpmcounter27h (/32)
(3037) mhpmcounter28h (/32)
(3038) mhpmcounter29h (/32)
(3039) mhpmcounter30h (/32)
(3040) mhpmcounter31h (/32)
(3137) cycle (/32)
(3138) time (/32)
(3139) instret (/32)
(3140) hpmcounter3 (/32)
(3141) hpmcounter4 (/32)
(3142) hpmcounter5 (/32)
(3143) hpmcounter6 (/32)
(3144) hpmcounter7 (/32)
(3145) hpmcounter8 (/32)
(3146) hpmcounter9 (/32)
(3147) hpmcounter10 (/32)
(3148) hpmcounter11 (/32)
(3149) hpmcounter12 (/32)
(3150) hpmcounter13 (/32)
(3151) hpmcounter14 (/32)
(3152) hpmcounter15 (/32)
(3153) hpmcounter16 (/32)
(3154) hpmcounter17 (/32)
(3155) hpmcounter18 (/32)
(3156) hpmcounter19 (/32)
(3157) hpmcounter20 (/32)
(3158) hpmcounter21 (/32)
(3159) hpmcounter22 (/32)
(3160) hpmcounter23 (/32)
(3161) hpmcounter24 (/32)
(3162) hpmcounter25 (/32)
(3163) hpmcounter26 (/32)
(3164) hpmcounter27 (/32)
(3165) hpmcounter28 (/32)
(3166) hpmcounter29 (/32)
(3167) hpmcounter30 (/32)
(3168) hpmcounter31 (/32)
(3265) cycleh (/32)
(3266) timeh (/32)
(3267) instreth (/32)
(3268) hpmcounter3h (/32)
(3269) hpmcounter4h (/32)
(3270) hpmcounter5h (/32)
(3271) hpmcounter6h (/32)
(3272) hpmcounter7h (/32)
(3273) hpmcounter8h (/32)
(3274) hpmcounter9h (/32)
(3275) hpmcounter10h (/32)
(3276) hpmcounter11h (/32)
(3277) hpmcounter12h (/32)
(3278) hpmcounter13h (/32)
(3279) hpmcounter14h (/32)
(3280) hpmcounter15h (/32)
(3281) hpmcounter16h (/32)
(3282) hpmcounter17h (/32)
(3283) hpmcounter18h (/32)
(3284) hpmcounter19h (/32)
(3285) hpmcounter20h (/32)
(3286) hpmcounter21h (/32)
(3287) hpmcounter22h (/32)
(3288) hpmcounter23h (/32)
(3289) hpmcounter24h (/32)
(3290) hpmcounter25h (/32)
(3291) hpmcounter26h (/32)
(3292) hpmcounter27h (/32)
(3293) hpmcounter28h (/32)
(3294) hpmcounter29h (/32)
(3295) hpmcounter30h (/32)
(3296) hpmcounter31h (/32)
(3922) mvendorid (/32)
(3923) marchid (/32)
(3924) mimpid (/32)
(3925) mhartid (/32)
(4161) priv (/8)

Info : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset

If I run the following on the command line to bypass Eclipse I get something similar...

% openocd -f $OPENOCD_SCRIPTS/interface/ftdi/flyswatter2.cfg -f $OPENOCD_SCRIPTS/target/esp32c3.cfg
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
adapter speed: 6000 kHz

force hard breakpoints
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 6000 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 : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset

@gerekon
Copy link
Collaborator

gerekon commented Apr 27, 2021

Pin 3 TMS
Pin 4 TDI
Pin 5 TCK
Pin 6 TDO

@dau42 You seem to have another issue. Check you JTAG pins connection
The proper connection is
GPIO4 -> TMS
GPIO5 -> TDI
GPIO6 -> TCK
GPIO7 -> TDO

Sorry. Your connection seem to be ok for esp32c3-Wroom. But the issue have different symptoms. What app did you flash to the chip? Can you check with hello_world example?

@gerekon
Copy link
Collaborator

gerekon commented Apr 27, 2021

@dau42 Note that before espressif/esp-idf@cccdb3e blink example used GPIO5 to control LED. GPIO5 is TDI on ESP32C3

@dau42
Copy link

dau42 commented Apr 27, 2021

I have switched to ESP32-C3 Dev Kit V2. Connections for JTAG are the same.
GPIO4 -> TMS

GPIO5 -> TDI

GPIO6 -> TCK

GPIO7 -> TDO
I have blink GPIO set to GPIO10. I can successfully flash using the USB connection but get the same results when using Command Line JTAG

% openocd -f $OPENOCD_SCRIPTS/interface/ftdi/flyswatter2.cfg -f $OPENOCD_SCRIPTS/target/esp32c3.cfg
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
adapter speed: 6000 kHz

force hard breakpoints
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 6000 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 : Hart 0 unexpectedly reset
Info : Hart 0 unexpectedly reset

I have set aside Eclipse for now to concentrate on getting command line flash via JTAG working.

Also, do you know where I can get the example code that comes on a virgin ESP32-C3 Dev Kit? It looks like it simple lights up the SK68XX RGB LED with cyan color.

@dau42
Copy link

dau42 commented Apr 28, 2021

The "Hart 0 unexpectedly reset" messages are caused by a mismatch of the ESP32c3 revision. In config there is a "Component config\ESP32c3 Specific\Minimum Supported ESP32C3 Revision" setting that defaults to Rev 3. My ESP32c3's are Revision 2 parts. This causes the boot loader to continually reset the part. If you monitor the TX line the boot loader sends out a message to warn about this condition.

ESP-IDF v4.4-dev-1183-g9d34a1cd42-dirty 2nd stage bootloader�
0;32mI (35) boot: compile time 14:26:18�
0;32mI (35) boot: chip revision: 2�
0;31mE (38) boot_comm: This chip is revision 2 but the application is configured for minimum revision 3. Can’t run.�
ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0x3 (RTC_SW_SYS_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x403d11b0
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x1658
load:0x403ce000,len:0x8b4
load:0x403d0000,len:0x2ba4
entry 0x403ce000
0;32mI (34) boot: ESP-IDF v4.4-dev-1183-g9d34a1cd42-dirty 2nd stage bootloader�
0;32mI (35) boot: compile time 14:26:18�
0;32mI (35) boot: chip revision: 2�
0;31mE (38) boot_comm: This chip is revision 2 but the application is configured for minimum revision 3. Can’t run.�
ESP-ROM:esp32c3-20200918
Build:Sep 18 2020
rst:0x3 (RTC_SW_SYS_RST),boot:0xc (SPI_FAST_FLASH_BOOT)

@dau42
Copy link

dau42 commented Apr 28, 2021

I have ESP32c3 Debug up and running on the Command Line and in Eclipse...

For the command line I use:

openocd -f $OPENOCD_SCRIPTS/interface/ftdi/flyswatter2.cfg  -f $OPENOCD_SCRIPTS/target/esp32c3.cfg 

to start up OpenOCD. I then open a second terminal session and use:

~/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gdb 

to start the correct version of gdb. Within gdb I use these commands:

set arch risk:rv32
target remote tcp::3333

to make the connection and start debugging. At this point everything works.

For Eclipse I setup a Debug Configuration with the OpenOCD config options as:

-s ${openocd_path}/share/openocd/scripts  -f interface/ftdi/flyswatter2.cfg -f target/esp32c3.cfg

and the correct risk version of gdb with the commands:

set arch riscv:rv32
set mem inaccessible-by-default off

At this point debugging on the ESP32C3 works fine on Eclipse.

@dau42
Copy link

dau42 commented Apr 28, 2021

I still cannot program the part via JTAG. When I use

% openocd -f $OPENOCD_SCRIPTS/interface/ftdi/flyswatter2.cfg  -f $OPENOCD_SCRIPTS/target/esp32c3.cfg -c "program_esp build/blink.bin 0x10000 verify exit"

I get...

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
adapter speed: 6000 kHz

force hard breakpoints
Info : clock speed 6000 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 : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210401/openocd-esp32/share/openocd/scripts/target/esp_common.cfg:100: Error: invalid command name "esp"
in procedure 'program_esp' 
at file "~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210401/openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 100

Something is still amiss with programming my ESP32c3 via JTAG. This command line works perfectly for an ESP32 if I compile for the esp32 and change the esp32c3.cfg to esp32.cfg. Everything works as expected using program_esp on the ESP32 but not the ESP32c3.

@igrr
Copy link
Member

igrr commented Apr 29, 2021

@dau42 Flash programming over JTAG and flash breakpoints aren't yet implemented for ESP32-C3. We are working on it and this will come in the next release.

@chegewara
Copy link

chegewara commented Jun 13, 2021

I believe i have the latest openocd installed but i am having the same issue as OP when i am trying to use buildin JTAG:

Open On-Chip Debugger v0.10.0-esp32-20210401 (2021-04-01-15:45)
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
force hard breakpoints
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!
Info : dropped 'gdb' connection

GDB logs:

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-build_pc-linux-gnu --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".
gdbinit:1: Error in sourced command file:
bfd requires xlen 8, but target has xlen 4

@igrr

EDIT with openocd -d i get this:

<feature name="org.gnu.gdb.riscv.virtual">
<reg name="priv" bitsize="8" regnum="4161" save-restore="no" type="int" group="general"/>
</feature>
</target>
#ab'
Debug: 887 1985 gdb_server.c:1043 gdb_connection_closed(): GDB Close, Target: esp32c3, state: halted, gdb_actual_connections=0
Debug: 888 1985 target.c:1636 target_call_event_callbacks(): target event 6 (gdb-end) for core esp32c3
Debug: 889 1985 target.c:1636 target_call_event_callbacks(): target event 20 (gdb-detach) for core esp32c3
Info : 890 1985 server.c:577 server_loop(): dropped 'gdb' connection

index.txt

@erhankur
Copy link
Collaborator

Hi @chegewara,
Looks like gdb could not recognize the correct target len. It thinks as 64 bit instead of 32. If you give your elf file, it will get correct XLEN from there.

riscv32-esp-elf-gdb build/hello-world.elf -x gdbinit

Or you can explicitly force gdb to 32-bit using set arch riscv:rv32

@chegewara
Copy link

@erhankur Thanks, adding elf file in command line helped.

@giacomo-zanichelli
Copy link

giacomo-zanichelli commented Aug 3, 2021

dau42 Flash programming over JTAG and flash breakpoints aren't yet implemented for ESP32-C3. We are working on it and this will come in the next release.

@igrr, is there an update on when programming over JTAG may be available? Thanks

@gerekon
Copy link
Collaborator

gerekon commented Aug 3, 2021

@giacomo-zanichelli It was released. But recommended openocd version is not updated in IDF yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants