lock_acquire_generic

Vaibhav02
Posts: 7
Joined: Wed Sep 04, 2024 8:09 am

lock_acquire_generic

Postby Vaibhav02 » Mon Dec 09, 2024 7:14 am

I am trying to erasing nvs on gpio ISR. I have write the below code.

Code: Select all

static void IRAM_ATTR gpio_isr_handler(void *arg)
{
    uint32_t current_time = xTaskGetTickCountFromISR();
    // Debounce: Only process if enough time has passed since the last interrupt
    if ((current_time - last_interrupt_time) > (3000 / portTICK_PERIOD_MS))
    {
        // button_state = true;
        esp_err_t err = nvs_flash_erase();
    
        if (err == ESP_OK) {
            ESP_LOGI("NVS", "NVS flash erased successfully.");
        } else {
            ESP_LOGE("NVS", "Failed to erase NVS flash: %s", esp_err_to_name(err));
        }
        last_interrupt_time = current_time;
    }
}
Below error comes to me for above code. How can I resolve this error.

Code: Select all


abort() was called at PC 0x40082edf on core 0
--- 0x40082edf: lock_acquire_generic at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/newlib/locks.c:133



Backtrace: 0x40081e0a:0x3ffb1b20 0x4008aa05:0x3ffb1b40 0x40092f55:0x3ffb1b60 0x40082edf:0x3ffb1bd0 0x4008301d:0x3ffb1c00 0x400830aa:0x3ffb1c20 0x4017e74e:0x3ffb1c50 0x40171c09:0x3ffb1f70 0x4018e435:0x3ffb1fa0 0x400918b9:0x3ffb1fd0 0x400831a9:0x3ffb2020 0x40083799:0x3ffb2040 0x4008386b:0x3ffb2070 0x40083545:0x3ffb20a0 0x40089723:0x3ffbbe70 0x400d47c3:0x3ffbbe90 0x4008c5d5:0x3ffbbeb0 0x4008b511:0x3ffbbed0
--- 0x40081e0a: panic_abort at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/esp_system/panic.c:463
0x4008aa05: esp_system_abort at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/esp_system/port/esp_system_chip.c:92
0x40092f55: abort at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/newlib/abort.c:38
0x40082edf: lock_acquire_generic at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/newlib/locks.c:133
0x4008301d: _lock_acquire_recursive at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/newlib/locks.c:162
0x400830aa: __retarget_lock_acquire_recursive at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/newlib/locks.c:321
0x4017e74e: _vfprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp-elf/src/newlib/newlib/libc/stdio/vfprintf.c:846 (discriminator 2)
0x40171c09: vprintf at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp-elf/src/newlib/newlib/libc/stdio/vprintf.c:34
0x4018e435: esp_log_writev at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/log/log.c:210
0x400918b9: esp_log_write at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/log/log.c:220
0x400831a9: gpio_isr_handler at C:/Users/Admin/Desktop/gateway/main/wifi.c:168 (discriminator 1)
0x40083799: gpio_isr_loop at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/esp_driver_gpio/src/gpio.c:4660x4008386b: gpio_intr_service at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/esp_driver_gpio/src/gpio.c:496
0x40083545: _xt_lowint1 at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/xtensa/xtensa_vectors.S:1240
0x40089723: xt_utils_wait_for_intr at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/xtensa/include/xt_utils.h:82
 (inlined by) esp_cpu_wait_for_intr at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/esp_hw_support/cpu.c:55
0x400d47c3: esp_vApplicationIdleHook at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/esp_system/freertos_hooks.c:58
0x4008c5d5: prvIdleTask at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/freertos/FreeRTOS-Kernel/tasks.c:4344 (discriminator 1)
0x4008b511: vPortTaskWrapper at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134





ELF file SHA256: 1a4a2a846

Rebooting...
I (13) boot: ESP-IDF v5.3-dirty 2nd stage bootloader
I (13) boot: compile time Dec  5 2024 15:23:00
I (13) boot: Multicore bootloader

ESP_Sprite
Posts: 9835
Joined: Thu Nov 26, 2015 4:08 am

Re: lock_acquire_generic

Postby ESP_Sprite » Mon Dec 09, 2024 7:26 am

There's very little you can do in an ISR; specifically you can't do anything that can block, and I guess NVS calls can block. The way to solve this is to use the ISR to set something (a semaphore, task notification, whatever) that signals code running in an actual task (not in an ISR) to do the erase.

MicroController
Posts: 1821
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: lock_acquire_generic

Postby MicroController » Mon Dec 09, 2024 10:52 am

Code: Select all

0x400918b9: esp_log_write at C:/Users/Admin/.espressif/frameworks/esp-idf-v5.3/components/log/log.c:220
I guess logging may block too ("This function or these macros should not be used from an interrupt.").
If you really have to log from an ISR, consider using ESP_EARLY_LOGx() or esp_rom_printf().

Who is online

Users browsing this forum: Majestic-12 [Bot] and 81 guests