espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.71k stars 7.43k forks source link

EEPROM/nvs driver crash with GPTimer interrupt #10536

Open dzungpv opened 3 weeks ago

dzungpv commented 3 weeks ago

Board

ESP32 Dev Module

Device Description

ESP32 Dev Module connect to TP Uart module.

Hardware Configuration

Software UART with GPTimer on pin 18 and 26.

Version

v3.0.6

IDE Name

VS, Arduino as ESP IDF (5.1.x)

Operating System

macOS 14.7

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

115200

Description

When read or write to flash, it will crash. I have user GPTimer to read and write using gpio_get_level/gpio_set_level

Core  1 register dump:
PC      : 0x40148fd8  PS      : 0x00060035  A0      : 0x80089c33  A1      : 0x3ffc0d90  
--- 0x40148fd8: gpio_get_level at /Users/vietdzung/esp/esp-idf-v5.1.4/components/driver/gpio/gpio.c:244

A2      : 0x3ffc5ab8  A3      : 0x3ffc0dc0  A4      : 0x00000000  A5      : 0x00060023  
A6      : 0xb33fffff  A7      : 0xb33fffff  A8      : 0x80084074  A9      : 0x3ffc0d90  
A10     : 0x0000001a  A11     : 0x00060023  A12     : 0x00060021  A13     : 0x3ffd9b40  
A14     : 0x3ffc0f44  A15     : 0x00000000  SAR     : 0x00000020  EXCCAUSE: 0x00000007  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000  
--- 0x4000c2e0: memcpy in ROM
0x4000c2f6: memcpy in ROM

Seem crash cause by interrupt when reading/writing to nvs flash, I search everywhere but not find any solution.

Crash occure after call code: EEPROM.commit()

Sketch

Sample code:

https://github.com/thelsing/knx/blob/master/examples/knx-demo-diy/knx-demo-diy.ino

interrupt using GPTimer driver:

static bool IRAM_ATTR baud_timer_handler(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_ctx) {
    static uint8_t bitcounter = 0;
    static uint32_t inputbuffer = 0;
    static uint32_t outputbuffer = 0;

    BaseType_t xHigherPriorityTaskWoken = pdFALSE;

    /* Shift the received bit into the buffer */
    inputbuffer <<= 1;
    inputbuffer |= (gpio_get_level(hb_rx_pin) & 0x01);
...
}

### Debug Message

```plain
Full crash and stack trace:

Core  1 register dump:
PC      : 0x40148fd8  PS      : 0x00060035  A0      : 0x80089c33  A1      : 0x3ffc0d90  
--- 0x40148fd8: gpio_get_level at /Users/vietdzung/esp/esp-idf-v5.1.4/components/driver/gpio/gpio.c:244

A2      : 0x3ffc5ab8  A3      : 0x3ffc0dc0  A4      : 0x00000000  A5      : 0x00060023  
A6      : 0xb33fffff  A7      : 0xb33fffff  A8      : 0x80084074  A9      : 0x3ffc0d90  
A10     : 0x0000001a  A11     : 0x00060023  A12     : 0x00060021  A13     : 0x3ffd9b40  
A14     : 0x3ffc0f44  A15     : 0x00000000  SAR     : 0x00000020  EXCCAUSE: 0x00000007  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000  
--- 0x4000c2e0: memcpy in ROM
0x4000c2f6: memcpy in ROM

Backtrace: 0x40148fd5:0x3ffc0d90 0x40089c30:0x3ffc0dc0 0x4008348d:0x3ffc0df0 0x4000bff0:0x3ffd9ab0 0x4008d5ae:0x3ffd9ac0 0x40084ecc:0x3ffd9ae0 0x40085d07:0x3ffd9b00 0x40085d12:0x3ffd9b20 0x40089a9d:0x3ffd9b40 0x40085723:0x3ffd9b60 0x4014fc46:0x3ffd9ba0 0x4015496f:0x3ffd9bd0 0x401d9846:0x3ffd9bf0 0x401556fe:0x3ffd9c10 0x4015399e:0x3ffd9c70 0x40153a1a:0x3ffd9cc0 0x4015447e:0x3ffd9d30 0x401547bd:0x3ffd9da0 0x40153357:0x3ffd9dc0 0x4012c54f:0x3ffd9df0 0x4011adf7:0x3ffd9e10 0x40121e3b:0x3ffd9e30 0x40121666:0x3ffd9e50 0x4011c305:0x3ffd9ee0 0x40125601:0x3ffd9f10 0x40125e0f:0x3ffd9f80 0x40125e26:0x3ffd9fa0 0x40123f08:0x3ffd9fc0 0x40124299:0x3ffd9fe0 0x40121b31:0x3ffda010 0x401d785a:0x3ffda030 0x4011cc49:0x3ffda060 0x40122fcf:0x3ffda0a0 0x40123666:0x3ffda1f0 0x40123a05:0x3ffda210 0x40123aff:0x3ffda230 0x4011b6c5:0x3ffda250 0x400df429:0x3ffda270 0x400e1010:0x3ffda290 0x4008c76a:0x3ffda2b0
--- 0x40148fd5: gpio_set_level at /Users/vietdzung/esp/esp-idf-v5.1.4/components/driver/gpio/gpio.c:241
0x40089c30: gptimer_default_isr at /Users/vietdzung/esp/esp-idf-v5.1.4/components/driver/gptimer/gptimer.c:518
0x4008348d: _xt_lowint1 at /Users/vietdzung/esp/esp-idf-v5.1.4/components/freertos/FreeRTOS-Kernel/portable/xtensa/xtensa_vectors.S:1240
0x4000bff0: _xtos_set_intlevel in ROM
0x4008d5ae: vPortClearInterruptMaskFromISR at /Users/vietdzung/esp/esp-idf-v5.1.4/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:568
 (inlined by) xTaskGetSchedulerState at /Users/vietdzung/esp/esp-idf-v5.1.4/components/freertos/FreeRTOS-Kernel/tasks.c:5175
0x40084ecc: spi_flash_enable_interrupts_caches_and_other_cpu at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/cache_utils.c:234
0x40085d07: cache_enable at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/spi_flash_os_func_app.c:65
0x40085d12: spi1_end at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/spi_flash_os_func_app.c:140
0x40089a9d: spiflash_end_default at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/esp_flash_api.c:202
0x40085723: esp_flash_read at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/esp_flash_api.c:905
0x4014fc46: esp_partition_read at /Users/vietdzung/esp/esp-idf-v5.1.4/components/esp_partition/partition_target.c:38
0x4015496f: nvs::NVSPartition::read(unsigned int, void*, unsigned int) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_partition.cpp:45
0x401d9846: nvs::Page::readEntry(unsigned int, nvs::Item&) const at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_page.cpp:853
0x401556fe: nvs::Page::findItem(unsigned char, nvs::ItemType, char const*, unsigned int&, nvs::Item&, unsigned char, nvs::VerOffset) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_page.cpp:906
0x4015399e: nvs::Storage::findItem(unsigned char, nvs::ItemType, char const*, nvs::Page*&, nvs::Item&, unsigned char, nvs::VerOffset) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_storage.cpp:248
0x40153a1a: nvs::Storage::cmpMultiPageBlob(unsigned char, char const*, void const*, unsigned int) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_storage.cpp:620
0x4015447e: nvs::Storage::writeItem(unsigned char, nvs::ItemType, char const*, void const*, unsigned int) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_storage.cpp:389
0x401547bd: nvs::NVSHandleSimple::set_blob(char const*, void const*, unsigned int) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_handle_simple.cpp:52
0x40153357: nvs_set_blob at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_api.cpp:426
0x4012c54f: EEPROMClass::commit() at /Users/vietdzung/dev/projects/esp32/sdks/5.1.4/arduino-esp32/libraries/EEPROM/src/EEPROM.cpp:179
0x4011adf7: Esp32Platform::commitToEeprom() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/esp32_platform.cpp:172
0x40121e3b: Platform::commitNonVolatileMemory() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/platform.cpp:201
0x40121666: Memory::writeMemory() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/memory.cpp:194
0x4011c305: BauSystemB::restartRequestIndication(Priority, HopCountType, unsigned short, SecurityControl const&, RestartType, EraseCode, unsigned char) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/bau_systemB.cpp:234
0x40125601: ApplicationLayer::individualIndication(HopCountType, Priority, unsigned short, APDU&, SecurityControl const&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/application_layer.cpp:1140
0x40125e0f: ApplicationLayer::dataConnectedIndication(Priority, unsigned short, APDU&, SecurityControl const&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/application_layer.cpp:380
0x40125e26: ApplicationLayer::dataConnectedIndication(Priority, unsigned short, APDU&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/application_layer.cpp:375
0x40123f08: TransportLayer::A2(unsigned short, Priority, APDU&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/transport_layer.cpp:664
0x40124299: TransportLayer::dataIndividualIndication(unsigned short, HopCountType, Priority, unsigned short, TPDU&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/transport_layer.cpp:58
0x40121b31: NetworkLayerDevice::dataIndication(AckType, AddressType, unsigned short, FrameFormat, NPDU&, Priority, unsigned short, unsigned char) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/network_layer_device.cpp:84
0x401d785a: NetworkLayerEntity::dataIndication(AckType, AddressType, unsigned short, FrameFormat, NPDU&, Priority, unsigned short) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/network_layer_entity.cpp:38
0x4011cc49: DataLinkLayer::frameReceived(CemiFrame&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/data_link_layer.cpp:196
0x40122fcf: TpUartDataLinkLayer::rxFrameReceived(TpFrame*) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:973
0x40123666: TpUartDataLinkLayer::processRxFrame(TpFrame*) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:1158
 (inlined by) TpUartDataLinkLayer::processRxFrameComplete() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:534
0x40123a05: TpUartDataLinkLayer::processRxByte() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:306
0x40123aff: TpUartDataLinkLayer::processRx(bool) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:172
 (inlined by) TpUartDataLinkLayer::processRx(bool) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:156
 (inlined by) TpUartDataLinkLayer::loop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:948
 (inlined by) TpUartDataLinkLayer::loop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:925
0x4011b6c5: Bau07B0::loop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/bau07B0.cpp:140
0x400df429: KnxFacade<Esp32Platform, Bau07B0>::loop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx_facade.h:242
 (inlined by) knxLoop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/main/app_knx.h:287
0x400e1010: knxTask(void*) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/main/app_knx.h:210
0x4008c76a: vPortTaskWrapper at /Users/vietdzung/esp/esp-idf-v5.1.4/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

Decode with https://maximeborges.github.io/esp-stacktrace-decoder/

0x40148fd8: gpio_get_level at /Users/vietdzung/esp/esp-idf-v5.1.4/components/driver/gpio/gpio.c:244
0x40148fd8: gpio_get_level at /Users/vietdzung/esp/esp-idf-v5.1.4/components/driver/gpio/gpio.c:244
0x40148fd5: gpio_set_level at /Users/vietdzung/esp/esp-idf-v5.1.4/components/driver/gpio/gpio.c:241
0x40089c30: gptimer_default_isr at /Users/vietdzung/esp/esp-idf-v5.1.4/components/driver/gptimer/gptimer.c:518
0x4008d5ae: vPortClearInterruptMaskFromISR at /Users/vietdzung/esp/esp-idf-v5.1.4/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:568
0x4008d5ae: xTaskGetSchedulerState at /Users/vietdzung/esp/esp-idf-v5.1.4/components/freertos/FreeRTOS-Kernel/tasks.c:5175
0x40084ecc: spi_flash_enable_interrupts_caches_and_other_cpu at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/cache_utils.c:234
0x40085d07: cache_enable at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/spi_flash_os_func_app.c:65
0x40085d12: spi1_end at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/spi_flash_os_func_app.c:140
0x40089a9d: spiflash_end_default at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/esp_flash_api.c:202
0x40085723: esp_flash_read at /Users/vietdzung/esp/esp-idf-v5.1.4/components/spi_flash/esp_flash_api.c:905
0x4014fc46: esp_partition_read at /Users/vietdzung/esp/esp-idf-v5.1.4/components/esp_partition/partition_target.c:38
0x4015496f: nvs::NVSPartition::read(unsigned int, void*, unsigned int) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_partition.cpp:45
0x401d9846: nvs::Page::readEntry(unsigned int, nvs::Item&) const at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_page.cpp:853
0x401556fe: nvs::Page::findItem(unsigned char, nvs::ItemType, char const*, unsigned int&, nvs::Item&, unsigned char, nvs::VerOffset) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_page.cpp:906
0x4015399e: nvs::Storage::findItem(unsigned char, nvs::ItemType, char const*, nvs::Page*&, nvs::Item&, unsigned char, nvs::VerOffset) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_storage.cpp:248
0x40153a1a: nvs::Storage::cmpMultiPageBlob(unsigned char, char const*, void const*, unsigned int) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_storage.cpp:620
0x4015447e: nvs::Storage::writeItem(unsigned char, nvs::ItemType, char const*, void const*, unsigned int) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_storage.cpp:389
0x401547bd: nvs::NVSHandleSimple::set_blob(char const*, void const*, unsigned int) at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_handle_simple.cpp:52
0x40153357: nvs_set_blob at /Users/vietdzung/esp/esp-idf-v5.1.4/components/nvs_flash/src/nvs_api.cpp:426
0x4012c54f: EEPROMClass::commit() at /Users/vietdzung/dev/projects/esp32/sdks/5.1.4/arduino-esp32/libraries/EEPROM/src/EEPROM.cpp:179
0x4011adf7: Esp32Platform::commitToEeprom() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/esp32_platform.cpp:172
0x40121e3b: Platform::commitNonVolatileMemory() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/platform.cpp:201
0x40121666: Memory::writeMemory() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/memory.cpp:194
0x4011c305: BauSystemB::restartRequestIndication(Priority, HopCountType, unsigned short, SecurityControl const&, RestartType, EraseCode, unsigned char) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/bau_systemB.cpp:234
0x40125601: ApplicationLayer::individualIndication(HopCountType, Priority, unsigned short, APDU&, SecurityControl const&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/application_layer.cpp:1140
0x40125e0f: ApplicationLayer::dataConnectedIndication(Priority, unsigned short, APDU&, SecurityControl const&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/application_layer.cpp:380
0x40125e26: ApplicationLayer::dataConnectedIndication(Priority, unsigned short, APDU&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/application_layer.cpp:375
0x40123f08: TransportLayer::A2(unsigned short, Priority, APDU&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/transport_layer.cpp:664
0x40124299: TransportLayer::dataIndividualIndication(unsigned short, HopCountType, Priority, unsigned short, TPDU&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/transport_layer.cpp:58
0x40121b31: NetworkLayerDevice::dataIndication(AckType, AddressType, unsigned short, FrameFormat, NPDU&, Priority, unsigned short, unsigned char) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/network_layer_device.cpp:84
0x401d785a: NetworkLayerEntity::dataIndication(AckType, AddressType, unsigned short, FrameFormat, NPDU&, Priority, unsigned short) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/network_layer_entity.cpp:38
0x4011cc49: DataLinkLayer::frameReceived(CemiFrame&) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/data_link_layer.cpp:196
0x40122fcf: TpUartDataLinkLayer::rxFrameReceived(TpFrame*) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:973
0x40123666: TpUartDataLinkLayer::processRxFrame(TpFrame*) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:1158
0x40123666: TpUartDataLinkLayer::processRxFrameComplete() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:534
0x40123a05: TpUartDataLinkLayer::processRxByte() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:306
0x40123aff: TpUartDataLinkLayer::processRx(bool) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:172
0x40123aff: TpUartDataLinkLayer::processRx(bool) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:156
0x40123aff: TpUartDataLinkLayer::loop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:948
0x40123aff: TpUartDataLinkLayer::loop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/tpuart_data_link_layer.cpp:925
0x4011b6c5: Bau07B0::loop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx/bau07B0.cpp:140
0x400df429: KnxFacade::loop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/components/knx/src/knx_facade.h:242
0x400df429: knxLoop() at /Users/vietdzung/dev/projects/esp32/sample_app_knx/main/app_knx.h:287
0x400e1010: knxTask(void*) at /Users/vietdzung/dev/projects/esp32/sample_app_knx/main/app_knx.h:210
0x4008c76a: vPortTaskWrapper at /Users/vietdzung/esp/esp-idf-v5.1.4/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162


### Other Steps to Reproduce

_No response_

### I have checked existing issues, online documentation and the Troubleshooting Guide

- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.