Skip to content

Commit e649abe

Browse files
maje-embrlubos
authored andcommitted
samples: nfc: writable_ndef_msg: Migrate from NVS to ZMS for nRF54
These changes introduce the use of the ZMS file system instead of NVS for the nRF54 series. Ref: NCSDK-29636 Signed-off-by: Marcin Jelinski <[email protected]>
1 parent c14b5f7 commit e649abe

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_NVS=n
8+
CONFIG_ZMS=y
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_NVS=n
8+
CONFIG_ZMS=y

samples/nfc/writable_ndef_msg/src/ndef_file_m.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
#include <zephyr/kernel.h>
1717
#include <soc.h>
1818
#include <zephyr/device.h>
19-
#include <string.h>
2019
#include <zephyr/fs/nvs.h>
2120
#include <nfc/t4t/ndef_file.h>
2221
#include <nfc/ndef/uri_msg.h>
2322
#include <zephyr/storage/flash_map.h>
24-
23+
#if defined(CONFIG_NVS)
24+
#include <zephyr/fs/nvs.h>
25+
#elif defined(CONFIG_ZMS)
26+
#include <zephyr/fs/zms.h>
27+
#endif /* defined(CONFIG_NVS) */
2528
#include "ndef_file_m.h"
2629

2730
#define FLASH_URL_ADDRESS_ID 1 /**< Address of URL message in FLASH */
@@ -30,29 +33,44 @@ static const uint8_t m_url[] = /**< Default NDEF message: URL "nordicsemi.com".
3033
{'n', 'o', 'r', 'd', 'i', 'c', 's', 'e', 'm', 'i', '.', 'c', 'o', 'm'};
3134

3235
/* Flash partition for NVS */
33-
#define NVS_FLASH_DEVICE FIXED_PARTITION_DEVICE(storage_partition)
36+
#define FLASH_DEVICE FIXED_PARTITION_DEVICE(storage_partition)
3437
/* Flash block size in bytes */
35-
#define NVS_SECTOR_SIZE (DT_PROP(DT_CHOSEN(zephyr_flash), erase_block_size))
36-
#define NVS_SECTOR_COUNT 2
38+
#define SECTOR_SIZE (DT_PROP(DT_CHOSEN(zephyr_flash), erase_block_size))
39+
#define SECTOR_COUNT 2
3740
/* Start address of the filesystem in flash */
38-
#define NVS_STORAGE_OFFSET FIXED_PARTITION_OFFSET(storage_partition)
41+
#define STORAGE_OFFSET FIXED_PARTITION_OFFSET(storage_partition)
3942

43+
#if defined(CONFIG_NVS)
4044
static struct nvs_fs fs = {
41-
.sector_size = NVS_SECTOR_SIZE,
42-
.sector_count = NVS_SECTOR_COUNT,
43-
.offset = NVS_STORAGE_OFFSET,
45+
.sector_size = SECTOR_SIZE,
46+
.sector_count = SECTOR_COUNT,
47+
.offset = STORAGE_OFFSET,
48+
};
49+
#elif defined(CONFIG_ZMS)
50+
static struct zms_fs fs = {
51+
.sector_size = SECTOR_SIZE,
52+
.sector_count = SECTOR_COUNT,
53+
.offset = STORAGE_OFFSET,
4454
};
55+
#else
56+
#error "Please select file system."
57+
#endif /* defined(CONFIG_NVS) */
4558

4659
int ndef_file_setup(void)
4760
{
4861
int err;
4962

50-
fs.flash_device = NVS_FLASH_DEVICE;
63+
fs.flash_device = FLASH_DEVICE;
5164
if (fs.flash_device == NULL) {
5265
return -ENODEV;
5366
}
5467

68+
#if defined(CONFIG_NVS)
5569
err = nvs_mount(&fs);
70+
#elif defined(CONFIG_ZMS)
71+
err = zms_mount(&fs);
72+
#endif /* defined(CONFIG_NVS) */
73+
5674
if (err < 0) {
5775
printk("Cannot initialize NVS!\n");
5876
}
@@ -63,7 +81,11 @@ int ndef_file_setup(void)
6381
int ndef_file_update(uint8_t const *buff, uint32_t size)
6482
{
6583
/* Update FLASH file with new NDEF message. */
84+
#if defined(CONFIG_NVS)
6685
return nvs_write(&fs, FLASH_URL_ADDRESS_ID, buff, size);
86+
#elif defined(CONFIG_ZMS)
87+
return zms_write(&fs, FLASH_URL_ADDRESS_ID, buff, size);
88+
#endif /* defined(CONFIG_NVS) */
6789
}
6890

6991
/** .. include_startingpoint_ndef_file_rst */
@@ -120,7 +142,12 @@ int ndef_file_load(uint8_t *buff, uint32_t size)
120142
* if we can read it from flash, since we don't know the size read the
121143
* maximum possible
122144
*/
145+
#if defined(CONFIG_NVS)
123146
err = nvs_read(&fs, FLASH_URL_ADDRESS_ID, buff, size);
147+
#elif defined(CONFIG_ZMS)
148+
err = zms_read(&fs, FLASH_URL_ADDRESS_ID, buff, size);
149+
#endif /* defined(CONFIG_NVS) */
150+
124151
if (err > 0) { /* Item was found, show it */
125152
printk("Found NDEF file record.\n");
126153
} else {

0 commit comments

Comments
 (0)