-1

I am using Eclipse with ESP-IDF 5.0.2 to develop for ESP32 C3. In this code, esp_wifi_set_config call always fails because WiFi is not initialized.

#include <stdio.h>

#include "esp_wifi.h"

void app_main(void) {
    printf("hello\n");

    wifi_config_t wifi_details = {
        .sta = {
            .ssid = "wifissid",
            .password = "wifipwd",
        },
    };
    int err = esp_wifi_set_config(WIFI_IF_STA, &wifi_details);
    if (err != 0) {
        printf("WiFi set details failed: %s\n", esp_err_to_name(err));
        exit(1);
    }
}

The output however looks like this:

hello
WiFi set details failed: ESP_ERR_WIFI_NOT_INIT

abort() was called at PC 0x42003889 on core 0
0x42003889: syscall_not_implemented_aborts at C:/esp-idf/esp-idf-v5.0.2/components/newlib/syscalls.c:27

Core  0 register dump:
MEPC    : 0x4038084c  RA      : 0x403840d0  SP      : 0x3fc91300  GP      : 0x3fc8b600
0x4038084c: panic_abort at C:/esp-idf/esp-idf-v5.0.2/components/esp_system/panic.c:423

0x403840d0: __ubsan_include at C:/esp-idf/esp-idf-v5.0.2/components/esp_system/ubsan.c:313

TP      : 0x3fc8960c  T0      : 0x37363534  T1      : 0x7271706f  T2      : 0x33323130
S0/FP   : 0x00000004  S1      : 0x3fc91364  A0      : 0x3fc9132c  A1      : 0x3fc91362
A2      : 0x00000000  A3      : 0x3fc91359  A4      : 0x00000001  A5      : 0x3fc8e000
A6      : 0x7a797877  A7      : 0x76757473  S2      : 0x00000000  S3      : 0x00000000
S4      : 0x00000000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000
T3      : 0x6e6d6c6b  T4      : 0x6a696867  T5      : 0x66656463  T6      : 0x62613938
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000007  MTVAL   : 0x00000000
0x40380001: _vector_table at ??:?

MHARTID : 0x00000000

Stack memory:
3fc91300: 0x00000000 0x3fc8c60c 0x3fc91360 0x403894b8 0x00000000 0x3fc8c60c 0x3fc8edc0 0x3fc8b50c
0x403894b8: abort at C:/esp-idf/esp-idf-v5.0.2/components/newlib/abort.c:35 (discriminator 3)

3fc91320: 0x3fc91364 0x3fc8b528 0x3fc91360 0x726f6261 0x20292874 0x20736177 0x6c6c6163 0x61206465
3fc91340: 0x43502074 0x34783020 0x33303032 0x20393838 0x63206e6f 0x2065726f 0x00000030 0x42000000
3fc91360: 0x00000030 0x30303234 0x39383833 0x00000000 0x00000000 0x00000000 0x00000001 0x4200388c
0x4200388c: newlib_include_syscalls_impl at C:/esp-idf/esp-idf-v5.0.2/components/newlib/syscalls.c:161

3fc91380: 0x00000000 0x00000000 0x00000001 0x4200b43e 0x0000003a 0x3c0244e8 0x00000000 0x420063a6
0x4200b43e: _fclose_r at ??:?

0x420063a6: riscv_decode_offset_from_jal_instruction at C:/esp-idf/esp-idf-v5.0.2/components/riscv/instruction_decode.c:34

3fc913a0: 0x00000804 0x69666977 0x64697373 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc913c0: 0x00000000 0x69666977 0x00647770 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc913e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc91400: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc91420: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x42015232
0x42015232: main_task at C:/esp-idf/esp-idf-v5.0.2/components/freertos/FreeRTOS-Kernel/portable/port_common.c:132 (discriminator 2)

3fc91440: 0x00000000 0x00001388 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000 0x40386544
0x40386544: vPortTaskWrapper at C:/esp-idf/esp-idf-v5.0.2/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:131

3fc91460: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc91480: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x00000154 0x3fc913e0 0x3fc8e304 0x3fc8c328
3fc914a0: 0x3fc8c328 0x3fc91494 0x3fc8c320 0x00000018 0x13e9b397 0xd9d9b153 0x3fc91494 0x00000000
3fc914c0: 0x00000001 0x3fc90490 0x6e69616d 0x37f11b00 0x5db4bd0d 0x00b999a0 0x00000000 0x3fc91480
3fc914e0: 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc8ecf0 0x3fc8ed58 0x3fc8edc0
3fc91500: 0x00000000 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000 0x4200b818 0x00000000
0x4200b818: _cleanup_r at ??:?

3fc91520: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc91540: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc91560: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc91580: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc915a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc915c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc915e0: 0x00000000 0x3f000000 0x00000600 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc91600: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc91620: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc91640: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc91660: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc91680: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc916a0: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc916c0: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc916e0: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5

What I want the output to be:

hello
WiFi set details failed: ESP_ERR_WIFI_NOT_INIT

How do I disable the core register dump? What other options do I have to see the my output only in the serial monitor?

I tried:

  • Setting the panic handler to various options in sdkconfig/menuconfig.
    • Halt-only behavior isn't an option.
    • Silent reboot causes more output because of reboot and init.
    • GDB mode on panic prints the dump.
    • GDB mode at runtime cannot be used probably because I am using UART0 for something else (in real code). The error is uart: uart_driver_install(1559): UART used by GDB-stubs! Please disable GDB in menuconfig.
  • Entering deep sleep instead of exit(1) is good, but disconnects the ESP32 from virtual serial port so a button must be used to enter flash mode on next reboot.
  • while(1) { printf("the error: ..."); } works but I cannot see previous program output.
  • sleep(100000) doesn't stop other FreeRTOS tasks from printing. Issuing vTaskEndScheduler() or vTaskSuspendAll() right before it doesn't seem to work (in real code).
  • vTaskSuspendAll(); while(1) {}; works, but triggers the watchdog timer. Disabling WDT globally is not recommended. Feeding the watchdog in the while loop, if it ends up working, is a bit too complex.
mik13ST
  • 95
  • 7
  • 2
    Why not fix what's making the unimplemented syscall? – stark May 31 '23 at 10:39
  • This is related to error handling in general, not to this specific error. – mik13ST May 31 '23 at 10:47
  • 2
    For an error which is too serious to continue, printing a dump with the information to fix it is the appropriate response. Why should there be a way to turn that off? – stark May 31 '23 at 10:55
  • As a beginner, I don't know how to read the dump and the error message is all I need to resolve the issue typically. Or at least I want to see the error first and having to scroll over the entire dump is tedious. – mik13ST May 31 '23 at 11:35
  • Oh, `exit()` is not implemented. The core dump is so big I never bothered reading it. I should have noticed that earlier. – mik13ST May 31 '23 at 16:25

2 Answers2

2

The "spam" is not from WiFi configuration failing. It's from the call to exit(1); - there is no exit from the main function of embedded firmware :)

Usually errors that raise a panic are not subject to error handling, they indicate an abnormal condition that should be fixed immediately. In this case, the syscall exit(); is simply not supported, so you cannot call it.

As for the verbose output, most of this is ESP IDF exception decoder at work. The micro itself only prints the few lines with encoded stack information. The python script that filters the serial output decodes it and fills in the details using the elf file. See this section in the IDF Monitor documentation on how to disable it. I don't know how to apply this fix to the Eclipse environment, but I personally want to see the full stack trace in such situations to figure out what went wrong and fix it ASAP.

Tarmo
  • 3,728
  • 1
  • 8
  • 25
  • I thought the error is caused by the core exiting, not caused by the `exit()` not being implemented. Thanks for pointing that out. As for the IDF monitor decoding, I still consider the non-decoded output too verbose. – mik13ST May 31 '23 at 16:29
0

I later settled on this:

void halt() {
    esp_task_wdt_deinit(); // Disable global WDT.
    vTaskSuspendAll(); // Suspend all other RTOS tasks.
    while (1) {} // Loop forever.
}

void main() {
    ...
    if (err != 0) {
        printf("WiFi set details failed: %s\n", esp_err_to_name(err));
        halt();
    }

The pros:

  • doesn't produce more output than the message itself
  • allows seeing the previous output
  • doesn't disconnect the ESP module
  • doesn't trigger WDT
  • doesn't require WDT disabled globally
  • seems to work from inside an RTOS task as well as from main()

The cons:

  • not a single call
mik13ST
  • 95
  • 7