Skip to content

Commit 2d97877

Browse files
bjarki-andreasennordicjm
authored andcommitted
[nrf fromtree] tests: spi: loopback: get spi controller before timed transfer
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]> (cherry picked from commit 3923365)
1 parent b55f9a6 commit 2d97877

File tree

1 file changed

+8
-0
lines changed
  • tests/drivers/spi/spi_loopback/src

1 file changed

+8
-0
lines changed

tests/drivers/spi/spi_loopback/src/spi.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,19 @@ ZTEST(spi_loopback, test_spi_complete_multiple_timed)
293293
uint32_t start_time, end_time, cycles_spent;
294294
uint64_t time_spent_us, expected_transfer_time_us, latency_measurement;
295295

296+
/*
297+
* spi_loopback_transceive() does an inline pm_device_runtime_get(), but since we are
298+
* timing the transfer, we need to get the SPI controller before we start the measurement.
299+
*/
300+
zassert_ok(pm_device_runtime_get(spec->bus));
301+
296302
/* since this is a test program, there shouldn't be much to interfere with measurement */
297303
start_time = k_cycle_get_32();
298304
spi_loopback_transceive(spec, &tx, &rx);
299305
end_time = k_cycle_get_32();
300306

307+
zassert_ok(pm_device_runtime_put(spec->bus));
308+
301309
if (end_time >= start_time) {
302310
cycles_spent = end_time - start_time;
303311
} else {

0 commit comments

Comments
 (0)