Skip to content

Cherry pick nrf spim rtio#4001

Merged
carlescufi merged 20 commits into
nrfconnect:mainfrom
bjarki-andreasen:nrf-spim-rtio
Jun 3, 2026
Merged

Cherry pick nrf spim rtio#4001
carlescufi merged 20 commits into
nrfconnect:mainfrom
bjarki-andreasen:nrf-spim-rtio

Conversation

@bjarki-andreasen
Copy link
Copy Markdown
Contributor

@bjarki-andreasen bjarki-andreasen commented Apr 17, 2026

Cherry pick nrf spim rtio. Adds RTIO support to SPIM

Created with

west ncs-cherry-pick -p nrf-spim-rtio --pr-number 107414 --pr-number 103497 --pr-number 108327

NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request Apr 17, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request Apr 17, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request Apr 27, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request May 1, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
bjarki-andreasen pushed a commit to NordicBuilder/sdk-nrf that referenced this pull request May 4, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request May 4, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
bjarki-andreasen pushed a commit to NordicBuilder/sdk-nrf that referenced this pull request May 4, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request May 7, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request May 18, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request May 27, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request May 27, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
@nika-nordic nika-nordic self-requested a review May 27, 2026 11:56
…uffer

The spi_rtio_copy implementation incorrectly sets up a transceive sqe
in place of a write or read when an empty "spacer" spi_buf is passed
which is not aligned with the "opposing" spi_buf. Using transceive in
these cases passes a NULL receive/transmit buffer with positive length,
which is a bug.

Some drivers have an additional check to clear the size if the buffer
is NULL, but we should not rely on this check in drivers as it is
duplicate code.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 652d2a7)
… thread safe

Don't rely on drivers protecting the spi_rtio ctx from multiple
threads as this is generic and could just be part of the spi_rtio
context to avoid duplicate code and thus make using it safer and
more efficient.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit e85a5ee)
Introduce spi_rtio_transceive_cb which is an implementation of the
spi_transceive_cb API based on the spi_rtio context.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit f37a79f)
The SPI_LOCK_ON flag is not compatible with RTIO, nor is the
related spi_release API. Introduce stub implementation for drivers to
use which simply returns -ENOTSUP and validate SPI_LOCK_ON within the
spi_rtio_transceive wrappers.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 5085a29)
…/spi/spi_rtio.h

Move the private spi_rtio.h header from the public path

 include/zephyr/drivers/spi/rtio.h

the the private path

  drivers/spi/spi_rtio.h

and update drivers to include it using a relative path.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit d99b89f)
Introduce support for NRF SPIM device based on RTIO.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 6f2829e)
…th rtio impl

Refactor the nrf_spim device driver to share the common code between
the nrf_spim_rtio implementation.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit e4d61fc)
… rtio case

Add nrf54h20dk and nrf54l15dk to drivers.spi.loopback.rtio test
case.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 09dd50b)
…me_buf_cmd

The nrf spim peripheral uses two EasyDMA channels, one read and one
write. Two channels can't access the same memory at the same time,
so if the spi frequency is too high, data will he lost/corrupted.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 7e5df6d)
…clude path

The header at drivers/spi/rtio.h was moved to a relative path, and
renamed "spi_rtio.h".

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 8ff7835)
…eep state set

The common pm_suspend implementation for the spi_nrfx_spim drivers
unconditionally sets the sleep state. The sleep state may not be
available, in which case we should not try to set it. Check
CONFIG_PINCTRL_KEEP_SLEEP_STATE and only try to set sleep state if
true.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 50df2d9)
… spi22 freq

The nrf54l15 SPIM22 instance does not support 16MHz, lower to 8MHz.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit a0d910e)
… SPIM

Ensure SPI pins are correctly configured before setting CS, by
configuring the SPIM before setting CS.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit ca9b6d4)
…platforms

The SPIM driver now produces the error
"Failed to configure nrfx driver" rather than
"Failed to initialize nrfx driver" as the driver now reconfigures
the SPIM. Update testcases to match.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit e511b52)
…r transfer

Update the tx and rx buffer progress after each transfer has
completed.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit ff6084f)
…ng buffers

The spi context tx_buf, rx_buf, tx_count and rx_count members are
modified during the transfer. These members are currently accessed
in spi_context_wait_for_completion when calculating the expected
timeout, which happens concurrently with the transfer being in
progress. This can lead to concurrency issues as the mentioned
members may be modified independently as they are being accessed by
the thread setting up the wait.

Remove this potential conflict by calculating the number of bytes
as part of spi_context_buffers_setup and store it, before the
transfer is started. Then used the stored value when setting up
the wait.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 05d6a7f)
The gpiote_nrfx.h header is needed for a macro used when handling
NRF52_ANOMALY_58

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 0068b2f)
…e cs is set

The current flow sets CS before the SPIM peripheral actually drives
the bus. This can cause SCK to be in the incorrect initial state
dictated by CPOL. New flow enables SPIM after it has been configured,
before CS is set, and disabled is after CS is cleared, thus the bus
is driven by SPIM during the entire transfer.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 407cedc)
… of controller

When configuring the nRF SPIM, the frequency needs to be limited by
the max frequency of the SPIM, which is specified in the devicetree.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit b2085e6)
… to 8MHz

The nrf7120 and nrf54l SPIM21 and SPIM22 instances do not support
16MHz, and the SPIS21 only supports up to 8MHz according to the
datasheet. The SPIS21 is the target device, which is what defines
the spi-max-frequency, compared to the max-frequency of the bus,
which does correctly set it to 8MHz for the SPIM instances.

Lower the spi-max-frequency to 8MHz, and remove the nrf7120 from
the 16Mhz and 32Mhz test case from testcase.yaml

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>

(cherry picked from commit 040034b)
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request May 27, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
@carlescufi carlescufi merged commit fbc1377 into nrfconnect:main Jun 3, 2026
15 checks passed
NordicBuilder added a commit to NordicBuilder/sdk-nrf that referenced this pull request Jun 3, 2026
Automatically created by action-manifest-pr GH action from PR:
nrfconnect/sdk-zephyr#4001

Signed-off-by: Nordic Builder <pylon@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants