Closed SBembedded closed 6 months ago
In the end it turned out to be a timing and driver related issue.
On STM32 with OSPI communication, auto polling for mem-ready is configured with cpu cycles instead of total time. Depending on the CPU load and other background tasks, this timeout may work in normal application condition, but may not in testing conditions without background tasks.
In this case, depending on the load, the driver would sporadically run into a timeout (e.g. chip is busy on erase), subsequent write/erase operations are discarded by the chip. This leads to littlefs operations not completing correctly, thus the corrupted filesystem and bad blocks.
Currently, more than 970 files @4kB can be written and erased. It seems to work stable now.
Hi @SBembedded, glad you figured out the issue. What an interesting bug.
Flash erase operations can take a surprising amount of time to complete, so it makes sense that is what would trip it up.
If you detect the timeout and return LFS_ERR_IO in your bd functions, it would be propagated up through littlefs's APIs in case this happens again in the future.
Hi,
I'm using littlefs together with a custom driver for the MX25L3233F 4MB NOR Flash on STM32L4R7. (4kB sector, 1 Byte wrap-around read/write, running at 120Mhz)
One thing I found out so far, is that mount & umount and format operations should not be done frequently. There seems to be no self-check if a fs is already mounted. Double-mount operations immediately lead to corrupted fs. The occurence of bad blocks and corrupted dir, are directly influenced by the settings in the cfg struct below. So far, I don't see how my configuration is false?
Littlefs configuration: (v2.9.3)
Debug output of file-write test: (700 files, with 256 byte of data each)
I tried to get it stable. So far without success. In some instances leading to a bricked device idling in an assert, if you dont immediately erase & reformat after dir corruption. For a production software rolling out to embedded devices it seems littlefs is far too unstable and unreliable to be of use?!
Using directory operations with these settings, leads to even faster dir-corruption and tons of bad blocks.
I wonder how blocks can be marked as bad, when there has been at-most one write on them. Does littlefs not work correctly with NOR Flash?
So far I understand it, the flash space is evenly divided in blocks. So every address of a block, should be
uint32_t address = block * c->block_size;
Perhaps someone has an idea, what I'm doing wrong here.