Skip to content

Commit c887d5e

Browse files
butokfabiobaltieri
authored andcommitted
sample: zms: add ZMS sample Kconfig
- adds ability to change the ZMS sample MAX_ITERATIONS and DELETE_ITERATION parameters via Kconfig without manually modifying the source code. - adds ability to reduce flash memory wear on real devices by reducing the number of write iterations. Signed-off-by: Andrej Butok <[email protected]>
1 parent 40823be commit c887d5e

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

samples/subsys/fs/zms/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "ZMS sample configuration"
5+
6+
config MAX_ITERATIONS
7+
int "The number of iterations that the sample writes the all set of data."
8+
default 300
9+
range 1 300
10+
11+
config DELETE_ITERATION
12+
int "The number of iterations after the sample delete all set of data and verify that it has been deleted."
13+
default 10
14+
range 1 MAX_ITERATIONS
15+
16+
source "Kconfig.zephyr"

samples/subsys/fs/zms/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Overview
2020
A loop is executed where we mount the storage system, and then write all set
2121
of data.
2222

23-
Each DELETE_ITERATION period, we delete all set of data and verify that it has been deleted.
23+
Each CONFIG_DELETE_ITERATION period, we delete all set of data and verify that it has been deleted.
2424
We generate as well incremented ID/value pairs, we store them until storage is full, then we
2525
delete them and verify that storage is empty.
2626

samples/subsys/fs/zms/src/main.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ static struct zms_fs fs;
2626
#define CNT_ID 2
2727
#define LONG_DATA_ID 3
2828

29-
#define MAX_ITERATIONS 300
30-
#define DELETE_ITERATION 10
31-
3229
static int delete_and_verify_items(struct zms_fs *fs, uint32_t id)
3330
{
3431
int rc = 0;
@@ -112,7 +109,7 @@ int main(void)
112109
fs.sector_size = info.size;
113110
fs.sector_count = 3U;
114111

115-
for (i = 0; i < MAX_ITERATIONS; i++) {
112+
for (i = 0; i < CONFIG_MAX_ITERATIONS; i++) {
116113
rc = zms_mount(&fs);
117114
if (rc) {
118115
printk("Storage Init failed, rc=%d\n", rc);
@@ -195,16 +192,16 @@ int main(void)
195192
break;
196193
}
197194

198-
/* Each DELETE_ITERATION delete all basic items */
199-
if (!(i % DELETE_ITERATION) && (i)) {
195+
/* Each CONFIG_DELETE_ITERATION delete all basic items */
196+
if (!(i % CONFIG_DELETE_ITERATION) && (i)) {
200197
rc = delete_basic_items(&fs);
201198
if (rc) {
202199
break;
203200
}
204201
}
205202
}
206203

207-
if (i != MAX_ITERATIONS) {
204+
if (i != CONFIG_MAX_ITERATIONS) {
208205
printk("Error: Something went wrong at iteration %u rc=%d\n", i, rc);
209206
return 0;
210207
}

0 commit comments

Comments
 (0)