SPI Flash Write Errors After Porting Project from ESP-IDF v4.1 to v4.4

PeterG76
Posts: 17
Joined: Wed May 25, 2022 10:25 am

SPI Flash Write Errors After Porting Project from ESP-IDF v4.1 to v4.4

Postby PeterG76 » Wed Nov 16, 2022 11:29 am

I have inherited a project that was built using ESP-IDF v4.1-beta2 and ported it to ESP-IDF v4.4. This involved migrating from minGW build system to CMake and Windows CMD/Visual Studio Code. The project mostly builds and runs once I had fixed some I2C initialization errors due to new parameters in the context. Target hardware is using SoC ESP32-WROVER-E

However I am having issues writing and closing a settings.ini file on the /spiflash 'storage' partition. It mounts OK (using the SPI flash wear levelling API) and I can open and read the settings.ini file OK. But I'm getting errors either writing (fprintf) or closing (fclose) the file. Sometimes the app just restarts with no useful debug and other times it reports the following.
Saving "language": 0
Saving "isDialLeft": true
Saving "isTemperatureCelsius": false
Saving "isNightMode": true
Saving "NightModeBrightness": 75
Saving "DayModeBrightness": 19
Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed).

Core 1 register dump:
PC : 0x401dcd04 PS : 0x00060034 A0 : 0x80083bd5 A1 : 0x3ffb1150
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x3ffb1680 A5 : 0x3ffc9310
A6 : 0x00000026 A7 : 0x3ffb5928 A8 : 0x80083b08 A9 : 0x00000000
A10 : 0x3ffb1680 A11 : 0x00000000 A12 : 0x00000000 A13 : 0x00000800
A14 : 0x00000000 A15 : 0x1300004c SAR : 0x00000018 EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000

Backtrace:0x401dcd01:0x3ffb11500x40083bd2:0x3ffb1180 0x40083069:0x3ffb11b0 0x4008c7e8:0x3ffc92e0 0x4008c586:0x3ffc9300 0x40092a99:0x3ffc9330 0x40085a87:0x3ffc93b0 0x401831fd:0x3ffc93f0 0x4016fa92:0x3ffc9420 0x40171267:0x3ffc9440 0x4016fbab:0x3ffc9480 0x40171503:0x3ffc94d0 0x4016f90f:0x3ffc9510 0x4016c157:0x3ffc9530 0x4016c035:0x3ffc9550 0x4016c49e:0x3ffc9570 0x4016c4e4:0x3ffc9590 0x4016ca29:0x3ffc95b0 0x4016cc28:0x3ffc95d0 0x4016d659:0x3ffc95f0 0x4016f3bf:0x3ffc9630 0x400d4581:0x3ffc9660 0x4000bd83:0x3ffc9680 0x4000117d:0x3ffc96a0 0x400592fe:0x3ffc96c0 0x4005937a:0x3ffc96e0 0x40058ad3:0x3ffc9700 0x401d4b8f:0x3ffc9730 0x401cc006:0x3ffc9750 0x401c0d19:0x3ffc9a60 0x4010dccd:0x3ffc9ab0 0x4010df65:0x3ffc9ce0 0x400f9cf9:0x3ffc9d10 0x401da955:0x3ffc9d40 0x401b59d9:0x3ffc9d60 0x400d27c4:0x3ffc9d80 0x4008b7f9:0x3ffc9da0

ELF file SHA256: 92dd71dce0d5f2e2

Rebooting...
I've compiled and built the simple wear_levelling example from the ESP-IDF and run it on our target hardware and that works OK. If I use the code from the app_main() in the wear_levelling example to read and write the hello.txt file in our app it also fails. Mounting is done at app start up which succeeds.

So it feels like I have some kind of configuration issue in our project with regard to the SPI Flash FAT API, given the simple wear_levelling example works on the same hardware.

I've tried using the same partitions_example.csv in my project (I did have to increase the factory partition because the app was too big) but that fails too.

Any suggestions would be much appreciated.

ESP_Mahavir
Posts: 190
Joined: Wed Jan 24, 2018 6:51 am

Re: SPI Flash Write Errors After Porting Project from ESP-IDF v4.1 to v4.4

Postby ESP_Mahavir » Thu Nov 17, 2022 4:06 am

What is the backtrace if you run your application through idf_monitor.py? Please refer to: https://docs.espressif.com/projects/esp ... s-decoding

Please also check a section about IRAM safe interrupt handlers: https://docs.espressif.com/projects/esp ... t-handlers

PeterG76
Posts: 17
Joined: Wed May 25, 2022 10:25 am

Re: SPI Flash Write Errors After Porting Project from ESP-IDF v4.1 to v4.4

Postby PeterG76 » Fri Nov 18, 2022 3:09 pm

Here is the consistent stack trace I was getting yesterday...
I (14753) MAIN: JACK Writing 'written using EDP-IDF v4.4-dirty' to file
I (14753) MAIN: Closing file
Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed).

Core 1 register dump:
PC : 0x401dac78 PS : 0x00060034 A0 : 0x80083d71 A1 : 0x3ffb15b0
0x401dac78: i2c_hal_update_config at C:/SK_CB1_DEV2/esp-idf/components/hal/i2c_hal.c:223

A2 : 0x00000000 A3 : 0x00000000 A4 : 0x3ffb1ae0 A5 : 0x00002000
A6 : 0x3ffb4128 A7 : 0x1300004c A8 : 0x80083ca4 A9 : 0x3ff53000
A10 : 0x3ffb1ae0 A11 : 0x6001301c A12 : 0x00000001 A13 : 0x3fff9bfc
A14 : 0x00000001 A15 : 0x00060223 SAR : 0x0000001c EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000

Backtrace:0x401dac75:0x3ffb15b00x40083d6e:0x3ffb15e0 0x40083101:0x3ffb1610 0x40084fc3:0x3ffbabc0 0x40083728:0x3ffbabe0 0x4008bd25:0x3ffbac00
0x401dac75: i2c_hal_enable_slave_rx_it at C:/SK_CB1_DEV2/esp-idf/components/hal/i2c_hal.c:170
0x40083d6e: i2c_isr_handler_default at C:/SK_CB1_DEV2/esp-idf/components/driver/i2c.c:497
0x40083101: _xt_lowint1 at C:/SK_CB1_DEV2/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1111
0x40084fc3: spi_flash_op_block_func at C:/SK_CB1_DEV2/esp-idf/components/spi_flash/cache_utils.c:123 (discriminator 1)
0x40083728: ipc_task at C:/SK_CB1_DEV2/esp-idf/components/esp_ipc/src/esp_ipc.c:77
0x4008bd25: vPortTaskWrapper at C:/SK_CB1_DEV2/esp-idf/components/freertos/port/xtensa/port.c:131

ELF file SHA256: 9651a85bd133b8d1
I then found the following issue reported by someone performing an SPIFFS write while using I2C

https://github.com/espressif/esp-idf/issues/8422

So I upgraded my ESP-IDF to v4.4.3 (v4.4.3-159-g54dcccc1f6) which had the fix in it. However I'm still getting a crash in 12c_hal.c

PeterG76
Posts: 17
Joined: Wed May 25, 2022 10:25 am

Re: SPI Flash Write Errors After Porting Project from ESP-IDF v4.1 to v4.4

Postby PeterG76 » Fri Nov 18, 2022 3:27 pm

I'm calling i2c_driver_install() with intr_alloc_flags set to ESP_INTR_FLAG_IRAM. I have a function called from app_main which is opening a file on SPI Flash and writing to it. The fprintf or fclose are triggering these crashes/panics.

I'm calling spi_flash_cache_enabled() just before my file write & close which is returning true.

The ESP-IDF documentation states "On ESP32, these caches must be disabled while reading/writing/erasing."

I've found spi_flash_enable_cache() but not one for disabling cache.

https://docs.espressif.com/projects/esp ... t-handlers

After my upgrade to ESP-IDF v4.4.3 I'm seeing the following panic...
I (34711) MAIN: Savings settings
I (34711) MAIN: ReadHello()
I (34711) MAIN: CacheEnabled YES
Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed).

Core 1 register dump:
PC : 0x401dac30 PS : 0x00060034 A0 : 0x40083248 A1 : 0x3ffb15d0
0x401dac30: i2c_hal_get_intsts_mask at C:/SK_CB1_DEV2/esp-idf/components/hal/i2c_hal.c:68
0x40083248: _xt_lowint1 at C:/SK_CB1_DEV2/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1114
A2 : 0x3ffcc2dc A3 : 0x3ffb1ae0 A4 : 0x00000000 A5 : 0x4008831e
0x4008831e: _frxt_int_enter at C:/SK_CB1_DEV2/esp-idf/components/freertos/port/xtensa/portasm.S:119
A10 : 0x3ffb1ae0 A11 : 0x3ffb15d0 A12 : 0x800826fa A13 : 0x3ffba4f0
A14 : 0x3ffb4110 A15 : 0x1300004c SAR : 0x0000001c EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000

Backtrace: 0x401dac2d:0x3ffb15d0 0x40083245:0x3ffb1610 0x40084f6f:0x3ffba530 0x400837a5:0x3ffba550 0x4008bee9:0x3ffba570
0x401dac2d: i2c_hal_disable_intr_mask at ??:?
0x40083245: _xt_lowint1 at C:/SK_CB1_DEV2/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:1114
0x40084f6f: spi_flash_op_block_func at C:/SK_CB1_DEV2/esp-idf/components/spi_flash/cache_utils.c:124 (discriminator 1)
0x400837a5: ipc_task at C:/SK_CB1_DEV2/esp-idf/components/esp_ipc/src/esp_ipc.c:77
0x4008bee9: vPortTaskWrapper at C:/SK_CB1_DEV2/esp-idf/components/freertos/port/xtensa/port.c:131

ELF file SHA256: f784a6c45c2034b3

ESP_Mahavir
Posts: 190
Joined: Wed Jan 24, 2018 6:51 am

Re: SPI Flash Write Errors After Porting Project from ESP-IDF v4.1 to v4.4

Postby ESP_Mahavir » Sat Nov 19, 2022 4:30 am

Please try the fix from https://github.com/espressif/esp-idf/is ... 1300401211 once. I think this problem looks relevant.

If you still run into any issues, please check the comment https://github.com/espressif/esp-idf/is ... 1302262774 to see if any additional I2C symbols needs IRAM placement.

PeterG76
Posts: 17
Joined: Wed May 25, 2022 10:25 am

Re: SPI Flash Write Errors After Porting Project from ESP-IDF v4.1 to v4.4

Postby PeterG76 » Tue Jan 03, 2023 9:38 am

Thank you,

Just an update to say that the suggested patch worked for me on ESP-IDF v4.4.3.

Not helped by the fact that one of my devices appears to have an ESP32-WROVER-E with faulty SPI flash anyway. But the patch worked on two other device samples.
ESP_Mahavir wrote:
Sat Nov 19, 2022 4:30 am
Please try the fix from https://github.com/espressif/esp-idf/is ... 1300401211 once. I think this problem looks relevant.

If you still run into any issues, please check the comment https://github.com/espressif/esp-idf/is ... 1302262774 to see if any additional I2C symbols needs IRAM placement.

Who is online

Users browsing this forum: No registered users and 249 guests