Skip to content

Commit e0edbac

Browse files
MirkoCovizzib-gent
authored andcommitted
samples: peripherals: add storage sample
Adds a storage sample based on the `bm_storage` library. Signed-off-by: Mirko Covizzi <[email protected]> Co-authored-by: Bartosz Gentkowski <[email protected]>
1 parent de067dc commit e0edbac

File tree

7 files changed

+523
-0
lines changed

7 files changed

+523
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(storage)
11+
12+
target_sources(app PRIVATE src/main.c)

samples/peripherals/storage/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "Storage sample"
8+
9+
module=STORAGE_SAMPLE
10+
module-dep=LOG
11+
module-str=Storage Sample
12+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
13+
14+
endmenu # "Storage sample"
15+
16+
source "Kconfig.zephyr"
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
.. _storage_sample:
2+
3+
Storage
4+
#######
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Storage sample demonstrates how to configure and use storage instances with event callbacks.
11+
Depending on the configuration selected, the sample uses either the SoftDevice storage backend or the RRAM storage backend.
12+
13+
Refer to the `Kconfig fragments`_ section for more information on configuration.
14+
15+
Requirements
16+
************
17+
18+
The sample supports the following development kits:
19+
20+
.. list-table::
21+
:header-rows: 1
22+
23+
* - Hardware platform
24+
- PCA
25+
- Board target
26+
- DFU-enabled board target
27+
* - `nRF54L15 DK`_
28+
- PCA10156
29+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
30+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
31+
* - `nRF54L15 DK`_ (emulating nRF54L10)
32+
- PCA10156
33+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
34+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
35+
* - `nRF54L15 DK`_ (emulating nRF54L05)
36+
- PCA10156
37+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
38+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
39+
40+
Kconfig fragments
41+
*****************
42+
43+
By default, the sample uses the SoftDevice storage backend.
44+
To build the sample for the RRAM backend, you can use the :file:`storage-rram.conf` Kconfig fragment.
45+
To configure it for this sample, follow the steps outlined in the `Configuring and building the sample`_ section.
46+
47+
Building and running
48+
********************
49+
50+
This sample can be found under :file:`samples/peripherals/storage/` in the |BMshort| folder structure.
51+
52+
.. include:: /includes/create_sample.txt
53+
54+
.. include:: /includes/configure_and_build_sample.txt
55+
56+
.. include:: /includes/program_sample.txt
57+
58+
Testing
59+
=======
60+
61+
You can test this sample by performing the following steps:
62+
63+
1. Compile and program the application.
64+
#. Observe that the following output is printed:
65+
66+
* For the SoftDevice storage backend:
67+
68+
.. code-block:: console
69+
70+
[00:00:00.005,789] <inf> app: Storage sample started
71+
[00:00:00.005,810] <inf> nrf_sdh: State change request: enable
72+
[00:00:00.011,214] <inf> app: Reading persisted data
73+
[00:00:00.011,232] <inf> app: output A:
74+
48 65 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 |Hello... ........
75+
[00:00:00.011,244] <inf> app: output B:
76+
57 6f 72 6c 64 21 00 00 00 00 00 00 00 00 00 00 |World!.. ........
77+
[00:00:00.011,250] <inf> app: Erasing in Partition A, addr: 0x0015B000, size: 16
78+
[00:00:00.011,297] <inf> app: Erasing in Partition B, addr: 0x0015C000, size: 16
79+
[00:00:00.011,304] <inf> app: Waiting for writes to complete...
80+
[00:00:00.012,370] <inf> app: Handler A: bm_storage_evt: WRITE_RESULT 0, DISPATCH_TYPE 1
81+
[00:00:00.013,444] <inf> app: Handler B: bm_storage_evt: WRITE_RESULT 0, DISPATCH_TYPE 1
82+
[00:00:00.013,468] <inf> app: output A:
83+
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........
84+
[00:00:00.013,481] <inf> app: output B:
85+
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........
86+
[00:00:00.013,496] <inf> nrf_sdh: State change request: disable
87+
[00:00:00.013,531] <inf> app: Writing in Partition A, addr: 0x0015B000, size: 16
88+
[00:00:00.013,659] <inf> app: Handler A: bm_storage_evt: WRITE_RESULT 0, DISPATCH_TYPE 0
89+
[00:00:00.013,664] <inf> app: Writing in Partition B, addr: 0x0015C000, size: 16
90+
[00:00:00.013,769] <inf> app: Handler B: bm_storage_evt: WRITE_RESULT 0, DISPATCH_TYPE 0
91+
[00:00:00.013,775] <inf> app: Waiting for writes to complete...
92+
[00:00:00.013,789] <inf> app: output A:
93+
48 65 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 |Hello... ........
94+
[00:00:00.013,801] <inf> app: output B:
95+
57 6f 72 6c 64 21 00 00 00 00 00 00 00 00 00 00 |World!.. ........
96+
[00:00:00.013,807] <inf> app: Storage sample finished.
97+
98+
* For the RRAM storage backend:
99+
100+
.. code-block:: console
101+
102+
[00:00:00.005,783] <inf> app: Storage sample started
103+
[00:00:00.005,791] <inf> app: Reading persisted data
104+
[00:00:00.005,808] <inf> app: output A:
105+
48 65 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 |Hello... ........
106+
[00:00:00.005,820] <inf> app: output B:
107+
57 6f 72 6c 64 21 00 00 00 00 00 00 00 00 00 00 |World!.. ........
108+
[00:00:00.005,825] <inf> app: Erasing in Partition A, addr: 0x0015B000, size: 16
109+
[00:00:00.005,835] <inf> app: Handler A: bm_storage_evt: WRITE_RESULT 0, DISPATCH_TYPE 0
110+
[00:00:00.005,886] <inf> app: Erasing in Partition B, addr: 0x0015C000, size: 16
111+
[00:00:00.005,894] <inf> app: Handler B: bm_storage_evt: WRITE_RESULT 0, DISPATCH_TYPE 0
112+
[00:00:00.005,949] <inf> app: Waiting for writes to complete...
113+
[00:00:00.005,960] <inf> app: output A:
114+
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........
115+
[00:00:00.005,972] <inf> app: output B:
116+
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |........ ........
117+
[00:00:00.005,977] <inf> app: Writing in Partition A, addr: 0x0015B000, size: 16
118+
[00:00:00.005,985] <inf> app: Handler A: bm_storage_evt: WRITE_RESULT 0, DISPATCH_TYPE 0
119+
[00:00:00.006,008] <inf> app: Writing in Partition B, addr: 0x0015C000, size: 16
120+
[00:00:00.006,016] <inf> app: Handler B: bm_storage_evt: WRITE_RESULT 0, DISPATCH_TYPE 0
121+
[00:00:00.006,042] <inf> app: Waiting for writes to complete...
122+
[00:00:00.006,053] <inf> app: output A:
123+
48 65 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 |Hello... ........
124+
[00:00:00.006,065] <inf> app: output B:
125+
57 6f 72 6c 64 21 00 00 00 00 00 00 00 00 00 00 |World!.. ........
126+
[00:00:00.006,071] <inf> app: Storage sample finished.
127+
128+
.. note::
129+
130+
The addresses may vary depending on the board target selected.

samples/peripherals/storage/prj.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CONFIG_LOG=y
2+
CONFIG_LOG_BACKEND_BM_UARTE=y
3+
4+
CONFIG_SOFTDEVICE=y
5+
CONFIG_NRF_SDH=y
6+
7+
# Enable RNG
8+
CONFIG_NRF_SECURITY=y
9+
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
10+
CONFIG_PSA_WANT_GENERATE_RANDOM=y
11+
12+
CONFIG_BM_STORAGE=y
13+
CONFIG_RING_BUFFER=y
14+
CONFIG_BM_STORAGE_BACKEND_SD=y
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
sample:
2+
name: Storage Sample
3+
tests:
4+
sample.storage:
5+
sysbuild: true
6+
build_only: true
7+
integration_platforms:
8+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
9+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
10+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
11+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
12+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
13+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
14+
platform_allow:
15+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
16+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
17+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
18+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
19+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
20+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
21+
tags: ci_build
22+
sample.storage_rram:
23+
sysbuild: true
24+
build_only: true
25+
integration_platforms:
26+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
27+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
28+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
29+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
30+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
31+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
32+
platform_allow:
33+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
34+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
35+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
36+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
37+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
38+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
39+
extra_args: EXTRA_CONF_FILE=storage-rram.conf
40+
tags: ci_build

0 commit comments

Comments
 (0)