1
1
/*
2
- * Copyright (c) 2019 Nordic Semiconductor ASA
2
+ * Copyright (c) 2019 Nordic Semiconductor ASA
3
+ * Copyright (c) 2024 STMicroelectronics
3
4
*
4
5
* SPDX-License-Identifier: Apache-2.0
5
6
*/
6
7
7
8
#include "test_uart.h"
8
9
10
+ #if defined(CONFIG_DCACHE ) && defined(CONFIG_DT_DEFINED_NOCACHE )
11
+ #define __NOCACHE __attribute__ ((__section__(CONFIG_DT_DEFINED_NOCACHE_NAME)))
12
+ #define NOCACHE_MEM 1
13
+ #elif defined(CONFIG_DCACHE ) && defined(CONFIG_NOCACHE_MEMORY )
14
+ #define __NOCACHE __nocache
15
+ #define NOCACHE_MEM 1
16
+ #else
17
+ #define NOCACHE_MEM 0
18
+ #endif /* CONFIG_NOCACHE_MEMORY */
19
+
9
20
K_SEM_DEFINE (tx_done , 0 , 1 );
10
21
K_SEM_DEFINE (tx_aborted , 0 , 1 );
11
22
K_SEM_DEFINE (rx_rdy , 0 , 1 );
@@ -79,14 +90,18 @@ static void uart_async_test_init(void)
79
90
80
91
struct test_data {
81
92
volatile uint32_t tx_aborted_count ;
82
- uint8_t rx_first_buffer [10 ];
93
+ __aligned ( 32 ) uint8_t rx_first_buffer [10 ];
83
94
uint32_t recv_bytes_first_buffer ;
84
- uint8_t rx_second_buffer [5 ];
95
+ __aligned ( 32 ) uint8_t rx_second_buffer [5 ];
85
96
uint32_t recv_bytes_second_buffer ;
86
97
bool supply_second_buffer ;
87
98
};
88
99
100
+ #if NOCACHE_MEM
101
+ static struct test_data tdata __used __NOCACHE ;
102
+ #else
89
103
ZTEST_BMEM struct test_data tdata ;
104
+ #endif /* NOCACHE_MEM */
90
105
91
106
static void test_single_read_callback (const struct device * dev ,
92
107
struct uart_event * evt , void * user_data )
@@ -308,8 +323,13 @@ ZTEST_USER(uart_async_multi_rx, test_multiple_rx_enable)
308
323
tdata_check_recv_buffers (tx_buf , sizeof (tx_buf ));
309
324
}
310
325
326
+ #if NOCACHE_MEM
327
+ static __aligned (32 ) uint8_t chained_read_buf [2 ][8 ] __used __NOCACHE ;
328
+ static __aligned (32 ) uint8_t chained_cpy_buf [10 ] __used __NOCACHE ;
329
+ #else
311
330
ZTEST_BMEM uint8_t chained_read_buf [2 ][8 ];
312
331
ZTEST_BMEM uint8_t chained_cpy_buf [10 ];
332
+ #endif /* NOCACHE_MEM */
313
333
ZTEST_BMEM volatile uint8_t rx_data_idx ;
314
334
ZTEST_BMEM uint8_t rx_buf_idx ;
315
335
@@ -358,7 +378,11 @@ static void *chained_read_setup(void)
358
378
359
379
ZTEST_USER (uart_async_chain_read , test_chained_read )
360
380
{
381
+ #if NOCACHE_MEM
382
+ static __aligned (32 ) uint8_t tx_buf [10 ] __used __NOCACHE ;
383
+ #else
361
384
uint8_t tx_buf [10 ];
385
+ #endif /* NOCACHE_MEM */
362
386
int iter = 6 ;
363
387
uint32_t rx_timeout_ms = 50 ;
364
388
int err ;
@@ -390,7 +414,11 @@ ZTEST_USER(uart_async_chain_read, test_chained_read)
390
414
"RX_DISABLED timeout" );
391
415
}
392
416
417
+ #if NOCACHE_MEM
418
+ static __aligned (32 ) uint8_t double_buffer [2 ][12 ] __used __NOCACHE ;
419
+ #else
393
420
ZTEST_BMEM uint8_t double_buffer [2 ][12 ];
421
+ #endif /* NOCACHE_MEM */
394
422
ZTEST_DMEM uint8_t * next_buf = double_buffer [1 ];
395
423
396
424
static void test_double_buffer_callback (const struct device * dev ,
@@ -431,7 +459,11 @@ static void *double_buffer_setup(void)
431
459
432
460
ZTEST_USER (uart_async_double_buf , test_double_buffer )
433
461
{
462
+ #if NOCACHE_MEM
463
+ static __aligned (32 ) uint8_t tx_buf [4 ] __used __NOCACHE ;
464
+ #else
434
465
uint8_t tx_buf [4 ];
466
+ #endif /* NOCACHE_MEM */
435
467
436
468
zassert_equal (uart_rx_enable (uart_dev ,
437
469
double_buffer [0 ],
@@ -456,8 +488,13 @@ ZTEST_USER(uart_async_double_buf, test_double_buffer)
456
488
"RX_DISABLED timeout ");
457
489
}
458
490
491
+ #if NOCACHE_MEM
492
+ static __aligned (32 ) uint8_t test_read_abort_rx_buf [2 ][100 ] __used __NOCACHE ;
493
+ static __aligned (32 ) uint8_t test_read_abort_read_buf [100 ] __used __NOCACHE ;
494
+ #else
459
495
ZTEST_BMEM uint8_t test_read_abort_rx_buf [2 ][100 ];
460
496
ZTEST_BMEM uint8_t test_read_abort_read_buf [100 ];
497
+ #endif /* NOCACHE_MEM */
461
498
ZTEST_BMEM int test_read_abort_rx_cnt ;
462
499
463
500
static void test_read_abort_callback (const struct device * dev ,
@@ -526,8 +563,13 @@ static void *read_abort_setup(void)
526
563
527
564
ZTEST_USER (uart_async_read_abort , test_read_abort )
528
565
{
566
+ #if NOCACHE_MEM
567
+ static __aligned (32 ) uint8_t rx_buf [100 ] __used __NOCACHE ;
568
+ static __aligned (32 ) uint8_t tx_buf [100 ] __used __NOCACHE ;
569
+ #else
529
570
uint8_t rx_buf [100 ];
530
571
uint8_t tx_buf [100 ];
572
+ #endif /* NOCACHE_MEM */
531
573
532
574
memset (rx_buf , 0 , sizeof (rx_buf ));
533
575
memset (tx_buf , 1 , sizeof (tx_buf ));
@@ -568,7 +610,11 @@ ZTEST_USER(uart_async_read_abort, test_read_abort)
568
610
569
611
ZTEST_BMEM volatile size_t sent ;
570
612
ZTEST_BMEM volatile size_t received ;
613
+ #if NOCACHE_MEM
614
+ static __aligned (32 ) uint8_t test_rx_buf [2 ][100 ] __used __NOCACHE ;
615
+ #else
571
616
ZTEST_BMEM uint8_t test_rx_buf [2 ][100 ];
617
+ #endif /* NOCACHE_MEM */
572
618
573
619
static void test_write_abort_callback (const struct device * dev ,
574
620
struct uart_event * evt , void * user_data )
@@ -612,7 +658,11 @@ static void *write_abort_setup(void)
612
658
613
659
ZTEST_USER (uart_async_write_abort , test_write_abort )
614
660
{
661
+ #if NOCACHE_MEM
662
+ static __aligned (32 ) uint8_t tx_buf [100 ] __used __NOCACHE ;
663
+ #else
615
664
uint8_t tx_buf [100 ];
665
+ #endif /* NOCACHE_MEM */
616
666
617
667
memset (test_rx_buf , 0 , sizeof (test_rx_buf ));
618
668
memset (tx_buf , 1 , sizeof (tx_buf ));
@@ -681,8 +731,13 @@ static void *forever_timeout_setup(void)
681
731
682
732
ZTEST_USER (uart_async_timeout , test_forever_timeout )
683
733
{
734
+ #if NOCACHE_MEM
735
+ static __aligned (32 ) uint8_t rx_buf [100 ] __used __NOCACHE ;
736
+ static __aligned (32 ) uint8_t tx_buf [100 ] __used __NOCACHE ;
737
+ #else
684
738
uint8_t rx_buf [100 ];
685
739
uint8_t tx_buf [100 ];
740
+ #endif /* NOCACHE_MEM */
686
741
687
742
memset (rx_buf , 0 , sizeof (rx_buf ));
688
743
memset (tx_buf , 1 , sizeof (tx_buf ));
@@ -715,7 +770,11 @@ ZTEST_USER(uart_async_timeout, test_forever_timeout)
715
770
}
716
771
717
772
773
+ #if NOCACHE_MEM
774
+ const uint8_t chained_write_tx_bufs [2 ][10 ] = {"Message 1" , "Message 2" };
775
+ #else
718
776
ZTEST_DMEM uint8_t chained_write_tx_bufs [2 ][10 ] = {"Message 1" , "Message 2" };
777
+ #endif /* NOCACHE_MEM */
719
778
ZTEST_DMEM bool chained_write_next_buf = true;
720
779
ZTEST_BMEM volatile uint8_t tx_sent ;
721
780
@@ -761,7 +820,11 @@ static void *chained_write_setup(void)
761
820
762
821
ZTEST_USER (uart_async_chain_write , test_chained_write )
763
822
{
823
+ #if NOCACHE_MEM
824
+ static __aligned (32 ) uint8_t rx_buf [20 ] __used __NOCACHE ;
825
+ #else
764
826
uint8_t rx_buf [20 ];
827
+ #endif /* NOCACHE_MEM */
765
828
766
829
memset (rx_buf , 0 , sizeof (rx_buf ));
767
830
@@ -787,9 +850,15 @@ ZTEST_USER(uart_async_chain_write, test_chained_write)
787
850
"RX_DISABLED timeout" );
788
851
}
789
852
853
+ #if NOCACHE_MEM
854
+ static __aligned (32 ) uint8_t long_rx_buf [1024 ] __used __NOCACHE ;
855
+ static __aligned (32 ) uint8_t long_rx_buf2 [1024 ] __used __NOCACHE ;
856
+ static __aligned (32 ) uint8_t long_tx_buf [1000 ] __used __NOCACHE ;
857
+ #else
790
858
ZTEST_BMEM uint8_t long_rx_buf [1024 ];
791
859
ZTEST_BMEM uint8_t long_rx_buf2 [1024 ];
792
860
ZTEST_BMEM uint8_t long_tx_buf [1000 ];
861
+ #endif /* NOCACHE_MEM */
793
862
ZTEST_BMEM volatile uint8_t evt_num ;
794
863
ZTEST_BMEM size_t long_received [2 ];
795
864
0 commit comments