ESP32-C3 and GDBGUI: breaks when enters my custom ecall

User avatar
EUtrilla2002
Posts: 18
Joined: Mon Mar 31, 2025 10:23 am

ESP32-C3 and GDBGUI: breaks when enters my custom ecall

Postby EUtrilla2002 » Tue Sep 16, 2025 7:34 am

Hi
As you can see in my profile, i'm trying to add a debug program in a board with a custom panic handler
Some of this entries make the CPU wait. For example this one

Code: Select all

int read_int(){

    unsigned char c;
    char buffer[16]; 
    int idx = 0;
    while(1){
        //while (!uart_rx_one_char(uart_no, &c)) { }
        c = uart_rx_one_char_block();
        // Check the char added

        //Is an space?? Finish it!!
        if (c == '\n' || c == '\r') {
            buffer[idx] = '\0';
            esp_rom_printf("\n"); //echo
            break;
        }
        //It is a number? add it!
        if (isdigit(c)) {
            if (idx < sizeof(buffer) - 1) {
                
                buffer[idx++] = c;
                esp_rom_printf("%c", c);
            }
        }
        //is another char? Ignore it

    }
    //Transform into number
    int value = 0;
    for (int i = 0; buffer[i] != '\0'; i++) {
        value = value * 10 + (buffer[i] - '0');
    }

    return value;

}
However, when i want to debug a proigram in gdbgui monitor,the first time the page appears it breaks. Here is the openocd log

Code: Select all

Open On-Chip Debugger v0.12.0-esp32-20241016 (2024-10-16-14:17)
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
Info : esp_usb_jtag: serial (58:CF:79:16:81:90)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 40000 kHz
Info : JTAG tap: esp32c3.tap0 tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : [esp32c3] datacount=2 progbufsize=16
Info : [esp32c3] Examined RISC-V core; found 1 harts
Info : [esp32c3]  XLEN=32, misa=0x40101104
Info : [esp32c3] Examination succeed
Info : [esp32c3] starting gdb server on 3333
Info : Listening on port 3333 for gdb connections
Info : JTAG tap: esp32c3.tap0 tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : [esp32c3] Reset cause (3) - (Software core reset)
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: libusb_bulk_write error: LIBUSB_ERROR_NO_DEVICE
Error: libusb_open() failed with LIBUSB_ERROR_NO_DEVICE
Error: esp_usb_jtag: device not found!
Error: esp_usb_jtag: failed to revive USB device!
Error: missing data from bitq interface
Error: dmi_scan failed jtag scan
Error: libusb_bulk_write error: LIBUSB_ERROR_NO_DEVICE
Error: esp_usb_jtag: device not found!
Error: esp_usb_jtag: failed to revive USB device!
Error: missing data from bitq interface
Error: failed jtag scan: -104
Error: [esp32c3] Failed DMI read at 0x11; status=2
Error: [esp32c3] polling failed!
Error: libusb_bulk_write error: LIBUSB_ERROR_NO_DEVICE
Info : esp_usb_jtag: serial (58:CF:79:16:81:90)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Error: missing data from bitq interface
Error: dmi_scan failed jtag scan
Error: [esp32c3] Failed DMI read at 0x11; status=2
Error: [esp32c3] polling failed!
Info : [esp32c3] Hart unexpectedly reset!
Info : [esp32c3] Reset cause (1) - (Chip reset)
Info : accepting 'gdb' connection on tcp/3333
Info : [esp32c3] Target halted, PC=0x4004C500, debug_reason=00000000
Info : [esp32c3] Halt cause (11) - (ECALL from M mode)
Warn : No symbols for FreeRTOS!
Info : [esp32c3] Found 8 triggers
Info : Flash mapping 0: 0x10020 -> 0x3c020020, 38 KB
Info : Flash mapping 1: 0x20020 -> 0x42000020, 90 KB
Info : Auto-detected flash bank 'esp32c3.flash' size 4096 KB
Info : Using flash bank 'esp32c3.flash' size 4096 KB
Info : Flash mapping 0: 0x10020 -> 0x3c020020, 38 KB
Info : Flash mapping 1: 0x20020 -> 0x42000020, 90 KB
Info : Using flash bank 'esp32c3.irom' size 92 KB
Info : Flash mapping 0: 0x10020 -> 0x3c020020, 38 KB
Info : Flash mapping 1: 0x20020 -> 0x42000020, 90 KB
Info : Using flash bank 'esp32c3.drom' size 40 KB
Info : Detected FreeRTOS version: (10.5.1)
Info : JTAG tap: esp32c3.tap0 tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : [esp32c3] Reset cause (3) - (Software core reset)
Info : dropped 'gdb' connection
Info : [esp32c3] Target halted, PC=0x420090CC, debug_reason=00000001
It's strange because there are other entries in my ecall panic handler ant does not show this problems

Is there something that i could do??
thx

User avatar
EUtrilla2002
Posts: 18
Joined: Mon Mar 31, 2025 10:23 am

Re: ESP32-C3 and GDBGUI: breaks when enters my custom ecall

Postby EUtrilla2002 » Thu Sep 25, 2025 11:45 am

Hi, i finally solved it.

For instance, if you try to make the CPU wait for longer than 1 seg, it crashes in GDB. For instance, y made a "busy wait"
Here is an example

Code: Select all

char read_buffer_char(){
    unsigned char c = '\0';
    //esp_rom_printf("Value: %c",c);

    uart_rx_one_char(&c);
    if (c != '\0') {
        esp_rom_printf("%c", c);
        return c;
    }
    else{ return '\0'; }
    
    return -1;
}

char read_char() {
    char value = '\0';
    int sum =0;
    while (value == '\0'){
        value =   read_buffer_char(); 
        if (value == '\0'){
            for (int x =1;x< 1000; x++){
                sum ++;

            }
        }
    }
    return value;
}
Maybe there's a more elegant way to solve this???

Who is online

Users browsing this forum: Applebot, Barkrowler, coccocbot, Google [Bot], meta-externalagent, trendictionbot and 4 guests