-
Notifications
You must be signed in to change notification settings - Fork 39
samples: SPI sample #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PizzaAllTheWay
wants to merge
1
commit into
nrfconnect:main
Choose a base branch
from
PizzaAllTheWay:spi-sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
samples: SPI sample #761
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
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. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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