README.rst
1.. zephyr:code-sample:: zms
2 :name: Zephyr Memory Storage (ZMS)
3 :relevant-api: zms_high_level_api
4
5 Store and retrieve data from storage using the ZMS API.
6
7Overview
8********
9 The sample shows how to use ZMS to store ID/VALUE pairs and reads them back.
10 Deleting an ID/VALUE pair is also shown in this sample.
11
12 The sample stores the following items:
13
14 #. A string representing an IP address: stored at id=1, data="192.168.1.1"
15 #. A binary blob representing a key/value pair: stored at id=0xbeefdead,
16 data={0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF}
17 #. A variable (32bit): stored at id=2, data=cnt
18 #. A long set of data (128 bytes)
19
20 A loop is executed where we mount the storage system, and then write all set
21 of data.
22
23 Each DELETE_ITERATION period, we delete all set of data and verify that it has been deleted.
24 We generate as well incremented ID/value pairs, we store them until storage is full, then we
25 delete them and verify that storage is empty.
26
27Requirements
28************
29
30* A board with flash support or native_sim target
31
32Building and Running
33********************
34
35This sample can be found under :zephyr_file:`samples/subsys/fs/zms` in the Zephyr tree.
36
37The sample can be built for several platforms, but for the moment it has been tested only
38on native_sim target
39
40.. zephyr-app-commands::
41 :zephyr-app: samples/subsys/fs/zms
42 :goals: build
43 :compact:
44
45After running the generated image on a native_sim target, the output on the console shows the
46multiple Iterations of read/write/delete exectuted.
47
48Sample Output
49=============
50
51.. code-block:: console
52
53 *** Booting Zephyr OS build v3.7.0-2383-g624f75400242 ***
54 [00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes
55 [00:00:00.000,000] <inf> fs_zms: alloc wra: 0, fc0
56 [00:00:00.000,000] <inf> fs_zms: data wra: 0, 0
57 ITERATION: 0
58 Adding IP_ADDRESS 172.16.254.1 at id 1
59 Adding key/value at id beefdead
60 Adding counter at id 2
61 Adding Longarray at id 3
62 [00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes
63 [00:00:00.000,000] <inf> fs_zms: alloc wra: 0, f80
64 [00:00:00.000,000] <inf> fs_zms: data wra: 0, 8c
65 ITERATION: 1
66 ID: 1, IP Address: 172.16.254.1
67 Adding IP_ADDRESS 172.16.254.1 at id 1
68 Id: beefdead, Key: de ad be ef de ad be ef
69 Adding key/value at id beefdead
70 Id: 2, loop_cnt: 0
71 Adding counter at id 2
72 Id: 3, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 5
73 4 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
74 Adding Longarray at id 3
75 .
76 .
77 .
78 .
79 .
80 .
81 [00:00:00.000,000] <inf> fs_zms: 3 Sectors of 4096 bytes
82 [00:00:00.000,000] <inf> fs_zms: alloc wra: 0, f40
83 [00:00:00.000,000] <inf> fs_zms: data wra: 0, 80
84 ITERATION: 299
85 ID: 1, IP Address: 172.16.254.1
86 Adding IP_ADDRESS 172.16.254.1 at id 1
87 Id: beefdead, Key: de ad be ef de ad be ef
88 Adding key/value at id beefdead
89 Id: 2, loop_cnt: 298
90 Adding counter at id 2
91 Id: 3, Longarray: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 5
92 4 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f
93 Adding Longarray at id 3
94 Memory is full let's delete all items
95 Free space in storage is 8064 bytes
96 Sample code finished Successfully
97