Skip to content

Commit cb13433

Browse files
samples: add SPI master/slave peripheral sample
Add SPI sample with SPIM and SPIS support for single-device loopback and two-device setups (one or two data paths). Button 2 triggers a master transfer, LED 2 toggles on slave reception. Includes: - SPIM and SPIS initialization and transfer handling - Board configuration with default pin mappings - Kconfig option for configurable message string - Documentation with wiring guide, pin conflict notes, and testing steps for all three wiring configurations Signed-off-by: Martynas Smilingis <martynas.smilingis@nordicsemi.no>
1 parent fc29f50 commit cb13433

9 files changed

Lines changed: 597 additions & 5 deletions

File tree

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

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

66+
/* Application SPI master configuration */
67+
#ifndef BOARD_APP_SPIM_INST
68+
#define BOARD_APP_SPIM_INST NRF_SPIM21
69+
#endif
70+
71+
#ifndef BOARD_APP_SPIM_PIN_SCK
72+
#define BOARD_APP_SPIM_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(11, 1)
73+
#endif
74+
#ifndef BOARD_APP_SPIM_PIN_MOSI
75+
#define BOARD_APP_SPIM_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(12, 1)
76+
#endif
77+
#ifndef BOARD_APP_SPIM_PIN_MISO
78+
#define BOARD_APP_SPIM_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(13, 1) /* Shared with Button 0. */
79+
#endif
80+
#ifndef BOARD_APP_SPIM_PIN_CSN
81+
#define BOARD_APP_SPIM_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(14, 1) /* Shared with LED 3. */
82+
#endif
83+
84+
/* Application SPI slave configuration */
85+
#ifndef BOARD_APP_SPIS_INST
86+
#define BOARD_APP_SPIS_INST NRF_SPIS30
87+
#endif
88+
89+
#ifndef BOARD_APP_SPIS_PIN_SCK
90+
#define BOARD_APP_SPIS_PIN_SCK NRF_PIN_PORT_TO_PIN_NUMBER(0, 0)
91+
#endif
92+
#ifndef BOARD_APP_SPIS_PIN_MOSI
93+
#define BOARD_APP_SPIS_PIN_MOSI NRF_PIN_PORT_TO_PIN_NUMBER(1, 0)
94+
#endif
95+
#ifndef BOARD_APP_SPIS_PIN_MISO
96+
#define BOARD_APP_SPIS_PIN_MISO NRF_PIN_PORT_TO_PIN_NUMBER(2, 0)
97+
#endif
98+
#ifndef BOARD_APP_SPIS_PIN_CSN
99+
#define BOARD_APP_SPIS_PIN_CSN NRF_PIN_PORT_TO_PIN_NUMBER(3, 0)
100+
#endif
101+
66102
/* Application UART configuration */
67103
#ifndef BOARD_APP_UARTE_INST
68104
#define BOARD_APP_UARTE_INST NRF_UARTE30
69105
#endif
70106

71107
#ifndef BOARD_APP_UARTE_PIN_TX
72-
#define BOARD_APP_UARTE_PIN_TX NRF_PIN_PORT_TO_PIN_NUMBER(0, 0)
108+
#define BOARD_APP_UARTE_PIN_TX NRF_PIN_PORT_TO_PIN_NUMBER(0, 0) /* Shared with SPI slave SCK. */
73109
#endif
74110
#ifndef BOARD_APP_UARTE_PIN_RX
75-
#define BOARD_APP_UARTE_PIN_RX NRF_PIN_PORT_TO_PIN_NUMBER(1, 0)
111+
#define BOARD_APP_UARTE_PIN_RX NRF_PIN_PORT_TO_PIN_NUMBER(1, 0) /* Shared with SPI slave MOSI. */
76112
#endif
77113
#ifndef BOARD_APP_UARTE_PIN_RTS
78-
#define BOARD_APP_UARTE_PIN_RTS NRF_PIN_PORT_TO_PIN_NUMBER(2, 0)
114+
#define BOARD_APP_UARTE_PIN_RTS NRF_PIN_PORT_TO_PIN_NUMBER(2, 0) /* Shared with SPI slave MISO. */
79115
#endif
80116
#ifndef BOARD_APP_UARTE_PIN_CTS
81-
#define BOARD_APP_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(3, 0)
117+
#define BOARD_APP_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(3, 0) /* Shared with SPI slave CSN. */
82118
#endif
83119

84120
/* Application LPUART configuration */
85121
#ifndef BOARD_APP_LPUARTE_INST
86122
#define BOARD_APP_LPUARTE_INST NRF_UARTE21
87123
#endif
88124

125+
/* Shared with SPI master SCK. */
89126
#ifndef BOARD_APP_LPUARTE_PIN_TX
90127
#define BOARD_APP_LPUARTE_PIN_TX NRF_PIN_PORT_TO_PIN_NUMBER(11, 1)
91128
#endif
129+
/* Shared with SPI master MOSI. */
92130
#ifndef BOARD_APP_LPUARTE_PIN_RX
93131
#define BOARD_APP_LPUARTE_PIN_RX NRF_PIN_PORT_TO_PIN_NUMBER(12, 1)
94132
#endif
95133
#ifndef BOARD_APP_LPUARTE_PIN_REQ
96134
#define BOARD_APP_LPUARTE_PIN_REQ NRF_PIN_PORT_TO_PIN_NUMBER(4, 0) /* Shared with button 3. */
97135
#endif
136+
/* Shared with LED 3 and SPI master CSN. */
98137
#ifndef BOARD_APP_LPUARTE_PIN_RDY
99-
#define BOARD_APP_LPUARTE_PIN_RDY NRF_PIN_PORT_TO_PIN_NUMBER(14, 1) /* Shared with LED 3. */
138+
#define BOARD_APP_LPUARTE_PIN_RDY NRF_PIN_PORT_TO_PIN_NUMBER(14, 1)
100139
#endif
101140

102141
#ifdef __cplusplus
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. list-table:: nRF54L15 DK — SPIM and SPIS (see :file:`board-config.h` for instance names and overrides).
2+
:widths: auto
3+
:header-rows: 1
4+
5+
* - Function
6+
- SPIM (master) pin
7+
- SPIS (slave) pin
8+
* - SCK
9+
- P1.11
10+
- P0.0
11+
* - MOSI
12+
- P1.12
13+
- P0.1
14+
* - MISO
15+
- P1.13
16+
- P0.2
17+
* - CSN
18+
- P1.14
19+
- P0.3

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ Peripheral samples
380380
------------------
381381

382382
* Added the :ref:`bm_ppi_sample` sample.
383+
* Added the :ref:`bm_spi_sample` sample.
383384

384385
* :ref:`bm_lpuarte_sample` sample:
385386

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(spi)
11+
12+
target_sources(app PRIVATE src/main.c)

samples/peripherals/spi/Kconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright (c) 2026 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "SPI sample"
8+
9+
config SAMPLE_SPI_MSG
10+
string "Message to send over SPI"
11+
default "Hello World!"
12+
help
13+
The message that the SPI master sends to the SPI slave when the button is pressed.
14+
15+
module=SAMPLE_SPI
16+
module-str=SPI Sample
17+
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
18+
19+
endmenu # "SPI sample"
20+
21+
source "Kconfig.zephyr"

0 commit comments

Comments
 (0)