Skip to content

Commit 70969ee

Browse files
bama-nordicjukkar
authored andcommitted
[nrf fromlist] tests: boards: nrf70: Add ztests for bus library
Add ztests for nrf70 bus lib to help validate functional integrity of the QPSI/SPI interface to nRF70 device via appropriate reads/writes from host processor to relevant memory blocks of nrf70 device. Note that this will NOT serve as a memory test for nrf70 device, rather just a functional verification of the wiring between the host processor and the nrf70 device. Upstream PR #: 82372 Signed-off-by: Bansidhar P.M <[email protected]> (cherry picked from commit bf4df4a)
1 parent b062985 commit 70969ee

File tree

5 files changed

+276
-0
lines changed

5 files changed

+276
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(nrf70_bustest)
11+
12+
target_sources(app PRIVATE
13+
src/main.c
14+
)
15+
16+
target_link_libraries(app PUBLIC nrf70-buslib)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
source "Kconfig.zephyr"
7+
8+
menu "NRF70 Buslib test sample"
9+
10+
config NRF70BUS_MEMTEST_LENGTH
11+
int "Memory test length"
12+
default 1024
13+
help
14+
This option sets the default length for the memory test.
15+
endmenu
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CONFIG_NRF70_BUSLIB=y
2+
CONFIG_ZTEST=y
3+
4+
CONFIG_HEAP_MEM_POOL_SIZE=50000
5+
CONFIG_HEAP_MEM_POOL_IGNORE_MIN=y
6+
7+
# System settings
8+
CONFIG_ASSERT=y
9+
10+
CONFIG_INIT_STACKS=y
11+
12+
# Memories
13+
CONFIG_MAIN_STACK_SIZE=5200
14+
15+
# Debugging
16+
CONFIG_STACK_SENTINEL=y
17+
CONFIG_DEBUG_COREDUMP=y
18+
CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y
19+
CONFIG_SHELL_CMDS_RESIZE=n
20+
CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL_DBG=y
21+
22+
# Logging
23+
CONFIG_LOG=y
24+
CONFIG_PRINTK=y
25+
# If below config is enabled, printk logs are
26+
# buffered. For unbuffered messages, disable this.
27+
CONFIG_LOG_PRINTK=n
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @brief File containing ztests for nrf70 buslib library
9+
*/
10+
11+
#include <zephyr/shell/shell.h>
12+
#include <zephyr/logging/log.h>
13+
#include <zephyr/ztest.h>
14+
#include <zephyr/drivers/wifi/nrf_wifi/bus/rpu_hw_if.h>
15+
#include <zephyr/drivers/wifi/nrf_wifi/bus/qspi_if.h>
16+
17+
LOG_MODULE_REGISTER(nrf70_bustest, CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL);
18+
19+
#define DATARAM_ADDR 0x0C0000
20+
static struct qspi_dev *dev;
21+
22+
static int wifi_on(void *state)
23+
{
24+
int ret;
25+
26+
ARG_UNUSED(state);
27+
28+
dev = qspi_dev();
29+
30+
ret = rpu_init();
31+
if (ret) {
32+
LOG_ERR("%s: RPU init failed with error %d", __func__, ret);
33+
return -1;
34+
}
35+
36+
ret = dev->init(qspi_defconfig());
37+
if (ret) {
38+
LOG_ERR("%s: QSPI device init failed", __func__);
39+
return -1;
40+
}
41+
42+
ret = rpu_enable();
43+
if (ret) {
44+
LOG_ERR("%s: RPU enable failed with error %d", __func__, ret);
45+
return -1;
46+
}
47+
k_sleep(K_MSEC(10));
48+
LOG_INF("Wi-Fi ON done");
49+
return 0;
50+
}
51+
52+
static void wifi_off(void *state)
53+
{
54+
ARG_UNUSED(state);
55+
56+
int ret;
57+
58+
ret = rpu_disable();
59+
if (ret) {
60+
LOG_ERR("%s: RPU disable failed with error %d", __func__, ret);
61+
}
62+
63+
ret = dev->deinit();
64+
if (ret) {
65+
LOG_ERR("%s: QSPI device de-init failed", __func__);
66+
}
67+
k_sleep(K_MSEC(10));
68+
LOG_INF("Wi-Fi OFF done");
69+
}
70+
71+
72+
static int memtest(uint32_t addr, char *memblock_name)
73+
{
74+
const uint32_t pattern = 0x12345678;
75+
uint32_t offset = 1;
76+
uint32_t *buff, *rxbuff;
77+
int i;
78+
79+
int err_count;
80+
int32_t rem_words = CONFIG_NRF70BUS_MEMTEST_LENGTH;
81+
uint32_t test_chunk, chunk_no = 0;
82+
int ret = -1;
83+
84+
buff = k_malloc(CONFIG_NRF70BUS_MEMTEST_LENGTH * 4);
85+
if (buff == NULL) {
86+
LOG_ERR("Failed to allocate memory for buff");
87+
return -1;
88+
}
89+
90+
rxbuff = k_malloc(CONFIG_NRF70BUS_MEMTEST_LENGTH * 4);
91+
if (rxbuff == NULL) {
92+
LOG_ERR("Failed to allocate memory for rxbuff");
93+
k_free(buff);
94+
return -1;
95+
}
96+
97+
while (rem_words > 0) {
98+
test_chunk = (rem_words < CONFIG_NRF70BUS_MEMTEST_LENGTH) ?
99+
rem_words : CONFIG_NRF70BUS_MEMTEST_LENGTH;
100+
101+
for (i = 0; i < test_chunk; i++) {
102+
buff[i] = pattern +
103+
(i + chunk_no * CONFIG_NRF70BUS_MEMTEST_LENGTH) * offset;
104+
}
105+
106+
addr = addr + chunk_no * CONFIG_NRF70BUS_MEMTEST_LENGTH;
107+
108+
if (rpu_write(addr, buff, test_chunk * 4) ||
109+
rpu_read(addr, rxbuff, test_chunk * 4)) {
110+
goto err;
111+
}
112+
113+
err_count = 0;
114+
for (i = 0; i < test_chunk; i++) {
115+
if (buff[i] != rxbuff[i]) {
116+
err_count++;
117+
LOG_ERR("%s: failed (%d), Expected 0x%x, Read 0x%x",
118+
__func__, i, buff[i], rxbuff[i]);
119+
if (err_count > 4)
120+
goto err;
121+
}
122+
}
123+
if (err_count) {
124+
goto err;
125+
}
126+
rem_words -= CONFIG_NRF70BUS_MEMTEST_LENGTH;
127+
chunk_no++;
128+
}
129+
ret = 0;
130+
err:
131+
k_free(rxbuff);
132+
k_free(buff);
133+
return ret;
134+
}
135+
136+
static int test_sysbus(void)
137+
{
138+
int val, i;
139+
/* List of some SYS bus addresses and default values to test bus read
140+
* integrity
141+
*/
142+
const uint32_t addr[] = {0x714, 0x71c, 0x720,
143+
0x728, 0x734, 0x738};
144+
const uint32_t val_arr[] = {
145+
0x000003f3, 0x0110f13f, 0x000003f3,
146+
0x0003073f, 0x0003073f, 0x03013f8f};
147+
148+
for (i = 0; i < ARRAY_SIZE(addr); i++) {
149+
rpu_read(addr[i], &val, 4);
150+
if (val != val_arr[i]) {
151+
LOG_ERR("%s: SYSBUS R/W failed (%d) : read = 0x%x, expected = 0x%x",
152+
__func__, i, val, val_arr[i]);
153+
return -1;
154+
}
155+
}
156+
return 0;
157+
}
158+
159+
static int test_peripbus(void)
160+
{
161+
uint32_t val;
162+
int i;
163+
/* Some Perip bus addresses that we can write/read to validate bus access*/
164+
const uint32_t addr[] = {0x62820, 0x62830, 0x62840, 0x62850, 0x62860, 0x62870};
165+
166+
for (i = 0; i < ARRAY_SIZE(addr); i++) {
167+
val = 0xA5A5A5A5; /* Test pattern */
168+
rpu_write(addr[i], &val, 4);
169+
val = 0;
170+
rpu_read(addr[i], &val, 4);
171+
/* Perip bus is 24-bit and hence LS 8 bits read are invalid, so discard them
172+
* in the check
173+
*/
174+
if (val >> 8 != 0xA5A5A5) {
175+
LOG_ERR("%s: PERIP BUS R/W failed (%d): read = 0x%x",
176+
__func__, i, val >> 8);
177+
return -1;
178+
}
179+
}
180+
return 0;
181+
}
182+
183+
ZTEST_SUITE(bustest_suite, NULL, (void *)wifi_on, NULL, NULL, wifi_off);
184+
185+
ZTEST(bustest_suite, test_sysbus)
186+
{
187+
zassert_equal(0, test_sysbus(), "SYSBUS read validation failed!!!");
188+
}
189+
190+
ZTEST(bustest_suite, test_peripbus)
191+
{
192+
zassert_equal(0, test_peripbus(), "PERIP BUS read/write validation failed!!!");
193+
}
194+
195+
ZTEST(bustest_suite, test_dataram)
196+
{
197+
zassert_equal(0, memtest(DATARAM_ADDR, "DATA RAM"), "DATA RAM memtest failed!!!");
198+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tests:
2+
nrf_wifi.bustest.nrf7002:
3+
sysbuild: true
4+
build_only: true
5+
integration_platforms:
6+
- nrf7002dk/nrf5340/cpuapp
7+
platform_allow: nrf7002dk/nrf5340/cpuapp
8+
9+
nrf_wifi.bustest.nrf7002ek:
10+
sysbuild: true
11+
build_only: true
12+
extra_args: SHIELD=nrf7002ek
13+
integration_platforms:
14+
- nrf5340dk/nrf5340/cpuapp
15+
- nrf52840dk/nrf52840
16+
- nucleo_h723zg
17+
platform_allow:
18+
- nrf5340dk/nrf5340/cpuapp
19+
- nrf52840dk/nrf52840
20+
- nucleo_h723zg

0 commit comments

Comments
 (0)