Hi,
we are having issue with nRF52832 and littlefs. We are using Nordic Connect SDK 1.9.1 and Visual Studio Code.
We created dts overlay and removed partitions not needed and expanded storage_partition so it takes all available space, in our case it was 256KB and first 256KB is for image.
We are using bluetooth for stored data transfer and some other data processing.
Idea was to write some struct (in our case is 40B) to file by advancing file index (fs_seek) by the amount of struct that we need to store, and when flash is full index is set to 0. Some sort of ring storage file. Data is written approximately each 400ms on bursts and can be idle for many hours.
Up to this point everything was working fine, reading and writing.
The problem occurs when function fs_write returns error -ENOSPC. Then file writing index is set to 0 to continue writing to the beginning of file. Every following call to fs_write return success, but function fs_close returns error -ENOSPC. This is happening to all following writes.
Next we tried several approaches to fix this problem.
We tried to use only smaller portion of flash for storage (64KB) and this happend again.
Then we tried to truncate file (fs_truncate) for last unsuccessful write to free some space and set index to 0 and this also returned error on next write.
Interesting thing happened on last attempt. We used all available storage for file system (256KB) and limit file index size to half of available storage, this means file size was max 128KB and this leaves us another 128KB free space in file system. When we hit this limit, index is set to 0 to continue writing to beginning of file. And then writing was fine up to 4K and then fs_write returns error -ENOSPC.
Also some combination of truncating file, using smaller file system or file size was attempted with no success.
On every attempt reading was working fine. Data we are writing was not consistent any more but can be readed.
What we are doing wrong?
In examples there is basically same thing we are trying to achieve when increasing boot count value except seek to beginning is used when we hit some condition.
https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/subsys/fs/littlefs/src/main.c
Thank you!