Skip to content

Commit f22ac4d

Browse files
committed
doc: flash: add flash simulator guide
Adds a dedicated flash_simulator.rst page describing the RAM-backed flash simulator driver and how to enable it. Fixes #20654. Signed-off-by: Isaac Jerish <[email protected]>
1 parent 96f51bf commit f22ac4d

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
.. _flash_simulator:
2+
3+
Flash Simulator Driver
4+
######################
5+
6+
Overview
7+
********
8+
The **Flash Simulator** is a RAM-backed driver that emulates non-volatile flash
9+
storage. It lets applications, file systems, and test cases run on targets
10+
that lack real flash hardware, or when avoiding wear-out on physical devices
11+
(e.g.\ during continuous-integration runs).
12+
13+
Because it stores data in system RAM, all contents are lost at system reset
14+
and timing characteristics do **not** represent real flash latency.
15+
16+
Enabling the driver
17+
*******************
18+
19+
Kconfig
20+
=======
21+
22+
Enable :kconfig:`CONFIG_FLASH_SIMULATOR` (the driver) and, if you plan to
23+
mount a file system on it, :kconfig:`CONFIG_FLASH_SIMULATOR_REGS`.
24+
25+
Devicetree
26+
==========
27+
28+
Add a node with compatible ``"zephyr,flash-sim"`` in your board DT overlay.
29+
A minimal example maps 256 KiB of simulated flash at address ``0x0``::
30+
31+
/ {
32+
flash0: flash@0 {
33+
compatible = "zephyr,flash-sim";
34+
reg = <0x0 0x40000>; /* 256 KiB */
35+
erase-block-size = <4096>;
36+
write-block-size = <4>;
37+
};
38+
};
39+
40+
The node becomes instance 0 of the flash driver and is exposed through the
41+
common :ref:`flash_api`.
42+
43+
Building and running
44+
********************
45+
46+
Quick test on QEMU
47+
==================
48+
49+
The sample below formats the simulated flash with LittleFS, creates a file,
50+
and prints its contents.
51+
52+
.. code-block:: console
53+
54+
# From the Zephyr repository root
55+
west build -b qemu_cortex_m3 samples/drivers/flash_simulator
56+
west build -t run
57+
58+
Expected output::
59+
60+
*** Booting Zephyr OS build v4.x ***
61+
flash_sim: initialized 256 KiB simulated flash
62+
littlefs: mounted
63+
Wrote: Zephyr Flash Simulator demo!
64+
Readback: Zephyr Flash Simulator demo!
65+
littlefs: unmounted
66+
67+
Using with your own application
68+
===============================
69+
70+
1. Enable the driver in *prj.conf*::
71+
72+
CONFIG_FLASH_SIMULATOR=y
73+
74+
2. Add the devicetree overlay shown above (adapt size if needed).
75+
76+
3. Use the normal flash API, file-system API, or MCUboot/DFU tools exactly as
77+
you would on real hardware.
78+
79+
Limitations
80+
***********
81+
* Contents live **only** in RAM → lost on reset or power-off.
82+
* Erase and write times are host-RAM fast; not suitable for timing studies.
83+
* Single-thread access only; no concurrent multi-core testing.
84+
* Sector layout is flat—parameterized by the `erase-block-size` property.
85+
86+
References
87+
**********
88+
* :zephyr_file:`samples/drivers/flash_simulator`
89+
* :doxygengroup:`flash_interface`
90+
* :ref:`file_systems`
91+
* `LittleFS documentation <https://littlefs.readthedocs.io/>`__

doc/hardware/peripherals/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Peripherals
2929
entropy.rst
3030
edac/index.rst
3131
flash.rst
32+
flash_simulator.rst
3233
fuel_gauge.rst
3334
gnss.rst
3435
gpio.rst

0 commit comments

Comments
 (0)