@@ -205,7 +205,8 @@ static int spi_loopback_gpio_cs_loopback_init(void)
205
205
/* just a wrapper of the driver transceive call with ztest error assert */
206
206
static void spi_loopback_transceive (struct spi_dt_spec * const spec ,
207
207
const struct spi_buf_set * const tx ,
208
- const struct spi_buf_set * const rx )
208
+ const struct spi_buf_set * const rx ,
209
+ int expected_cs_count )
209
210
{
210
211
int ret ;
211
212
@@ -218,8 +219,7 @@ static void spi_loopback_transceive(struct spi_dt_spec *const spec,
218
219
ztest_test_skip ();
219
220
}
220
221
zassert_ok (ret , "SPI transceive failed, code %d" , ret );
221
- /* There should be two CS triggers during the transaction, start and end */
222
- zassert_false (spi_loopback_gpio_cs_loopback_check (2 ));
222
+ zassert_ok (spi_loopback_gpio_cs_loopback_check (expected_cs_count ));
223
223
zassert_ok (pm_device_runtime_put (spec -> bus ));
224
224
}
225
225
@@ -286,7 +286,7 @@ ZTEST(spi_loopback, test_spi_complete_multiple)
286
286
buffer_rx , BUF_SIZE ,
287
287
buffer2_rx , BUF2_SIZE );
288
288
289
- spi_loopback_transceive (spec , & tx , & rx );
289
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
290
290
291
291
spi_loopback_compare_bufs (buffer_tx , buffer_rx , BUF_SIZE ,
292
292
buffer_print_tx , buffer_print_rx );
@@ -316,7 +316,7 @@ ZTEST(spi_loopback, test_spi_complete_multiple_timed)
316
316
317
317
/* since this is a test program, there shouldn't be much to interfere with measurement */
318
318
start_time = k_cycle_get_32 ();
319
- spi_loopback_transceive (spec , & tx , & rx );
319
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
320
320
end_time = k_cycle_get_32 ();
321
321
322
322
zassert_ok (pm_device_runtime_put (spec -> bus ));
@@ -392,7 +392,7 @@ void spi_loopback_test_mode(struct spi_dt_spec *spec, bool cpol, bool cpha)
392
392
spec -> config .operation &= ~SPI_MODE_CPHA ;
393
393
}
394
394
395
- spi_loopback_transceive (spec , & tx , & rx );
395
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
396
396
397
397
spec -> config .operation = original_op ;
398
398
@@ -447,7 +447,7 @@ ZTEST(spi_loopback, test_spi_null_tx_buf)
447
447
448
448
(void )memset (buffer_rx , 0x77 , BUF_SIZE );
449
449
450
- spi_loopback_transceive (spec , & tx , & rx );
450
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
451
451
452
452
spi_loopback_compare_bufs (expected_nop_return_buf , buffer_rx , BUF_SIZE ,
453
453
buffer_print_rx , buffer_print_rx );
@@ -463,7 +463,7 @@ ZTEST(spi_loopback, test_spi_rx_half_start)
463
463
464
464
(void )memset (buffer_rx , 0 , BUF_SIZE );
465
465
466
- spi_loopback_transceive (spec , & tx , & rx );
466
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
467
467
468
468
spi_loopback_compare_bufs (buffer_tx , buffer_rx , 8 ,
469
469
buffer_print_tx , buffer_print_rx );
@@ -485,7 +485,7 @@ ZTEST(spi_loopback, test_spi_rx_half_end)
485
485
486
486
(void )memset (buffer_rx , 0 , BUF_SIZE );
487
487
488
- spi_loopback_transceive (spec , & tx , & rx );
488
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
489
489
490
490
spi_loopback_compare_bufs (buffer_tx + 8 , buffer_rx , 8 ,
491
491
buffer_print_tx , buffer_print_rx );
@@ -509,7 +509,7 @@ ZTEST(spi_loopback, test_spi_rx_every_4)
509
509
510
510
(void )memset (buffer_rx , 0 , BUF_SIZE );
511
511
512
- spi_loopback_transceive (spec , & tx , & rx );
512
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
513
513
514
514
spi_loopback_compare_bufs (buffer_tx + 4 , buffer_rx , 4 ,
515
515
buffer_print_tx , buffer_print_rx );
@@ -537,7 +537,7 @@ ZTEST(spi_loopback, test_spi_rx_bigger_than_tx)
537
537
538
538
(void )memset (buffer_rx , 0xff , BUF_SIZE );
539
539
540
- spi_loopback_transceive (spec , & tx , & rx );
540
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
541
541
542
542
spi_loopback_compare_bufs (buffer_tx , buffer_rx , tx_buf_size ,
543
543
buffer_print_tx , buffer_print_rx );
@@ -557,7 +557,7 @@ ZTEST(spi_loopback, test_spi_complete_large_transfers)
557
557
const struct spi_buf_set rx = spi_loopback_setup_xfer (rx_bufs_pool , 1 ,
558
558
large_buffer_rx , BUF3_SIZE );
559
559
560
- spi_loopback_transceive (spec , & tx , & rx );
560
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
561
561
562
562
zassert_false (memcmp (large_buffer_tx , large_buffer_rx , BUF3_SIZE ),
563
563
"Large Buffer contents are different" );
@@ -572,7 +572,7 @@ ZTEST(spi_loopback, test_spi_null_tx_buf_set)
572
572
573
573
(void )memset (buffer_rx , 0x77 , BUF_SIZE );
574
574
575
- spi_loopback_transceive (spec , NULL , & rx );
575
+ spi_loopback_transceive (spec , NULL , & rx , 2 );
576
576
577
577
spi_loopback_compare_bufs (expected_nop_return_buf , buffer_rx , BUF_SIZE ,
578
578
buffer_print_rx , buffer_print_rx );
@@ -584,14 +584,14 @@ ZTEST(spi_loopback, test_spi_null_rx_buf_set)
584
584
const struct spi_buf_set tx = spi_loopback_setup_xfer (tx_bufs_pool , 1 ,
585
585
buffer_tx , BUF_SIZE );
586
586
587
- spi_loopback_transceive (spec , & tx , NULL );
587
+ spi_loopback_transceive (spec , & tx , NULL , 2 );
588
588
}
589
589
590
590
ZTEST (spi_loopback , test_spi_null_tx_rx_buf_set )
591
591
{
592
592
struct spi_dt_spec * spec = loopback_specs [spec_idx ];
593
593
594
- spi_loopback_transceive (spec , NULL , NULL );
594
+ spi_loopback_transceive (spec , NULL , NULL , 0 );
595
595
}
596
596
597
597
ZTEST (spi_loopback , test_nop_nil_bufs )
@@ -600,7 +600,7 @@ ZTEST(spi_loopback, test_nop_nil_bufs)
600
600
const struct spi_buf_set tx = spi_loopback_setup_xfer (tx_bufs_pool , 1 , NULL , 0 );
601
601
const struct spi_buf_set rx = spi_loopback_setup_xfer (rx_bufs_pool , 1 , NULL , 0 );
602
602
603
- spi_loopback_transceive (spec , & tx , & rx );
603
+ spi_loopback_transceive (spec , & tx , & rx , 0 );
604
604
605
605
/* nothing really to check here, check is done in spi_loopback_transceive */
606
606
}
@@ -615,7 +615,7 @@ ZTEST(spi_loopback, test_spi_write_back)
615
615
616
616
memcpy (buffer_rx , tx_data , sizeof (tx_data ));
617
617
618
- spi_loopback_transceive (spec , & set , & set );
618
+ spi_loopback_transceive (spec , & set , & set , 2 );
619
619
620
620
spi_loopback_compare_bufs (tx_data , buffer_rx , BUF_SIZE ,
621
621
buffer_print_tx , buffer_print_rx );
@@ -636,7 +636,7 @@ ZTEST(spi_loopback, test_spi_same_buf_cmd)
636
636
637
637
memcpy (buffer_rx , tx_data , BUF_SIZE );
638
638
639
- spi_loopback_transceive (spec , & tx , & rx );
639
+ spi_loopback_transceive (spec , & tx , & rx , 2 );
640
640
641
641
spi_loopback_compare_bufs (tx_data , buffer_rx , 1 ,
642
642
buffer_print_tx , buffer_print_rx );
@@ -667,7 +667,7 @@ static void spi_loopback_test_word_size(struct spi_dt_spec *spec,
667
667
const struct spi_buf_set rx = spi_loopback_setup_xfer (rx_bufs_pool , 1 ,
668
668
rx_buffer , buffer_size );
669
669
670
- spi_loopback_transceive (spec_copy , & tx , & rx );
670
+ spi_loopback_transceive (spec_copy , & tx , & rx , 2 );
671
671
672
672
zassert_false (memcmp (compare_data , rx_buffer , buffer_size ),
673
673
"%d-bit word buffer contents are different" , word_size );
@@ -961,11 +961,11 @@ ZTEST(spi_extra_api_features, test_spi_lock_release)
961
961
lock_spec -> config .operation |= SPI_LOCK_ON ;
962
962
963
963
zassert_ok (pm_device_runtime_get (lock_spec -> bus ));
964
- spi_loopback_transceive (lock_spec , & tx , & rx );
964
+ spi_loopback_transceive (lock_spec , & tx , & rx , 2 );
965
965
zassert_false (spi_release_dt (lock_spec ), "SPI release failed" );
966
966
zassert_ok (pm_device_runtime_put (lock_spec -> bus ));
967
967
968
- spi_loopback_transceive (try_spec , & tx , & rx );
968
+ spi_loopback_transceive (try_spec , & tx , & rx , 2 );
969
969
970
970
lock_spec -> config .operation &= ~SPI_LOCK_ON ;
971
971
}
@@ -1021,7 +1021,7 @@ ZTEST(spi_extra_api_features, test_spi_hold_on_cs)
1021
1021
}
1022
1022
1023
1023
/* now just do a normal transfer to make sure there was no leftover effects */
1024
- spi_loopback_transceive (hold_spec , & tx , & rx );
1024
+ spi_loopback_transceive (hold_spec , & tx , & rx , 2 );
1025
1025
1026
1026
return ;
1027
1027
0 commit comments