1
1
/*
2
+ * Copyright 2025 NXP
2
3
* Copyright (c) 2017 Intel Corporation.
3
4
*
4
5
* SPDX-License-Identifier: Apache-2.0
@@ -96,6 +97,16 @@ static void to_display_format(const uint8_t *src, size_t size, char *dst)
96
97
}
97
98
}
98
99
100
+ /* just a wrapper of the driver transceive call with ztest error assert */
101
+ static void spi_loopback_transceive (struct spi_dt_spec * const spec ,
102
+ const struct spi_buf_set * const tx ,
103
+ const struct spi_buf_set * const rx )
104
+ {
105
+ int ret = spi_transceive_dt (spec , tx , rx );
106
+
107
+ zassert_false (ret , "SPI transceive failed, code %d" , ret );
108
+ }
109
+
99
110
/*
100
111
**************
101
112
* Test cases *
@@ -130,16 +141,10 @@ static int spi_complete_multiple(struct spi_dt_spec *spec)
130
141
rx_bufs [1 ].buf = buffer2_rx ;
131
142
rx_bufs [1 ].len = BUF2_SIZE ;
132
143
133
- int ret ;
134
144
135
145
LOG_INF ("Start complete multiple" );
136
146
137
- ret = spi_transceive_dt (spec , & tx , & rx );
138
- if (ret ) {
139
- LOG_ERR ("Code %d" , ret );
140
- zassert_false (ret , "SPI transceive failed" );
141
- return ret ;
142
- }
147
+ spi_loopback_transceive (spec , & tx , & rx );
143
148
144
149
if (memcmp (buffer_tx , buffer_rx , BUF_SIZE )) {
145
150
to_display_format (buffer_tx , BUF_SIZE , buffer_print_tx );
@@ -187,16 +192,9 @@ static int spi_complete_loop(struct spi_dt_spec *spec)
187
192
.count = ARRAY_SIZE (rx_bufs )
188
193
};
189
194
190
- int ret ;
191
-
192
195
LOG_INF ("Start complete loop" );
193
196
194
- ret = spi_transceive_dt (spec , & tx , & rx );
195
- if (ret ) {
196
- LOG_ERR ("Code %d" , ret );
197
- zassert_false (ret , "SPI transceive failed" );
198
- return ret ;
199
- }
197
+ spi_loopback_transceive (spec , & tx , & rx );
200
198
201
199
if (memcmp (buffer_tx , buffer_rx , BUF_SIZE )) {
202
200
to_display_format (buffer_tx , BUF_SIZE , buffer_print_tx );
@@ -242,17 +240,9 @@ static int spi_null_tx_buf(struct spi_dt_spec *spec)
242
240
.count = ARRAY_SIZE (rx_bufs )
243
241
};
244
242
245
- int ret ;
246
-
247
243
LOG_INF ("Start null tx" );
248
244
249
- ret = spi_transceive_dt (spec , & tx , & rx );
250
- if (ret ) {
251
- LOG_ERR ("Code %d" , ret );
252
- zassert_false (ret , "SPI transceive failed" );
253
- return ret ;
254
- }
255
-
245
+ spi_loopback_transceive (spec , & tx , & rx );
256
246
257
247
if (memcmp (buffer_rx , EXPECTED_NOP_RETURN_BUF , BUF_SIZE )) {
258
248
to_display_format (buffer_rx , BUF_SIZE , buffer_print_rx );
@@ -289,18 +279,10 @@ static int spi_rx_half_start(struct spi_dt_spec *spec)
289
279
.buffers = rx_bufs ,
290
280
.count = ARRAY_SIZE (rx_bufs )
291
281
};
292
- int ret ;
293
-
294
- LOG_INF ("Start half start" );
295
282
296
283
(void )memset (buffer_rx , 0 , BUF_SIZE );
297
284
298
- ret = spi_transceive_dt (spec , & tx , & rx );
299
- if (ret ) {
300
- LOG_ERR ("Code %d" , ret );
301
- zassert_false (ret , "SPI transceive failed" );
302
- return -1 ;
303
- }
285
+ spi_loopback_transceive (spec , & tx , & rx );
304
286
305
287
if (memcmp (buffer_tx , buffer_rx , 8 )) {
306
288
to_display_format (buffer_tx , 8 , buffer_print_tx );
@@ -342,7 +324,6 @@ static int spi_rx_half_end(struct spi_dt_spec *spec)
342
324
.buffers = rx_bufs ,
343
325
.count = ARRAY_SIZE (rx_bufs )
344
326
};
345
- int ret ;
346
327
347
328
if (IS_ENABLED (CONFIG_SPI_STM32_DMA )) {
348
329
LOG_INF ("Skip half end" );
@@ -353,12 +334,7 @@ static int spi_rx_half_end(struct spi_dt_spec *spec)
353
334
354
335
(void )memset (buffer_rx , 0 , BUF_SIZE );
355
336
356
- ret = spi_transceive_dt (spec , & tx , & rx );
357
- if (ret ) {
358
- LOG_ERR ("Code %d" , ret );
359
- zassert_false (ret , "SPI transceive failed" );
360
- return -1 ;
361
- }
337
+ spi_loopback_transceive (spec , & tx , & rx );
362
338
363
339
if (memcmp (buffer_tx + 8 , buffer_rx , 8 )) {
364
340
to_display_format (buffer_tx + 8 , 8 , buffer_print_tx );
@@ -408,7 +384,6 @@ static int spi_rx_every_4(struct spi_dt_spec *spec)
408
384
.buffers = rx_bufs ,
409
385
.count = ARRAY_SIZE (rx_bufs )
410
386
};
411
- int ret ;
412
387
413
388
if (IS_ENABLED (CONFIG_SPI_STM32_DMA )) {
414
389
LOG_INF ("Skip every 4" );
@@ -424,12 +399,7 @@ static int spi_rx_every_4(struct spi_dt_spec *spec)
424
399
425
400
(void )memset (buffer_rx , 0 , BUF_SIZE );
426
401
427
- ret = spi_transceive_dt (spec , & tx , & rx );
428
- if (ret ) {
429
- LOG_ERR ("Code %d" , ret );
430
- zassert_false (ret , "SPI transceive failed" );
431
- return -1 ;
432
- }
402
+ spi_loopback_transceive (spec , & tx , & rx );
433
403
434
404
if (memcmp (buffer_tx + 4 , buffer_rx , 4 )) {
435
405
to_display_format (buffer_tx + 4 , 4 , buffer_print_tx );
@@ -479,7 +449,6 @@ static int spi_rx_bigger_than_tx(struct spi_dt_spec *spec)
479
449
.buffers = rx_bufs ,
480
450
.count = ARRAY_SIZE (rx_bufs )
481
451
};
482
- int ret ;
483
452
484
453
if (IS_ENABLED (CONFIG_SPI_STM32_DMA )) {
485
454
LOG_INF ("Skip rx bigger than tx" );
@@ -495,12 +464,7 @@ static int spi_rx_bigger_than_tx(struct spi_dt_spec *spec)
495
464
496
465
(void )memset (buffer_rx , 0xff , BUF_SIZE );
497
466
498
- ret = spi_transceive_dt (spec , & tx , & rx );
499
- if (ret ) {
500
- LOG_ERR ("Code %d" , ret );
501
- zassert_false (ret , "SPI transceive failed" );
502
- return -1 ;
503
- }
467
+ spi_loopback_transceive (spec , & tx , & rx );
504
468
505
469
if (memcmp (buffer_tx , buffer_rx , tx_buf_size )) {
506
470
to_display_format (buffer_tx , tx_buf_size , buffer_print_tx );
@@ -553,16 +517,9 @@ static int spi_complete_large_transfers(struct spi_dt_spec *spec)
553
517
rx_bufs .buf = large_buffer_rx ;
554
518
rx_bufs .len = BUF3_SIZE ;
555
519
556
- int ret ;
557
-
558
520
LOG_INF ("Start complete large transfers" );
559
521
560
- ret = spi_transceive_dt (spec , & tx , & rx );
561
- if (ret ) {
562
- LOG_ERR ("Code %d" , ret );
563
- zassert_false (ret , "SPI transceive failed" );
564
- return ret ;
565
- }
522
+ spi_loopback_transceive (spec , & tx , & rx );
566
523
567
524
if (memcmp (large_buffer_tx , large_buffer_rx , BUF3_SIZE )) {
568
525
zassert_false (1 , "Large Buffer contents are different" );
0 commit comments