Skip to content

Commit da22f1a

Browse files
hakehuangnordic-krch
authored andcommitted
[nrf fromtree] tests: uart_async_api: update test for dma usage
1. ensure the two dma buffers all aligned with 32 bits 2. clean the rx_data_idx at test begin Signed-off-by: Krzysztof Chruściński <[email protected]> Signed-off-by: Hake Huang <[email protected]> (cherry picked from commit 193bfab)
1 parent 9548301 commit da22f1a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

tests/drivers/uart/uart_async_api/src/test_uart_async.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,24 @@ ZTEST_USER(uart_async_multi_rx, test_multiple_rx_enable)
324324
}
325325

326326
#if NOCACHE_MEM
327-
static __aligned(32) uint8_t chained_read_buf[2][8] __used __NOCACHE;
327+
/* To ensure 32-bit alignment of the buffer array,
328+
* the two arrays are defined instead using an array of arrays
329+
*/
330+
static __aligned(32) uint8_t chained_read_buf_0[8] __used __NOCACHE;
331+
static __aligned(32) uint8_t chained_read_buf_1[8] __used __NOCACHE;
328332
static __aligned(32) uint8_t chained_cpy_buf[10] __used __NOCACHE;
329333
#else
330-
ZTEST_BMEM uint8_t chained_read_buf[2][8];
334+
ZTEST_BMEM uint8_t chained_read_buf_0[8];
335+
ZTEST_BMEM uint8_t chained_read_buf_1[8];
331336
ZTEST_BMEM uint8_t chained_cpy_buf[10];
332337
#endif /* NOCACHE_MEM */
333338
ZTEST_BMEM volatile uint8_t rx_data_idx;
334339
ZTEST_BMEM uint8_t rx_buf_idx;
335340

336341
ZTEST_BMEM uint8_t *read_ptr;
337342

343+
static uint8_t *chained_read_buf[2] = {chained_read_buf_0, chained_read_buf_1};
344+
338345
static void test_chained_read_callback(const struct device *dev,
339346
struct uart_event *evt, void *user_data)
340347
{
@@ -352,9 +359,8 @@ static void test_chained_read_callback(const struct device *dev,
352359
rx_data_idx += evt->data.rx.len;
353360
break;
354361
case UART_RX_BUF_REQUEST:
355-
err = uart_rx_buf_rsp(dev,
356-
chained_read_buf[rx_buf_idx],
357-
sizeof(chained_read_buf[0]));
362+
err = uart_rx_buf_rsp(dev, chained_read_buf[rx_buf_idx],
363+
sizeof(chained_read_buf_0));
358364
zassert_equal(err, 0);
359365
rx_buf_idx = !rx_buf_idx ? 1 : 0;
360366
break;
@@ -387,11 +393,10 @@ ZTEST_USER(uart_async_chain_read, test_chained_read)
387393
uint32_t rx_timeout_ms = 50;
388394
int err;
389395

390-
err = uart_rx_enable(uart_dev,
391-
chained_read_buf[rx_buf_idx++],
392-
sizeof(chained_read_buf[0]),
396+
err = uart_rx_enable(uart_dev, chained_read_buf[rx_buf_idx++], sizeof(chained_read_buf_0),
393397
rx_timeout_ms * USEC_PER_MSEC);
394398
zassert_equal(err, 0);
399+
rx_data_idx = 0;
395400

396401
for (int i = 0; i < iter; i++) {
397402
zassert_not_equal(k_sem_take(&rx_disabled, K_MSEC(10)),
@@ -406,7 +411,7 @@ ZTEST_USER(uart_async_chain_read, test_chained_read)
406411
"Unexpected amount of data received %d exp:%d",
407412
rx_data_idx, sizeof(tx_buf));
408413
zassert_equal(memcmp(tx_buf, chained_cpy_buf, sizeof(tx_buf)), 0,
409-
"Buffers not equal");
414+
"Buffers not equal exp %s, real %s", tx_buf, chained_cpy_buf);
410415
rx_data_idx = 0;
411416
}
412417
uart_rx_disable(uart_dev);

0 commit comments

Comments
 (0)