Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion boards/nordic/bm_nrf54l15dk/include/board-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,42 @@ extern "C" {
#define BOARD_CONSOLE_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(7, 1)
#endif

/* Application SPI master configuration */
#ifndef BOARD_APP_SPIM_INST
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need board config for the other boards as well.

Copy link
Copy Markdown
Contributor Author

@PizzaAllTheWay PizzaAllTheWay May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this does however mean we need a bit of refactoring of the code, because not all SoC support master and slave SPI peripherals at the same time without modifying the board (eks: nRF54LV10)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I added new boards and refactored code and documentation to fit with the new sample code

#define BOARD_APP_SPIM_INST NRF_SPIM21
#endif

#ifndef BOARD_APP_SPIM_PIN_SCK
#define BOARD_APP_SPIM_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(11, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_MOSI
#define BOARD_APP_SPIM_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(12, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_MISO
#define BOARD_APP_SPIM_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(13, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_CSN
#define BOARD_APP_SPIM_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(14, 1)
#endif

/* Application SPI slave configuration */
#ifndef BOARD_APP_SPIS_INST
#define BOARD_APP_SPIS_INST NRF_SPIS30
#endif

#ifndef BOARD_APP_SPIS_PIN_SCK
#define BOARD_APP_SPIS_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(0, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_MOSI
#define BOARD_APP_SPIS_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(1, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_MISO
#define BOARD_APP_SPIS_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(2, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_CSN
#define BOARD_APP_SPIS_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(3, 0)
#endif

/* Application UART configuration */
#ifndef BOARD_APP_UARTE_INST
#define BOARD_APP_UARTE_INST NRF_UARTE30
Expand Down Expand Up @@ -104,17 +140,20 @@ extern "C" {
#define BOARD_APP_LPUARTE_INST NRF_UARTE21
#endif

/* Shared with SPI master SCK. */
#ifndef BOARD_APP_LPUARTE_PIN_TX
#define BOARD_APP_LPUARTE_PIN_TX NRF_PIN_PORT_TO_PIN_NUMBER(11, 1)
#endif
/* Shared with SPI master MOSI. */
#ifndef BOARD_APP_LPUARTE_PIN_RX
#define BOARD_APP_LPUARTE_PIN_RX NRF_PIN_PORT_TO_PIN_NUMBER(12, 1)
#endif
#ifndef BOARD_APP_LPUARTE_PIN_REQ
#define BOARD_APP_LPUARTE_PIN_REQ NRF_PIN_PORT_TO_PIN_NUMBER(4, 0) /* Shared with button 3. */
#endif
/* Shared with LED 3 and SPI master CSN. */
#ifndef BOARD_APP_LPUARTE_PIN_RDY
#define BOARD_APP_LPUARTE_PIN_RDY NRF_PIN_PORT_TO_PIN_NUMBER(14, 1) /* Shared with LED 3. */
#define BOARD_APP_LPUARTE_PIN_RDY NRF_PIN_PORT_TO_PIN_NUMBER(14, 1)
#endif

#ifdef __cplusplus
Expand Down
36 changes: 36 additions & 0 deletions boards/nordic/bm_nrf54lm20dk/include/board-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,42 @@ extern "C" {
#define BOARD_CONSOLE_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(19, 1)
#endif

/* Application SPI master configuration */
#ifndef BOARD_APP_SPIM_INST
#define BOARD_APP_SPIM_INST NRF_SPIM21
#endif

#ifndef BOARD_APP_SPIM_PIN_SCK
#define BOARD_APP_SPIM_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(11, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_MOSI
#define BOARD_APP_SPIM_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(12, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_MISO
#define BOARD_APP_SPIM_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(13, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_CSN
#define BOARD_APP_SPIM_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(14, 1)
#endif

/* Application SPI slave configuration */
#ifndef BOARD_APP_SPIS_INST
#define BOARD_APP_SPIS_INST NRF_SPIS30
#endif

#ifndef BOARD_APP_SPIS_PIN_SCK
#define BOARD_APP_SPIS_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(0, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_MOSI
#define BOARD_APP_SPIS_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(1, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_MISO
#define BOARD_APP_SPIS_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(2, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_CSN
#define BOARD_APP_SPIS_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(3, 0)
#endif

/* Application UART configuration */
#ifndef BOARD_APP_UARTE_INST
#define BOARD_APP_UARTE_INST NRF_UARTE30
Expand Down
36 changes: 36 additions & 0 deletions boards/nordic/bm_nrf54ls05dk/include/board-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,42 @@ extern "C" {
#define BOARD_CONSOLE_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(7, 1)
#endif

/* Application SPI master configuration */
#ifndef BOARD_APP_SPIM_INST
#define BOARD_APP_SPIM_INST NRF_SPIM21
#endif

#ifndef BOARD_APP_SPIM_PIN_SCK
#define BOARD_APP_SPIM_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(2, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_MOSI
#define BOARD_APP_SPIM_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(3, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_MISO
#define BOARD_APP_SPIM_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(5, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_CSN
#define BOARD_APP_SPIM_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(6, 1)
#endif

/* Application SPI slave configuration */
#ifndef BOARD_APP_SPIS_INST
#define BOARD_APP_SPIS_INST NRF_SPIS22
#endif

#ifndef BOARD_APP_SPIS_PIN_SCK
#define BOARD_APP_SPIS_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(11, 1)
#endif
#ifndef BOARD_APP_SPIS_PIN_MOSI
#define BOARD_APP_SPIS_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(12, 1)
#endif
#ifndef BOARD_APP_SPIS_PIN_MISO
#define BOARD_APP_SPIS_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(21, 1)
#endif
#ifndef BOARD_APP_SPIS_PIN_CSN
#define BOARD_APP_SPIS_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(22, 1)
#endif

/* Application UART configuration */
#ifndef BOARD_APP_UARTE_INST
#define BOARD_APP_UARTE_INST NRF_UARTE21
Expand Down
36 changes: 36 additions & 0 deletions boards/nordic/bm_nrf54lv10dk/include/board-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,42 @@ extern "C" {
#define BOARD_CONSOLE_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(7, 1)
#endif

/* Application SPI master configuration */
#ifndef BOARD_APP_SPIM_INST
#define BOARD_APP_SPIM_INST NRF_SPIM21
#endif

#ifndef BOARD_APP_SPIM_PIN_SCK
#define BOARD_APP_SPIM_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(0, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_MOSI
#define BOARD_APP_SPIM_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(1, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_MISO
#define BOARD_APP_SPIM_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(2, 1)
#endif
#ifndef BOARD_APP_SPIM_PIN_CSN
#define BOARD_APP_SPIM_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(3, 1)
#endif

/* Application SPI slave configuration */
#ifndef BOARD_APP_SPIS_INST
#define BOARD_APP_SPIS_INST NRF_SPIS30
#endif

#ifndef BOARD_APP_SPIS_PIN_SCK
#define BOARD_APP_SPIS_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(0, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_MOSI
#define BOARD_APP_SPIS_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(1, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_MISO
#define BOARD_APP_SPIS_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(2, 0)
#endif
#ifndef BOARD_APP_SPIS_PIN_CSN
#define BOARD_APP_SPIS_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(3, 0)
#endif

/* Application UART configuration */
#ifndef BOARD_APP_UARTE_INST
#define BOARD_APP_UARTE_INST NRF_UARTE30
Expand Down
49 changes: 49 additions & 0 deletions doc/nrf-bm/includes/spi_board_connections.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. list-table:: SPIM and SPIS pin connections (board-config.h).
:widths: auto
:header-rows: 1

* - Development Kit
- nRF54L15 DK
- nRF54LM20 DK
- nRF54LS05 DK
- nRF54LV10 DK
* - SPIM SCK
- P1.11
- P1.11
- P1.02
- P1.00
* - SPIM MOSI
- P1.12
- P1.12
- P1.03
- P1.01
* - SPIM MISO
- P1.13
- P1.13
- P1.05
- P1.02
* - SPIM CSN
- P1.14
- P1.14
- P1.06
- P1.03
* - SPIS SCK
- P0.00
- P0.00
- P1.11
- P0.00
* - SPIS MOSI
- P0.01
- P0.01
- P1.12
- P0.01
* - SPIS MISO
- P0.02
- P0.02
- P1.21
- P0.02
* - SPIS CSN
- P0.03
- P0.03
- P1.22
- P0.03
1 change: 1 addition & 0 deletions doc/nrf-bm/links.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
.. _`How to flash an application`: https://docs.nordicsemi.com/bundle/nrf-connect-vscode/page/get_started/quick_debug.html#how-to-flash-an-application
.. _`How to connect to the terminal`: https://docs.nordicsemi.com/bundle/nrf-connect-vscode/page/get_started/quick_debug.html#how-to-connect-to-the-terminal
.. _`nRF Connect for Desktop`: https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Connect-for-desktop
.. _`Board Configurator`: https://docs.nordicsemi.com/bundle/nrf-connect-board-configurator/page/index.html
.. _`additional requirements`: https://docs.nordicsemi.com/bundle/nrf-connect-desktop/page/download_cfd.html
.. _`nRF Connect Device Manager`: https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-Device-Manager
.. _`nRF Toolbox`: https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Toolbox
Expand Down
2 changes: 1 addition & 1 deletion doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ No changes since the latest nRF Connect SDK Bare Metal release.
Peripheral samples
------------------

No changes since the latest nRF Connect SDK Bare Metal release.
* Added the :ref:`bm_spi_sample` sample.

DFU samples
-----------
Expand Down
12 changes: 12 additions & 0 deletions samples/peripherals/spi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Copyright (c) 2026 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(spi)

target_sources(app PRIVATE src/main.c)
21 changes: 21 additions & 0 deletions samples/peripherals/spi/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2026 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "SPI sample"

config SAMPLE_SPI_MSG
string "Message to send over SPI"
default "Hello World!"
help
The message that the SPI master sends to the SPI slave when the button is pressed.

module=SAMPLE_SPI
module-str=SPI Sample
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"

endmenu # "SPI sample"

source "Kconfig.zephyr"
88 changes: 88 additions & 0 deletions samples/peripherals/spi/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.. _bm_spi_sample:

SPI
###

.. contents::
:local:
:depth: 2

The SPI sample demonstrates how to configure and use the SPIM and SPIS peripherals with the nrfx drivers.

Requirements
************

The sample supports the following development kits:

.. tabs::

.. group-tab:: Simple board variants
Comment thread
eivindj-nordic marked this conversation as resolved.

The following board variants do **not** have DFU capabilities:

.. include:: /includes/supported_boards_all_non-mcuboot_variants_s115.txt

.. include:: /includes/supported_boards_all_non-mcuboot_variants_s145.txt

.. group-tab:: MCUboot board variants

The following board variants have DFU capabilities:

.. include:: /includes/supported_boards_all_mcuboot_variants_s115.txt

.. include:: /includes/supported_boards_all_mcuboot_variants_s145.txt

Overview
********

The sample initializes the **SPIM** and **SPIS** instances with the pins configured in the board's :file:`board-config.h`.
When **Button 2** is pressed, the master sends a configurable string (:kconfig:option:`CONFIG_SAMPLE_SPI_MSG`) to the slave.
The slave receives the data, logs it, and toggles **LED 2**.

User interface
**************

LED 0
Lit when the sample is initialized and ready.

LED 2
Toggles each time the SPI slave completes a reception.

Button 2
Sends a message from the local SPIM to the connected SPIS.

.. _bm_spi_wiring:

Wiring
======

The sample uses the **SPIM** and **SPIS** pins defined in the board's :file:`board-config.h` header (``BOARD_APP_SPIM_*`` and ``BOARD_APP_SPIS_*``).

.. include:: /includes/spi_board_connections.txt

Connect the four SPIM pins to the SPIS pins on the same board, matching each signal by name (SCK→SCK, MOSI→MOSI, MISO→MISO, CSN→CSN).

.. note:: Board-specific behavior

* **nRF54L15 DK** — SPI Master pins overlap with **LED 3** (P1.14, flickers during transfers) and **Button 0** (P1.13, do not press during transfers).
* **nRF54LV10 DK** — The SPI Slave pins (P0.00-P0.03) are shared with one of the debugger's virtual serial ports.
Before running the sample, open the `Board Configurator`_ app in `nRF Connect for Desktop`_ and disable the **Connect port VCOM** entry that is mapped to pins **P0.00-P0.03**, to release these pins from the debugger.
Leave the other **Connect port VCOM** entry (mapped to pins **P1.04-P1.07**) enabled, since it is the virtual serial port used to read the sample's log output.

Building and running
********************

This sample can be found under :file:`samples/peripherals/spi/` in the |BMshort| folder structure.

For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`.

Testing
=======

After building and flashing the sample, test it as follows:

1. Connect the four SPIM→SPIS signal pairs on the same board (see :ref:`Wiring <bm_spi_wiring>`).
#. Open the console log and verify that ``SPI sample initialized`` appears in the log.
#. Press **Button 2**.
#. Observe that the log shows a master "sent" entry and a slave "received" entry, both containing the :kconfig:option:`CONFIG_SAMPLE_SPI_MSG` string.
#. Observe that **LED 2** toggles on each completed reception.
Loading
Loading