Hardware: nRF52832 on the nRF52-DK
SDK: nRF Connect v2.0.0
IDE: Visual Studio Code 1.73.1 with nRF Connect for VS Code (v2022.11.140) extension
I'm trying to get familiar with writing and reading information from the littlefs on my nRF52832. The end goal is to have a log file that I will write prior to going into SYSTEM_OFF, and this will then get read back when the device exists SYSTEM_OFF, updated with new information, and then re-written to the littlefs.
I've been using the littlefs example (.../samples/subsys/fs/littlefs/) as a basis. All I've changed is to add some MCUBoot functionality and to add fixed partitions for my littlefs_storage space in Flash, as in my end code, I'll be using the settings_storage for settings and NVS, and want to control the amount of memory I allocate for littlefs. If I set up the littlefs parition as follows, my example (attached below) works as expected.
littlefs_storage: address: 0x7a000 size: 0x6000 placement: before: - end region: flash_primary
However in my end code, I won't have this much space available, and so I have been experimenting with reducing the fixed partition space for littlefs, with mixed results. If I set my fixed partition as follows:
littlefs_storage: address: 0x7e000 size: 0x2000 placement: before: - end region: flash_primary
and then if I have TEST_FILE_SIZE = 64, everything works. But if I set TEST_FILE_SIZE = 65 or higher, then I get the following errors:
*** Booting Zephyr OS build v3.0.99-ncs1 ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Swap type: none
I: Bootloader chainload address offset: 0xc000
�*** Booting Zephyr OS build v3.0.99-ncs1 ***
Sample program to r/w files on littlefs
Area 6 at 0x7e000 on NRF_FLASH_DRV_NAME for 8192 bytes
I: LittleFS version 2.4, disk version 2.0
I: FS at NRF_FLASH_DRV_NAME:0x7e000 is 2 0x1000-byte blocks with 512 cycle
I: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
I: /lfs mounted
/lfs mount: 0
/lfs: bsize = 16 ; frsize = 4096 ; blocks = 2 ; bfree = 0
Listing dir /lfs ...
[FILE] boot_count (size = 1)
[FILE] pattern.bin (size = 0)
/lfs/boot_count read count:2 (bytes: 1)
/lfs/boot_count write new boot count 3: [wr:1]
I: Test file: /lfs/pattern.bin not found, create one!
------ FILE: /lfs/pattern.bin ------
01 55 55 55 55 55 55 55 02 55 55 55 55 55 55 55
03 55 55 55 55 55 55 55 04 55 55 55 55 55 55 55
05 55 55 55 55 55 55 55 06 55 55 55 55 55 55 55
07 55 55 55 55 55 55 55 08 55 55 55 55 55 55 55
aa
E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:567: No more free space 3
E: file write error (-28)
file write error (-28)
E: FAIL: write /lfs/pattern.bin: -28
I: /lfs unmounted
/lfs unmount: 0
This appears to be indicating that I am running out of space, but given I've allocated 8kB of flash, and I'm only trying to store 65 bytes in total (/boot count and /pattern.bin), I can't understand why this is occuring.
Can anyone with some experience in littlefs give me some pointers as to how I can resolve this? Or at least help me understand why I'm getting the "No more free space" error with 8kB of flash and only 65 bytes of info being written to it?
Here is my example code:
Thanks,
Mike