Page 1 of 1

fatfs crashes after some time

Posted: Tue May 21, 2024 2:17 pm
by Weskrauser
Hello!

I am currently working on sdio logging on SD card with esp32s3. I'm using platformio with :
- platform = espressif32 @ 6.6.0
- framework-arduinoespressif32 @ 3.20014.231204 (2.0.14)
- toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5

My system uses 2 buffers and one task per core for logging purpose:
- One shared short buffer protected by a mutex is feeded at 500 Hz by the main task on core0.
- At 50Hz the second task on core1 grab the mutex, copy the short buffer content in a ringBuffer (from https://github.com/greiman/SdFat/blob/m ... /RingBuf.h), write it to the SD file and flush the result every 10 seconds.

Fast task on core0:

Code: Select all

// Update temp buffer if it is unused
    if (xSemaphoreTake(xSemaphore, (TickType_t)1) == pdTRUE)
    {
        // Write new data frame to short buffer 
        xSemaphoreGive(xSemaphore);
    }
  
Slow task on core 1:

Code: Select all

if (xSemaphoreTake(xSemaphore, (TickType_t)10) == pdTRUE)
    {
    	// Copy this short buffer to big ringBuffer 
        bytesWritten = ringBuffer->write(tempFastBuffer, idxTempFastBuffer);
        xSemaphoreGive(xSemaphore);        
        idxTempFastBuffer = 0U;
    }    
  
The part of code that crashes in this slow task:

Code: Select all


        for (size_t i = 0; i < nbSectorsToWrite; i++)
        {
            // Write one sector from RingBuf to file
            mRingBufferBatchSize != ringBuffer->writeOut(mRingBufferBatchSize);
        }
      
This systems works well for around 310-340s with really consistent logs results. Then I face Guru meditation with two kind of errors:

Code: Select all

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4203fcda  PS      : 0x00060b30  A0      : 0x8203cd17  A1      : 0x3fcb34e0  
A2      : 0x000000a0  A3      : 0x3d838aec  A4      : 0x0000ded7  A5      : 0x00000001  
A6      : 0x3fc95e08  A7      : 0x00000200  A8      : 0x00000000  A9      : 0x00000280  
A10     : 0x000000a0  A11     : 0x3d838aec  A12     : 0x00000083  A13     : 0x00000001  
A14     : 0x00060320  A15     : 0x00000001  SAR     : 0x0000000c  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000008  LBEG    : 0x40056f5c  LEND    : 0x40056f72  LCOUNT  : 0xffffffff  


Backtrace: 0x4203fcd7:0x3fcb34e0 0x4203cd14:0x3fcb3500 0x4203e7e6:0x3fcb3520 0x420403d4:0x3fcb3550 0x42039d36:0x3fcb3570 0x42011da9:0x3fcb3590 0x4208d309:0x3fcb35b0 0x42017183:0x3fcb35d0 0x42013bfa:0x3fcb35f0 0x420057f2:0x3fcb36d0

  #0  0x4203fcd7:0x3fcb34e0 in ff_disk_read at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/fatfs/diskio/diskio.c:70
  #1  0x4203cd14:0x3fcb3500 in move_window at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/fatfs/src/ff.c:1077
      (inlined by) move_window at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/fatfs/src/ff.c:1064
  #2  0x4203e7e6:0x3fcb3520 in f_sync at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/fatfs/src/ff.c:4011
  #3  0x420403d4:0x3fcb3550 in vfs_fat_fsync at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/fatfs/vfs/vfs_fat.c:499
  #4  0x42039d36:0x3fcb3570 in esp_vfs_fsync at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/vfs/vfs.c:565 (discriminator 3)
  #5  0x42011da9:0x3fcb3590 in VFSFileImpl::flush() at /Users/denis/.platformio/packages/framework-arduinoespressif32@3.20014.231204/libraries/FS/src/vfs_api.cpp:418
  #6  0x4208d309:0x3fcb35b0 in fs::File::flush() at /Users/denis/.platformio/packages/framework-arduinoespressif32@3.20014.231204/libraries/FS/src/FS.cpp:103
      (inlined by) fs::File::flush() at /Users/denis/.platformio/packages/framework-arduinoespressif32@3.20014.231204/libraries/FS/src/FS.cpp:97
  #7  0x42017183:0x3fcb35d0 in streamLogger::flushLog() at lib/libDM_stream_logger/src/libDM_stream_logger_common.cpp:108
  #8  0x42013bfa:0x3fcb35f0 in streamLogger::writeLog() at lib/libDM_stream_logger/src/libDM_stream_logger_ESP32.cpp:337
  #9  0x420057f2:0x3fcb36d0 in taskSecondary(void*) at src/appdm_ins02box_esp32s3/src/tasks.cpp:522
or

Code: Select all

Guru Meditation Error: Core  1 panic'ed (IntegerDivideByZero). Exception was unhandled.

Core  1 register dump:
PC      : 0x4203e61c  PS      : 0x00060f30  A0      : 0x8204086b  A1      : 0x3fcb3470  
A2      : 0x00000000  A3      : 0x3d814920  A4      : 0x00000200  A5      : 0x3fcb34bc  
A6      : 0x3d838ab0  A7      : 0x3d83a2f8  A8      : 0x8203e6f1  A9      : 0x00000000  
A10     : 0x021aa800  A11     : 0x00000000  A12     : 0x0003896b  A13     : 0x00000001  
A14     : 0x00000001  A15     : 0x3d838ab0  SAR     : 0x0000000c  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x40056f5c  LEND    : 0x40056f72  LCOUNT  : 0xffffffff  


Backtrace: 0x4203e619:0x3fcb3470 0x42040868:0x3fcb34b0 0x42039b89:0x3fcb34e0 0x42073749:0x3fcb3500 0x42071dba:0x3fcb3520 0x42071f16:0x3fcb3550 0x42071f79:0x3fcb3590 0x42011d61:0x3fcb35b0 0x4208d289:0x3fcb35d0 0x42013b8e:0x3fcb35f0 0x420057ee:0x3fcb36d0

  #0  0x4203e619:0x3fcb3470 in f_write at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/fatfs/src/ff.c:3863
  #1  0x42040868:0x3fcb34b0 in vfs_fat_write at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/fatfs/vfs/vfs_fat.c:379
  #2  0x42039b89:0x3fcb34e0 in esp_vfs_write at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/vfs/vfs.c:431 (discriminator 3)
  #3  0x42073749:0x3fcb3500 in __swrite at /Users/brnomac003/.gitlab-runner/builds/qR2TxTby/1/idf/crosstool-NG/.build/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/stdio.c:94
  #4  0x42071dba:0x3fcb3520 in __sfvwrite_r at /Users/brnomac003/.gitlab-runner/builds/qR2TxTby/1/idf/crosstool-NG/.build/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/fvwrite.c:196 (discriminator 4)
  #5  0x42071f16:0x3fcb3550 in _fwrite_r at /Users/brnomac003/.gitlab-runner/builds/qR2TxTby/1/idf/crosstool-NG/.build/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/fwrite.c:137
  #6  0x42071f79:0x3fcb3590 in fwrite at /Users/brnomac003/.gitlab-runner/builds/qR2TxTby/1/idf/crosstool-NG/.build/xtensa-esp32s3-elf/src/newlib/newlib/libc/stdio/fwrite.c:177
  #7  0x42011d61:0x3fcb35b0 in VFSFileImpl::write(unsigned char const*, unsigned int) at /Users/denis/.platformio/packages/framework-arduinoespressif32@3.20014.231204/libraries/FS/src/vfs_api.cpp:399
  #8  0x4208d289:0x3fcb35d0 in fs::File::write(unsigned char const*, unsigned int) at /Users/denis/.platformio/packages/framework-arduinoespressif32@3.20014.231204/libraries/FS/src/FS.cpp:50
      (inlined by) fs::File::write(unsigned char const*, unsigned int) at /Users/denis/.platformio/packages/framework-arduinoespressif32@3.20014.231204/libraries/FS/src/FS.cpp:44
  #9  0x42013b8e:0x3fcb35f0 in RingBuf<fs::File, 102400u>::writeOut(unsigned int) at lib/sdfat_legacy/src/RingBuf.h:340
      (inlined by) streamLogger::writeLog() at lib/libDM_stream_logger/src/libDM_stream_logger_ESP32.cpp:323
  #10 0x420057ee:0x3fcb36d0 in taskSecondary(void*) at src/appdm_ins02box_esp32s3/src/tasks.cpp:522
Do you have any idea the reason behind this crash?

I tested the possibility of empty buffers but it does not seem to be the case.

Thanks in advance!