Skip to content

Commit 5e0dff8

Browse files
samples: peripherals: spi_mngr: add SPI manager NOR flash sample
Add a non-blocking sample that exercises read, page program, and sector erase on the on-board external NOR flash through the SPI manager library. Buttons trigger the operations and the read result is logged as a hex dump. Wire up BOARD_EXTERNAL_MEMORY_* macros (SPIM instance, SCK/MOSI/MISO/CS and WP#/RST# strap pins) in the affected board-config.h files so the sample picks up the on-board flash automatically. Signed-off-by: Martynas Smilingis <martynas.smilingis@nordicsemi.no>
1 parent a83db65 commit 5e0dff8

13 files changed

Lines changed: 560 additions & 2 deletions

boards/nordic/bm_nrf54l15dk/include/board-config.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ extern "C" {
6363
#define BOARD_CONSOLE_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(7, 1)
6464
#endif
6565

66+
/* External SPI memory pins. */
67+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_INST
68+
#define BOARD_EXTERNAL_MEMORY_SPIM_INST NRF_SPIM00
69+
#endif
70+
71+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_PIN_SCK
72+
#define BOARD_EXTERNAL_MEMORY_SPIM_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(1, 2)
73+
#endif
74+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_PIN_MOSI
75+
#define BOARD_EXTERNAL_MEMORY_SPIM_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(2, 2)
76+
#endif
77+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_PIN_MISO
78+
#define BOARD_EXTERNAL_MEMORY_SPIM_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(4, 2)
79+
#endif
80+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_PIN_CSN
81+
#define BOARD_EXTERNAL_MEMORY_SPIM_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(5, 2)
82+
#endif
83+
#ifndef BOARD_EXTERNAL_MEMORY_PIN_WP
84+
#define BOARD_EXTERNAL_MEMORY_PIN_WP NRF_PIN_PORT_TO_PIN_NUMBER(3, 2)
85+
#endif
86+
#ifndef BOARD_EXTERNAL_MEMORY_PIN_RST
87+
#define BOARD_EXTERNAL_MEMORY_PIN_RST NRF_PIN_PORT_TO_PIN_NUMBER(0, 2)
88+
#endif
89+
6690
/* Application UART configuration */
6791
#ifndef BOARD_APP_UARTE_INST
6892
#define BOARD_APP_UARTE_INST NRF_UARTE30

boards/nordic/bm_nrf54lm20dk/include/board-config.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ extern "C" {
6363
#define BOARD_CONSOLE_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(19, 1)
6464
#endif
6565

66+
/* External SPI memory pins. */
67+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_INST
68+
#define BOARD_EXTERNAL_MEMORY_SPIM_INST NRF_SPIM00
69+
#endif
70+
71+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_PIN_SCK
72+
#define BOARD_EXTERNAL_MEMORY_SPIM_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(1, 2)
73+
#endif
74+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_PIN_MOSI
75+
#define BOARD_EXTERNAL_MEMORY_SPIM_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(2, 2)
76+
#endif
77+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_PIN_MISO
78+
#define BOARD_EXTERNAL_MEMORY_SPIM_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(4, 2)
79+
#endif
80+
#ifndef BOARD_EXTERNAL_MEMORY_SPIM_PIN_CSN
81+
#define BOARD_EXTERNAL_MEMORY_SPIM_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(5, 2)
82+
#endif
83+
#ifndef BOARD_EXTERNAL_MEMORY_PIN_WP
84+
#define BOARD_EXTERNAL_MEMORY_PIN_WP NRF_PIN_PORT_TO_PIN_NUMBER(3, 2)
85+
#endif
86+
#ifndef BOARD_EXTERNAL_MEMORY_PIN_RST
87+
#define BOARD_EXTERNAL_MEMORY_PIN_RST NRF_PIN_PORT_TO_PIN_NUMBER(0, 2)
88+
#endif
89+
6690
/* Application UART configuration */
6791
#ifndef BOARD_APP_UARTE_INST
6892
#define BOARD_APP_UARTE_INST NRF_UARTE30
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
**S115**:
2+
3+
.. list-table::
4+
:header-rows: 1
5+
6+
* - Hardware platform
7+
- PCA
8+
- Board target
9+
* - `nRF54L15 DK`_
10+
- PCA10156
11+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
12+
* - `nRF54L15 DK`_ (emulating nRF54L10)
13+
- PCA10156
14+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
15+
* - `nRF54L15 DK`_ (emulating nRF54L05)
16+
- PCA10156
17+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
18+
* - `nRF54LM20 DK`_
19+
- PCA10184
20+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice/mcuboot
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
**S145**:
2+
3+
.. list-table::
4+
:header-rows: 1
5+
6+
* - Hardware platform
7+
- PCA
8+
- Board target
9+
* - `nRF54L15 DK`_
10+
- PCA10156
11+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice/mcuboot
12+
* - `nRF54L15 DK`_ (emulating nRF54L10)
13+
- PCA10156
14+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice/mcuboot
15+
* - `nRF54L15 DK`_ (emulating nRF54L05)
16+
- PCA10156
17+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot
18+
* - `nRF54LM20 DK`_
19+
- PCA10184
20+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice/mcuboot
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
**S115**:
2+
3+
.. list-table::
4+
:header-rows: 1
5+
6+
* - Hardware platform
7+
- PCA
8+
- Board target
9+
* - `nRF54L15 DK`_
10+
- PCA10156
11+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
12+
* - `nRF54L15 DK`_ (emulating nRF54L10)
13+
- PCA10156
14+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
15+
* - `nRF54L15 DK`_ (emulating nRF54L05)
16+
- PCA10156
17+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
18+
* - `nRF54LM20 DK`_
19+
- PCA10184
20+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
**S145**:
2+
3+
.. list-table::
4+
:header-rows: 1
5+
6+
* - Hardware platform
7+
- PCA
8+
- Board target
9+
* - `nRF54L15 DK`_
10+
- PCA10156
11+
- bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice
12+
* - `nRF54L15 DK`_ (emulating nRF54L10)
13+
- PCA10156
14+
- bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice
15+
* - `nRF54L15 DK`_ (emulating nRF54L05)
16+
- PCA10156
17+
- bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice
18+
* - `nRF54LM20 DK`_
19+
- PCA10184
20+
- bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ No changes since the latest nRF Connect SDK Bare Metal release.
3333
Boards
3434
======
3535

36-
No changes since the latest nRF Connect SDK Bare Metal release.
36+
* Added ``BOARD_EXTERNAL_MEMORY_*`` macros to **bm_nrf54l15dk** and **bm_nrf54lm20dk** ``board-config.h`` (SPIM instance, SCK/MOSI/MISO/CS and WP#/RST# strap pins) for on-board SPI external flash. Other BM development kits do not include external flash memory on the board, so their ``board-config.h`` files omit these macros.
3737

3838
Build system
3939
============
@@ -120,7 +120,7 @@ No changes since the latest nRF Connect SDK Bare Metal release.
120120
Peripheral samples
121121
------------------
122122

123-
No changes since the latest nRF Connect SDK Bare Metal release.
123+
* Added the :ref:`spi_mngr_sample` sample, demonstrating non-blocking read, page program, and sector erase on the on-board external NOR flash using the :ref:`lib_bm_spi_mngr` library.
124124

125125
DFU samples
126126
-----------
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2026 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(spi_mngr)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright (c) 2026 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "SPI Manager sample"
8+
9+
config SAMPLE_SPI_MNGR_MSG
10+
string "Message to write to external NOR flash"
11+
default "Hello World!"
12+
help
13+
Payload bytes written to the external NOR flash when a program operation is triggered.
14+
Truncated to 64 bytes if longer.
15+
16+
module=SAMPLE_SPI_MNGR
17+
module-str=SPI manager sample
18+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
19+
20+
endmenu # "SPI Manager sample"
21+
22+
source "Kconfig.zephyr"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
.. _spi_mngr_sample:
2+
3+
SPI manager external memory
4+
###########################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The SPI manager sample demonstrates how to use the :ref:`lib_bm_spi_mngr` library with |BMlong| to perform non-blocking read, page program, and sector erase operations on the external flash memory of the development kit.
11+
12+
Requirements
13+
************
14+
15+
Use a development kit with **on-board SPI external flash** and ``BOARD_EXTERNAL_MEMORY_*`` in :file:`board-config.h` (**nRF54L15 DK** and **nRF54LM20 DK** only). The nRF54LV10 and nRF54LS05 DKs have no on-board external flash for this sample and are not listed.
16+
17+
The following board targets match :file:`sample.yaml`:
18+
19+
.. tabs::
20+
21+
.. group-tab:: Simple board variants
22+
23+
The following board variants do **not** have DFU capabilities:
24+
25+
.. include:: /includes/supported_boards_with_external_flash_memory_non-mcuboot_variants_s115.txt
26+
27+
.. include:: /includes/supported_boards_with_external_flash_memory_non-mcuboot_variants_s145.txt
28+
29+
.. group-tab:: MCUboot board variants
30+
31+
The following board variants have DFU capabilities:
32+
33+
.. include:: /includes/supported_boards_with_external_flash_memory_mcuboot_variants_s115.txt
34+
35+
.. include:: /includes/supported_boards_with_external_flash_memory_mcuboot_variants_s145.txt
36+
37+
.. important::
38+
Enable **external storage** in **nRF Connect for Desktop** → **Board Configurator**, then write the configuration to the board. Without that, the on-board flash may not be powered or routed to the SoC, and the sample does not work.
39+
40+
Overview
41+
********
42+
43+
The sample uses the SPI manager library to schedule read, program, and erase operations on the external flash without blocking the CPU. All operations target the same flash address (``FLASH_ADDR`` in :file:`main.c`) and share a single SPI manager instance.
44+
45+
The flash is the on-board MX25-class NOR device on the development kit. Its SPI and strap pins are defined by the ``BOARD_EXTERNAL_MEMORY_*`` macros in :file:`board-config.h`.
46+
47+
User interface
48+
**************
49+
50+
LED 0:
51+
Lit when the device is initialized.
52+
53+
Button 1:
54+
Erase the flash sector.
55+
56+
Button 2:
57+
Read from the flash and log the data as a hex dump.
58+
59+
Button 3:
60+
Program the message defined by :kconfig:option:`CONFIG_SAMPLE_SPI_MNGR_MSG` to the flash.
61+
62+
Configuration
63+
*************
64+
65+
Set the message written to flash through the following Kconfig option:
66+
67+
* :kconfig:option:`CONFIG_SAMPLE_SPI_MNGR_MSG`. String written to the external flash during a program operation. The string is truncated to 64 bytes if longer. The default value is ``"Hello World!"``.
68+
69+
Building and running
70+
********************
71+
72+
This sample can be found under :file:`samples/peripherals/spi_mngr/` in the |BMshort| folder structure.
73+
74+
For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`.
75+
76+
Testing
77+
=======
78+
79+
Make sure that you have enabled **external storage** in the Board Configurator (see the note in the Requirements section) before flashing the sample.
80+
81+
You can then test the sample by performing the following steps:
82+
83+
1. Compile and program the application.
84+
#. Open a serial terminal and observe the startup log, which lists the buttons and their operations.
85+
#. Press **Button 2** to read the on-board flash. The hex dump shows either all ``0xFF`` (erased) or whatever was last written to the address in a previous session.
86+
#. Press **Button 3** to program the configured message. The log prints ``Programming "Hello World!" @ 0x00100000``.
87+
#. Press **Button 2** again. The hex dump now starts with the message bytes, confirming that the write succeeded. For the default configuration, this is ``48 65 6c 6c 6f 20 57 6f 72 6c 64 21`` followed by ``0xFF`` padding.
88+
#. Power-cycle the board and press **Button 2** without programming again. The same message reappears, which confirms that the data is non-volatile and persists in the external flash across resets.
89+
#. Press **Button 1** to erase the sector. Wait a moment for the chip to finish the self-timed erase.
90+
#. Power-cycle the board and press **Button 2**. The hex dump shows all ``0xFF`` again, which confirms that the erase removed the data.
91+
#. Optionally, change :kconfig:option:`CONFIG_SAMPLE_SPI_MNGR_MSG` to a different string, rebuild, and repeat steps 4 to 6 to verify that your custom message is written and persists across reboots.

0 commit comments

Comments
 (0)