---
title: "littlefs Key/Value"
description: "Read this one carefully. The littlefs west module is not checked out in the authoring workspace, so CONFIGFILESYSTEMLITTLEFS=n there and **the only branch verified PASS on nativesim today is the #else fallback — the one that prints \"module not fetched\". The fsmount / fsopen / fsread / fswrite / 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."
source: https://docs.alplab.ai/sdk/examples/littlefs-keyvalue
---

# `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/`](https://github.com/alplabai/alp-sdk/tree/main/examples/power-timing/littlefs-keyvalue).

## What it does

Under `#ifdef CONFIG_FILE_SYSTEM_LITTLEFS`:

1. Mounts `/lfs`.
2. Writes `answer=42` to `kv.txt`.
3. Seeks and reads it back.
4. `fs_readdir()`s the mount point.
5. 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 flash over xSPI DMA | `CONFIG_ALP_LITTLEFS_XSPI_DMA` |
| E1M-V2N(-M1) | Not available to an M33 app: as of alp-sdk v0.17.0 Linux on the A55 owns the eMMC. `CONFIG_ALP_LITTLEFS_EMMC_DMA` applies only to an A55-side build | `CONFIG_ALP_LITTLEFS_EMMC_DMA` (A55 only) |
| any | Sync I/O (default) | `CONFIG_ALP_LITTLEFS_SYNC_IO` |

## `board.yaml`

```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
```

## See also

- [`<alp/storage.h>`](https://docs.alplab.ai/sdk/api/storage)
- [Examples overview](https://docs.alplab.ai/sdk/examples/overview)
