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