I am having issues to get a debug session started on the ESP32C6 using openOCD and GDB.
Board: ESP32-C6-DevKitC-1-N8 (8MB FLASH)
ESP-IFD: Fresh install 5.1 latest release from yesterday incl. tools
Code: hello_world example modified to stay in a loop to not restart (see below)
I was able to debug the board before with a pre-release version of ESP-IDF (master branch) so I assume its due to the update of ESP-IDF and something with GDB but maybe I just made a stupid mistake somewhere?!
Help is very much appreciated!
- #include <stdio.h>
- #include <inttypes.h>
- #include "sdkconfig.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_chip_info.h"
- #include "esp_flash.h"
- void app_main(void)
- {
- printf("Hello world!\n");
- /* Print chip information */
- esp_chip_info_t chip_info;
- uint32_t flash_size;
- esp_chip_info(&chip_info);
- printf("This is %s chip with %d CPU core(s), WiFi%s%s%s, ",
- CONFIG_IDF_TARGET,
- chip_info.cores,
- (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
- (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "",
- (chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : "");
- unsigned major_rev = chip_info.revision / 100;
- unsigned minor_rev = chip_info.revision % 100;
- printf("silicon revision v%d.%d, ", major_rev, minor_rev);
- if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
- printf("Get flash size failed");
- return;
- }
- printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
- (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
- printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
- for (int i = 10; i >= 0; i--) {
- printf("Restarting in %d seconds...\n", i);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- }
- while(1)
- {
- printf("Just sitting here waiting to debug... \n");
- vTaskDelay(2000 / portTICK_PERIOD_MS);
- }
- printf("Restarting now.\n");
- fflush(stdout);
- esp_restart();
- }
I am using the command line to start openOCD and GDB.
OpenOCD seems to work fine and able to connect to the target when started.
D:\ESP_VSC_Projects\hello_world>openocd -f /board/esp32c6-builtin,cfg
Open On-Chip Debugger v0.12.0-esp32-20230419 (2023-04-18-22:02)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
embedded:startup.tcl:28: Error: Can't find /board/esp32c6-builtin,cfg
in procedure 'script'
at file "embedded:startup.tcl", line 28
D:\ESP_VSC_Projects\hello_world>openocd -f /board/esp32c6-builtin.cfg
Open On-Chip Debugger v0.12.0-esp32-20230419 (2023-04-18-22:02)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselecting 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
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: serial (60:55:F9:F7:2B:AC)
Info : esp_usb_jtag: Device found. Base speed 24000KHz, div range 1 to 255
Info : clock speed 24000 kHz
Info : JTAG tap: esp32c6.cpu tap/device found: 0x0000dc25 (mfg: 0x612 (Espressif Systems), part: 0x000d, ver: 0x0)
Info : datacount=2 progbufsize=16
Info : Examined RISC-V core; found 2 harts
Info : hart 0: XLEN=32, misa=0x40903105
Info : starting gdb server for esp32c6 on 3333
Info : Listening on port 3333 for gdb connections
Starting GDB I get "Remote replied unexpectedly to 'vMustReplyEmpty': timeout" see below.
My gdbInit includes these lines:
target remote :3333
set remote hardware-watchpoint-limit 2
mon reset halt
flushregs
thb app_main
c
GDB output:
D:\ESP_VSC_Projects\hello_world>riscv32-esp-elf-gdb -x gdbinit build/hello_world.elf
GNU gdb (esp-gdb) 12.1_20221002
Copyright (C) 2022 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-w64-mingw32 --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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/hello_world.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)
Once I get the error in GDB openOCD prints the following:
Warn : No symbols for FreeRTOS!
Error: Algorithm timed out after 40001 ms.
Info : [esp32c6] Halt cause (5) - (PMP Load access fault)
Error: ra = 0x408012a2
Error: sp = 0x40804700
Error: gp = 0x40812040
Error: tp = 0x4080d920
Error: t0 = 0x0
Error: t1 = 0x0
Error: t2 = 0x0
Error: s0 = 0x40817210
Error: s1 = 0x0
Error: a0 = 0x5
Error: a1 = 0xffffffff
Error: a2 = 0x40804780
Error: a3 = 0x0
Error: a4 = 0x8
Error: a5 = 0x8
Error: a6 = 0x0
Error: a7 = 0x40801064
Error: s2 = 0x0
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 = 0x40800000
Error: mstatus = 0x1800
Error: mepc = 0x40800000
Error: mcause = 0x5
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)!
Error: Target is already running an algorithm
Error: Failed to start algorithm (-4)!
Error: Failed to run flasher stub (-4)!
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