Skip to content

Commit 499ef10

Browse files
JarmouniAnordicjm
authored andcommitted
[nrf fromtree] tests: drivers: spi_loopback: fix buffers alignment size
Size given to __aligned() is in bytes. Align following DCACHE line size, or default to 32-byte alignment Signed-off-by: Abderrahmane JARMOUNI <[email protected]> (cherry picked from commit da62b1c)
1 parent b0ff34a commit 499ef10

File tree

1 file changed

+24
-15
lines changed
  • tests/drivers/spi/spi_loopback/src

1 file changed

+24
-15
lines changed

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,40 +66,49 @@ const struct gpio_dt_spec mosi_pin = GPIO_DT_SPEC_GET_OR(DT_PATH(zephyr_user), m
6666
********************
6767
*/
6868

69-
#if CONFIG_NOCACHE_MEMORY
69+
#ifdef CONFIG_NOCACHE_MEMORY
7070
#define __NOCACHE __attribute__((__section__(".nocache")))
7171
#elif defined(CONFIG_DT_DEFINED_NOCACHE)
7272
#define __NOCACHE __attribute__((__section__(CONFIG_DT_DEFINED_NOCACHE_NAME)))
7373
#else /* CONFIG_NOCACHE_MEMORY */
7474
#define __NOCACHE
75+
#if CONFIG_DCACHE_LINE_SIZE != 0
76+
#define __BUF_ALIGN __aligned(CONFIG_DCACHE_LINE_SIZE)
77+
#else
78+
#define __BUF_ALIGN __aligned(DT_PROP_OR(DT_PATH(cpus, cpu_0), d_cache_line_size, 32))
79+
#endif
7580
#endif /* CONFIG_NOCACHE_MEMORY */
7681

82+
#ifndef __BUF_ALIGN
83+
#define __BUF_ALIGN __aligned(32)
84+
#endif
85+
7786
#define BUF_SIZE 18
7887
static const char tx_data[BUF_SIZE] = "0123456789abcdef-\0";
79-
static __aligned(32) char buffer_tx[BUF_SIZE] __NOCACHE;
80-
static __aligned(32) char buffer_rx[BUF_SIZE] __NOCACHE;
88+
static __BUF_ALIGN char buffer_tx[BUF_SIZE] __NOCACHE;
89+
static __BUF_ALIGN char buffer_rx[BUF_SIZE] __NOCACHE;
8190

8291
#define BUF2_SIZE 36
8392
static const char tx2_data[BUF2_SIZE] = "Thequickbrownfoxjumpsoverthelazydog\0";
84-
static __aligned(32) char buffer2_tx[BUF2_SIZE] __NOCACHE;
85-
static __aligned(32) char buffer2_rx[BUF2_SIZE] __NOCACHE;
93+
static __BUF_ALIGN char buffer2_tx[BUF2_SIZE] __NOCACHE;
94+
static __BUF_ALIGN char buffer2_rx[BUF2_SIZE] __NOCACHE;
8695

8796
#define BUF3_SIZE CONFIG_SPI_LARGE_BUFFER_SIZE
8897
static const char large_tx_data[BUF3_SIZE] = "Thequickbrownfoxjumpsoverthelazydog\0";
89-
static __aligned(32) char large_buffer_tx[BUF3_SIZE] __NOCACHE;
90-
static __aligned(32) char large_buffer_rx[BUF3_SIZE] __NOCACHE;
98+
static __BUF_ALIGN char large_buffer_tx[BUF3_SIZE] __NOCACHE;
99+
static __BUF_ALIGN char large_buffer_rx[BUF3_SIZE] __NOCACHE;
91100

92101
#define BUFWIDE_SIZE 12
93102
static const uint16_t tx_data_16[] = {0x1234, 0x5678, 0x9ABC, 0xDEF0,
94103
0xFF00, 0x00FF, 0xAAAA, 0x5555,
95104
0xF0F0, 0x0F0F, 0xA5A5, 0x5A5A};
96-
static __aligned(32) uint16_t buffer_tx_16[BUFWIDE_SIZE] __NOCACHE;
97-
static __aligned(32) uint16_t buffer_rx_16[BUFWIDE_SIZE] __NOCACHE;
105+
static __BUF_ALIGN uint16_t buffer_tx_16[BUFWIDE_SIZE] __NOCACHE;
106+
static __BUF_ALIGN uint16_t buffer_rx_16[BUFWIDE_SIZE] __NOCACHE;
98107
static const uint32_t tx_data_32[] = {0x12345678, 0x56781234, 0x9ABCDEF0, 0xDEF09ABC,
99108
0xFFFF0000, 0x0000FFFF, 0x00FF00FF, 0xFF00FF00,
100109
0xAAAA5555, 0x5555AAAA, 0xAA55AA55, 0x55AA55AA};
101-
static __aligned(32) uint32_t buffer_tx_32[BUFWIDE_SIZE] __NOCACHE;
102-
static __aligned(32) uint32_t buffer_rx_32[BUFWIDE_SIZE] __NOCACHE;
110+
static __BUF_ALIGN uint32_t buffer_tx_32[BUFWIDE_SIZE] __NOCACHE;
111+
static __BUF_ALIGN uint32_t buffer_rx_32[BUFWIDE_SIZE] __NOCACHE;
103112

104113
/*
105114
********************
@@ -667,7 +676,7 @@ ZTEST(spi_loopback, test_spi_word_size_9)
667676
{
668677
struct spi_dt_spec *spec = loopback_specs[spec_idx];
669678

670-
static __aligned(32) uint16_t tx_data_9[BUFWIDE_SIZE];
679+
static __BUF_ALIGN uint16_t tx_data_9[BUFWIDE_SIZE];
671680

672681
for (int i = 0; i < BUFWIDE_SIZE; i++) {
673682
tx_data_9[i] = tx_data_16[i] & 0x1FF;
@@ -691,7 +700,7 @@ ZTEST(spi_loopback, test_spi_word_size_24)
691700
{
692701
struct spi_dt_spec *spec = loopback_specs[spec_idx];
693702

694-
static __aligned(32) uint32_t tx_data_24[BUFWIDE_SIZE];
703+
static __BUF_ALIGN uint32_t tx_data_24[BUFWIDE_SIZE];
695704

696705
for (int i = 0; i < BUFWIDE_SIZE; i++) {
697706
tx_data_24[i] = tx_data_32[i] & 0xFFFFFF;
@@ -717,8 +726,8 @@ static struct k_thread thread[3];
717726
static K_SEM_DEFINE(thread_sem, 0, 3);
718727
static K_SEM_DEFINE(sync_sem, 0, 1);
719728

720-
static uint8_t __aligned(32) tx_buffer[3][32] __NOCACHE;
721-
static uint8_t __aligned(32) rx_buffer[3][32] __NOCACHE;
729+
static uint8_t __BUF_ALIGN tx_buffer[3][32] __NOCACHE;
730+
static uint8_t __BUF_ALIGN rx_buffer[3][32] __NOCACHE;
722731

723732
atomic_t thread_test_fails;
724733

0 commit comments

Comments
 (0)