Skip to content

Spi loopback adjustments #91194

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

Conversation

bjarki-andreasen
Copy link
Collaborator

Adjust the spi_loopback test to use a more optimal method of determining stack sizes used internally, and produce a more accurate transfer time measurement when pm device runtime is enabled.

The spi_loopback test suite creates three internal threads. The
stack sizes for these threads is hardcoded to 512, which is to little
for some socs, namely the nrf54h20 cpuapp if pm device runtime is
enabled. Instead, determine the stack sizes the same way ztest
stack sizes are determined.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
The test which measures and validates transfer times is using the
helper spi_loopback_transceive() to perform the transfer. This
helper internally gets the spi controller, which is useful for
most tests, but for this one, it means the time to get and put
the spi controller is included in the transfer time measurement.

This commit gets the spi controller before calling
spi_loopback_transceive() which results in only the actual
transfer time being measured.

Before this commit, on the nrf54h20:

  START - test_spi_complete_multiple_timed
  Transfer took 745 us vs theoretical minimum 108 us
  Latency measurement: 637 us
   PASS - test_spi_complete_multiple_timed in 0.008 seconds

  START - test_spi_complete_multiple_timed
  Transfer took 700 us vs theoretical minimum 54 us
  Latency measurement: 646 us

      Assertion failed at ...
  Very high latency
   FAIL - test_spi_complete_multiple_timed in 0.027 seconds

After this commit:

  START - test_spi_complete_multiple_timed
  Transfer took 250 us vs theoretical minimum 108 us
  Latency measurement: 142 us
   PASS - test_spi_complete_multiple_timed in 0.008 seconds

  START - test_spi_complete_multiple_timed
  Transfer took 204 us vs theoretical minimum 54 us
  Latency measurement: 150 us
   PASS - test_spi_complete_multiple_timed in 0.008 seconds

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
Copy link

sonarqubecloud bot commented Jun 6, 2025

@bjarki-andreasen
Copy link
Collaborator Author

@decsny The timing measurements are great! Really puts into perspective how inefficient "inline PM" is :) 500us of get/put for every total transfer time of around 200us is wild

@danieldegrasse danieldegrasse merged commit 3923365 into zephyrproject-rtos:main Jun 10, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants