esp_littlefs: How to prevent assert failed: lfs_bd_prog lfs.c:262 (pcache->block == ((lfs_block_t)-1)) when writing bigger files e.g. greater than 64 kB?

    char buf[BUFSIZ];
    int create_test_file(const size_t size_bytes, const std::string_view& name) {
        const std::filesystem::path test_megabyte { std::filesystem::path(mount_point).append(name) };

        FILE* file { std::fopen(test_megabyte.c_str(), "w") };
        std::setbuf(file, buf);
        if(file == nullptr) {
            return -1;
        }

        char c { 'a' };
        for(
            size_t i = 1;
            i <= size_bytes;
            [&i, &c]() {
                if(c == 'z') {
                    c = 'a';
                } else {
                    c++;
                }

                i++;
            }()
        ) {
            if(std::fputc(c, file) != c) {
                return static_cast<int>(i);
            }
            if((i % BUFSIZ) == 0) {
                std::fflush(file);
            }
        }

        std::fclose(file);
        return 0;
    }

I’m doing something like this to create a test file with ESP32-C6 and 2GB SD card over single lane SPI. I’ve tried adding the std::fflush and std::setbuf for the FILE* stream and it doesn’t seem to help at all. What is the actual maximum file size? And can you create files like 1MB in size and larger? Or not?

Logs:

I (10729) esp_littlefs: SD card formatted!
Success: SD_Card::format(): '0'
Success: SD_Card::create_test_file(unsigned int: '1', unsigned int: 'jcb1'): '0'
Success: SD_Card::check_test_file(unsigned int: '1', unsigned int: 'jcb1'): '0'
Success: SD_Card::create_test_file(unsigned int: '2', unsigned int: 'jcb2'): '0'
Success: SD_Card::check_test_file(unsigned int: '2', unsigned int: 'jcb2'): '0'
Success: SD_Card::create_test_file(unsigned int: '4', unsigned int: 'jcb4'): '0'
Success: SD_Card::check_test_file(unsigned int: '4', unsigned int: 'jcb4'): '0'
Success: SD_Card::create_test_file(unsigned int: '8', unsigned int: 'jcb8'): '0'
Success: SD_Card::check_test_file(unsigned int: '8', unsigned int: 'jcb8'): '0'
Success: SD_Card::create_test_file(unsigned int: '16', unsigned int: 'jcb16'): '0'
Success: SD_Card::check_test_file(unsigned int: '16', unsigned int: 'jcb16'): '0'
Success: SD_Card::create_test_file(unsigned int: '32', unsigned int: 'jcb32'): '0'
Success: SD_Card::check_test_file(unsigned int: '32', unsigned int: 'jcb32'): '0'
Success: SD_Card::create_test_file(unsigned int: '64', unsigned int: 'jcb64'): '0'
Success: SD_Card::check_test_file(unsigned int: '64', unsigned int: 'jcb64'): '0'
Success: SD_Card::create_test_file(unsigned int: '128', unsigned int: 'jcb128'): '0'
Success: SD_Card::check_test_file(unsigned int: '128', unsigned int: 'jcb128'): '0'
Success: SD_Card::create_test_file(unsigned int: '256', unsigned int: 'jcb256'): '0'
Success: SD_Card::check_test_file(unsigned int: '256', unsigned int: 'jcb256'): '0'
Success: SD_Card::create_test_file(unsigned int: '512', unsigned int: 'jcb512'): '0'
Success: SD_Card::check_test_file(unsigned int: '512', unsigned int: 'jcb512'): '0'
Success: SD_Card::create_test_file(unsigned int: '1024', unsigned int: 'jcb1024'): '0'
Success: SD_Card::check_test_file(unsigned int: '1024', unsigned int: 'jcb1024'): '0'
Success: SD_Card::create_test_file(unsigned int: '2048', unsigned int: 'jcb2048'): '0'
Success: SD_Card::check_test_file(unsigned int: '2048', unsigned int: 'jcb2048'): '0'
Success: SD_Card::create_test_file(unsigned int: '4096', unsigned int: 'jcb4096'): '0'
Success: SD_Card::check_test_file(unsigned int: '4096', unsigned int: 'jcb4096'): '0'
Success: SD_Card::create_test_file(unsigned int: '8192', unsigned int: 'jcb8192'): '0'
Success: SD_Card::check_test_file(unsigned int: '8192', unsigned int: 'jcb8192'): '0'
Success: SD_Card::create_test_file(unsigned int: '16384', unsigned int: 'jcb16384'): '0'
Success: SD_Card::check_test_file(unsigned int: '16384', unsigned int: 'jcb16384'): '0'
Success: SD_Card::create_test_file(unsigned int: '32768', unsigned int: 'jcb32768'): '0'
Success: SD_Card::check_test_file(unsigned int: '32768', unsigned int: 'jcb32768'): '0'
Success: SD_Card::create_test_file(unsigned int: '65536', unsigned int: 'jcb65536'): '0'
Success: SD_Card::check_test_file(unsigned int: '65536', unsigned int: 'jcb65536'): '0'

assert failed: lfs_bd_prog lfs.c:262 (pcache->block == ((lfs_block_t)-1))
Core  0 register dump:
MEPC    : 0x408004ec  RA      : 0x408065e4  SP      : 0x40813a00  GP      : 0x4080d3b0  
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x408004ec: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x408065e4: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
TP      : 0x407fc578  T0      : 0x37363534  T1      : 0x7271706f  T2      : 0x33323130  
S0/FP   : 0x0000007e  S1      : 0x00000001  A0      : 0x40813a3c  A1      : 0x4080d619  
A2      : 0x00000001  A3      : 0x00000029  A4      : 0x00000001  A5      : 0x40810000  
A6      : 0x0000000c  A7      : 0x76757473  S2      : 0x00000009  S3      : 0x40813b59  
S4      : 0x4080d618  S5      : 0x40813b6c  S6      : 0x4081514c  S7      : 0x00000001  
S8      : 0x40815920  S9      : 0x00000000  S10     : 0x00000007  S11     : 0x00000006  
T3      : 0x6e6d6c6b  T4      : 0x6a696867  T5      : 0x66656463  T6      : 0x62613938  
MSTATUS : 0x00001881  MTVEC   : 0x40800001  MCAUSE  : 0x00000007  MTVAL   : 0x00000000  
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x40800001: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
MHARTID : 0x00000000  

Stack memory:
40813a00: 0x00000000 0x000000ff 0x4206e080 0x4080ba62 0x4080d7bc 0x4206e080 0x4080d7cc 0x42064660
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4080ba62: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813a20: 0x4080d7d0 0x40813a34 0x4080d7d4 0x4206479c 0x4080d618 0x00323632 0x40813a9c 0x65737361
40813a40: 0x66207472 0x656c6961 0x6c203a64 0x625f7366 0x72705f64 0x6c20676f 0x632e7366 0x3236323a
40813a60: 0x63702820 0x65686361 0x6c623e2d 0x206b636f 0x28203d3d 0x73666c28 0x6f6c625f 0x745f6b63
40813a80: 0x29312d29 0x00000029 0x4080ee70 0x42010ce4 0x00000008 0x00000001 0x40813aec 0x0000000d
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x42010ce4: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813aa0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40813ac0: 0x00000000 0x00001c00 0x00000000 0x000003e8 0x00000200 0x00000000 0x4080ee70 0x4201140c
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4201140c: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813ae0: 0x00000004 0x00000000 0x00000000 0x00000026 0x00000000 0x00000000 0x00000000 0x00000000
40813b00: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00003d00 0x4081514c 0x00000004
40813b20: 0x00023616 0x00000000 0x40815928 0x4200be06 0x4081514c 0x00023616 0x40815920 0x40815924
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4200be06: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813b40: 0x00017a24 0x00023614 0x40815928 0x00000000 0x4081514c 0x4081514c 0x00000000 0x4200cdbc
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4200cdbc: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813b60: 0x4080772c 0x00023616 0x00000200 0x00023614 0x407fc578 0x40028192 0x00023615 0x00000000
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4080772c: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/.espressif/tools/esp-rom-elfs/20230320/esp32c6_rev0_rom.elf 0x40028192: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813b80: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000080 0x00000080 0x4080edf0
40813ba0: 0x00017a24 0x4081514c 0x408158e8 0x4200ce66 0x00000000 0x00000000 0x00000000 0x00000000
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4200ce66: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813bc0: 0x00000000 0x00000000 0x4080edf0 0x00000080 0x00017a24 0x4081514c 0x408158e8 0x4200d230
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4200d230: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813be0: 0x00000000 0x00000000 0x408157ec 0x40807276 0x40811818 0x00000004 0x00000000 0x00000080
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x40807276: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813c00: 0x4080edf0 0x408158e8 0x4081514c 0x4201036c 0x00000000 0xffffffff 0x408150f4 0x00000080
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4201036c: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813c20: 0x00000000 0x4080edf0 0x4081506c 0x42009ab2 0x40813ef4 0x00000004 0x40813c7c 0x40813ef4
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x42009ab2: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813c40: 0x00000080 0x4080edf0 0x00000003 0x4205db24 0x00000072 0x00000072 0x40811818 0x4080edf0
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4205db24: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813c60: 0x00000080 0x40813ef4 0x40811818 0x4003071e 0x00000000 0x00000000 0x40811818 0x40813d80
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/.espressif/tools/esp-rom-elfs/20230320/esp32c6_rev0_rom.elf 0x4003071e: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813c80: 0x00000000 0x40813ef4 0x40811818 0x4003079a 0x00000000 0x00000000 0x00000000 0x40811818
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/.espressif/tools/esp-rom-elfs/20230320/esp32c6_rev0_rom.elf 0x4003079a: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813ca0: 0x00000000 0x00020000 0x40811818 0x42007672 0x37303630 0x39303830 0x00017b00 0x72313231
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x42007672: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813cc0: 0x40815734 0x00000011 0x00000011 0x31323032 0x33323232 0x35323432 0x4081587c 0x408157ec
40813ce0: 0x00000011 0x0000001e 0x00647261 0x37333633 0x39333833 0x00000000 0x40813cb8 0x40813cbf
40813d00: 0x37343634 0x40813d84 0x00000014 0x420080d8 0x35353435 0x37353635 0x00000009 0x40813d8c
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x420080d8: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813d20: 0x33363236 0x35363436 0x37363636 0x39363836 0x31373037 0x33373237 0x35373437 0x37373637
40813d40: 0x39373837 0x31383038 0x00000009 0x40813d8c 0x00000009 0x40813d8c 0x00000009 0x40813d8c
40813d60: 0x00000000 0x40813e24 0x00000014 0x00000000 0x00000000 0x40813e24 0x00000014 0x42008256
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x42008256: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813d80: 0x00020000 0x40813d8c 0x00000009 0x3162636a 0x37303133 0x00000032 0x40811748 0x40813da4
40813da0: 0x00000009 0x3162636a 0x37303133 0x40810032 0x4080f1d0 0x4080f000 0x40813dc0 0x00000006
40813dc0: 0x30313331 0x42003237 0x00000001 0x4riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x42003237: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
080f554 0x00000000 0x4080f000 0x42061000 0x4200645a
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4200645a: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'
40813de0: 0x00000000 0x00000000 0x00000001 0x00008000 0x00000000 0x00000000 0x00000001 0x4080b7c2
riscv32-esp-elf-addr2line -pfiaC -e /home/spikeyamk/esp/ESP32_AD5933/fw/build/cpp_rtti.elf 0x4080b7c2: [Errno 2] No such file or directory: 'riscv32-esp-elf-addr2line'



ELF file SHA256: 26849f8d5

Rebooting...

About this issue

  • Original URL
  • State: open
  • Created 4 months ago
  • Comments: 19 (4 by maintainers)

Most upvoted comments

Can confirm this is unlikely to be a littlefs issue. littlefs also doesn’t support cross-block/cross-sector writes at the moment so espressif/esp-idf#7804 seems a bit unlikely if I understand the integration correctly.

Honestly I’d be a bit suspicious of the c++ stdlib/integration here. What is BUFSIZ? Could it be that the stdlib was compiled with a different BUFSIZ?

BUFSIZ is 128 but honestly it don’t matter. I added that thing with char buf[BUFSIZ] with std::setbuf(file, buf) and std::flush(file) as a desparate attempt to fix this and it failed the exact same way before.

Can confirm this is unlikely to be a littlefs issue. littlefs also doesn’t support cross-block/cross-sector writes at the moment so https://github.com/espressif/esp-idf/issues/7804 seems a bit unlikely if I understand the integration correctly.

Honestly I’d be a bit suspicious of the c++ stdlib/integration here. What is BUFSIZ? Could it be that the stdlib was compiled with a different BUFSIZ?