littlefs-keyvalue
:::warning [UNTESTED] — including the littlefs code path itself
Read this one carefully. The littlefs west module is not checked out in the authoring workspace, so CONFIG_FILE_SYSTEM_LITTLEFS=n there and the only branch verified PASS on native_sim today is the #else fallback — the one that prints "module not fetched". The fs_mount / fs_open / fs_read / fs_write / fs_readdir code is real, correct API usage that is currently untested on that machine. Run west update to pull modules/fs/littlefs and the real branch takes over with no source change.
:::
Mount a RAM-backed littlefs, write a key/value pair, read it back, and list the mount point.
Source: examples/power-timing/littlefs-keyvalue/.
What it does
Under #ifdef CONFIG_FILE_SYSTEM_LITTLEFS:
- Mounts
/lfs. - Writes
answer=42tokv.txt. - Seeks and reads it back.
fs_readdir()s the mount point.- Asserts read == write, then unmounts.
Under #else, it prints an explanatory message and exits — that is the branch a workspace without the module fetched will run.
libraries: [littlefs] emits CONFIG_FILE_SYSTEM_LITTLEFS=y + CONFIG_FILE_SYSTEM=y + CONFIG_ALP_LITTLEFS_SYNC_IO=y. The flash-backend Kconfig (CONFIG_FLASH / CONFIG_FLASH_MAP) is app-local and lives in the example's prj.conf.
Hardware swap
Swap the storage medium behind the storage_partition devicetree label. No change to src/main.c is required — only the board's DTS partition map changes what storage_partition physically backs onto.
| SoM | Backing store | Backend knob |
|---|---|---|
| E1M-AEN | Alif on-die MRAM over xSPI DMA | CONFIG_ALP_LITTLEFS_XSPI_DMA |
| E1M-V2N(-M1) | eMMC over DMA | CONFIG_ALP_LITTLEFS_EMMC_DMA |
| any | Sync I/O (default) | CONFIG_ALP_LITTLEFS_SYNC_IO |
board.yaml
libraries:
- name: littlefs
cores: [m55_hp]
som:
sku: E1M-AEN801
preset: e1m-evk
supported_boards:
- e1m-evk
- e1m-x-evk
cores:
m55_hp:
app: ./src
peripherals: []
diagnostics:
log_level: info
Expected output
With modules/fs/littlefs fetched (CONFIG_FILE_SYSTEM_LITTLEFS=y):
[littlefs-keyvalue] mounting /lfs ...
[littlefs-keyvalue] mount rc=0
[littlefs-keyvalue] wrote "answer=42" (9 bytes)
[littlefs-keyvalue] read "answer=42" (9 bytes)
[littlefs-keyvalue] dir /lfs:
[littlefs-keyvalue] [FILE] kv.txt (size = 9)
[littlefs-keyvalue] read matches write -- OK
[littlefs-keyvalue] done
Without it — the #else fallback:
[littlefs-keyvalue] CONFIG_FILE_SYSTEM_LITTLEFS=n in this build --
[littlefs-keyvalue] the littlefs west module isn't fetched (run
[littlefs-keyvalue] `west update` to pull modules/fs/littlefs); the
[littlefs-keyvalue] fs_mount/fs_open/fs_read/fs_write/fs_readdir code
[littlefs-keyvalue] above this #else is the real, correct API usage.
[littlefs-keyvalue] done