espressif / openocd-esp32

OpenOCD branch with ESP32 JTAG support
Other
358 stars 131 forks source link

Problem programming ESP32-C2 with J-Link JTAG. Hart unexpectedly reset! (OCD-933) #322

Closed jeroenommering closed 6 months ago

jeroenommering commented 7 months ago

Development Kit

Custom board

Module or chip used

ESP32-C2

Debug Adapter

J-Link / JTAG

OpenOCD version

v0.12.0-esp32-20240318

Operating System

Windows

Using an IDE ?

no, running OpenOCD32 from the command line

OpenOCD command line

openocd-esp32\bin\openocd.exe -f interface/jlink.cfg -f target/esp32c2_fast.cfg -c "init; program_esp ESP32C2-2MB_ESP-AT_UART0_TX20_RX19_no_console_V03030000.bin 0x0 verify exit"

JTAG Clock Speed

1MHz, 4MHz, ....

ESP-IDF version

not applicable

Problem Description

I am trying to (re-)program the ESP32-C2. No debugging is involved.

Today I updated to the newest version of OpenOCD32. I already had the problem with the version from april 2023.

The two configuration files specified at the command line are those that come with the latest release. The only modification is the addition of a line that set the interface speed.

1) Power on the ESP 2) Run the command line specified above. The .bin is similar to the default ESP-AT firmware.

Attached is the log file obtained by adding -d3 to the command line

openocd_log.txt

Debug Logs

Log output without the -d3 flag:
Open On-Chip Debugger v0.12.0-esp32-20240318 (2024-03-18-18:26)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Info : J-Link V9 compiled May  7 2021 16:26:12
Info : Hardware version: 9.60
Info : VTarget = 3.312 V
Info : clock speed 4000 kHz
Info : JTAG tap: esp32c2.cpu tap/device found: 0x0000cc25 (mfg: 0x612 (Espressif Systems), part: 0x000c, ver: 0x0)
Info : [esp32c2] datacount=2 progbufsize=16
Info : [esp32c2] Examined RISC-V core; found 1 harts
Info : [esp32c2]  XLEN=32, misa=0x40101104
Info : [esp32c2] Examination succeed
Info : starting gdb server for esp32c2 on 3333
Info : Listening on port 3333 for gdb connections
** program_esp input args <0x0 verify exit> **
Info : JTAG tap: esp32c2.cpu tap/device found: 0x0000cc25 (mfg: 0x612 (Espressif Systems), part: 0x000c, ver: 0x0)
Info : [esp32c2] Reset cause (24) - (JTAG CPU reset)
** Programming Started **
Info : [esp32c2] Found 2 triggers
Warn : Failed to get flash maps (-8)!
Warn : Invalid magic number in app image!
Warn : Failed to get flash mappings (-4)!
Info : Auto-detected flash bank 'esp32c2.flash' size 2048 KB
Info : Using flash bank 'esp32c2.flash' size 2048 KB
Info : PROF: Erased 2097152 bytes in 1386.99 ms
Error: [esp32c2] Failed DMI write (NOP) at 0x38; status=1
Info : [esp32c2] Hart unexpectedly reset!
Error: [esp32c2] Failed DMI read at 0x38; status=1
Warn : [esp32c2] Failed to write memory via system bus.
Warn : [esp32c2] Buggy aampostincrement! Address not incremented correctly.
Info : [esp32c2] Reset cause (0) - (Unknown reset cause)
Info : [esp32c2] Hart unexpectedly reset!
Info : [esp32c2] Reset cause (3) - (Software core reset)
Info : [esp32c2] Hart unexpectedly reset!
Error: Algorithm accidentally stopped (1)! Transferred 622516 of 2097152
Error: Failed to exec algorithm user func (-4)!
Error: Algorithm timed out after 1 ms.
Error: ra = 0x40055af0
Error: sp = 0x3fcde9c0
Error: gp = 0x0
Error: tp = 0x0
Error: t0 = 0x400553da
Error: t1 = 0xffffffe0
Error: t2 = 0x3fcde9fc
Error: fp = 0x65c
Error: s1 = 0xd42ec36a
Error: a0 = 0x3c000b54
Error: a1 = 0x403aeb70
Error: a2 = 0x1f04
Error: a3 = 0x3c002294
Error: a4 = 0x1740
Error: a5 = 0x5d0
Error: a6 = 0x80000000
Error: a7 = 0x10
Error: s2 = 0x2
Error: s3 = 0x3fce0000
Error: s4 = 0xffff
Error: s5 = 0x3ff48094
Error: s6 = 0xb54
Error: s7 = 0x3fce0000
Error: s8 = 0x0
Error: s9 = 0x0
Error: s10 = 0x0
Error: s11 = 0x0
Error: t3 = 0x0
Error: t4 = 0x15b593
Error: t5 = 0x95be8de1
Error: t6 = 0xffe007b7
Error: pc = 0x40055b1c
Error: mstatus = 0x9
Error: mepc = 0x0
Error: mcause = 0x0
Error: Failed to wait algorithm (-302)!
Error: Algorithm run failed (-302)!
Error: Failed to run flasher stub (-302)!
Error: error writing to flash at address 0x00000000 at offset 0x00000000
Info : [esp32c2] Reset cause (3) - (Software core reset)
** Programming Failed **
shutdown command invoked
D:/xxxx/WifiSniffer/Image_and_JTAG/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg:9: Error: 
at file "D:/xxxx/WifiSniffer/Image_and_JTAG/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 9

Expected behavior

I expect to be able to successfully program the ESP32-C2 every time I run the programming command

Screenshots

No response

erhankur commented 6 months ago

@jeroenommering Typically I set adapter speed to 5Mhz when I use jlink.

This is a custom board. So, what is your flash chip manufacturer?

Can you try below command and send us the output.

openocd-esp32\bin\openocd.exe -f interface/jlink.cfg -f target/esp32c2_fast.cfg  -c "init; esp stub_log on; program_esp ESP32C2-2MB_ESP-AT_UART0_TX20_RX19_no_console_V03030000.bin 0x0 verify exit"
jeroenommering commented 6 months ago

Hi Erhan,

Thanks for your response. The exact processor reference is the ESP8684H2. Meanwhile, I think I found the real cause of the problem which seems to be the power supplied to the board during programming. I'm seeing large fluctuations and the reset may be caused by that. I did not have the opportunity to investigate further but for now, I will close the issue.