Skip to content

Commit

Permalink
[nrf fromlist] tests: boards: nrf70: Add ztests for bus library
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bama-nordic committed Dec 4, 2024
1 parent 167e968 commit 82eddf1
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/boards/nrf/nrf70/bustest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: BSD-3-Clause
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(nrf70_bustest)

target_sources(app PRIVATE
src/main.c
)

target_link_libraries(app PUBLIC nrf70-buslib)
15 changes: 15 additions & 0 deletions tests/boards/nrf/nrf70/bustest/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2024 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0
#
source "Kconfig.zephyr"

menu "NRF70 Buslib test sample"

config NRF70BUS_MEMTEST_LENGTH
int "Memory test length"
default 1024
help
This option sets the default length for the memory test.
endmenu
27 changes: 27 additions & 0 deletions tests/boards/nrf/nrf70/bustest/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CONFIG_NRF70_BUSLIB=y
CONFIG_ZTEST=y

CONFIG_HEAP_MEM_POOL_SIZE=50000
CONFIG_HEAP_MEM_POOL_IGNORE_MIN=y

# System settings
CONFIG_ASSERT=y

CONFIG_INIT_STACKS=y

# Memories
CONFIG_MAIN_STACK_SIZE=5200

# Debugging
CONFIG_STACK_SENTINEL=y
CONFIG_DEBUG_COREDUMP=y
CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y
CONFIG_SHELL_CMDS_RESIZE=n
CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL_DBG=y

# Logging
CONFIG_LOG=y
CONFIG_PRINTK=y
# If below config is enabled, printk logs are
# buffered. For unbuffered messages, disable this.
CONFIG_LOG_PRINTK=n
198 changes: 198 additions & 0 deletions tests/boards/nrf/nrf70/bustest/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @brief File containing ztests for nrf70 buslib library
*/

#include <zephyr/shell/shell.h>
#include <zephyr/logging/log.h>
#include <zephyr/ztest.h>
#include <zephyr/drivers/wifi/nrf_wifi/bus/rpu_hw_if.h>
#include <zephyr/drivers/wifi/nrf_wifi/bus/qspi_if.h>

LOG_MODULE_REGISTER(nrf70_bustest, CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL);

#define DATARAM_ADDR 0x0C0000
static struct qspi_dev *dev;

static int wifi_on(void *state)
{
int ret;

ARG_UNUSED(state);

dev = qspi_dev();

ret = rpu_init();
if (ret) {
LOG_ERR("%s: RPU init failed with error %d", __func__, ret);
return -1;
}

ret = dev->init(qspi_defconfig());
if (ret) {
LOG_ERR("%s: QSPI device init failed", __func__);
return -1;
}

ret = rpu_enable();
if (ret) {
LOG_ERR("%s: RPU enable failed with error %d", __func__, ret);
return -1;
}
k_sleep(K_MSEC(10));
LOG_INF("Wi-Fi ON done");
return 0;
}

static void wifi_off(void *state)
{
ARG_UNUSED(state);

int ret;

ret = rpu_disable();
if (ret) {
LOG_ERR("%s: RPU disable failed with error %d", __func__, ret);
}

ret = dev->deinit();
if (ret) {
LOG_ERR("%s: QSPI device de-init failed", __func__);
}
k_sleep(K_MSEC(10));
LOG_INF("Wi-Fi OFF done");
}


static int memtest(uint32_t addr, char *memblock_name)
{
const uint32_t pattern = 0x12345678;
uint32_t offset = 1;
uint32_t *buff, *rxbuff;
int i;

int err_count;
int32_t rem_words = CONFIG_NRF70BUS_MEMTEST_LENGTH;
uint32_t test_chunk, chunk_no = 0;
int ret = -1;

buff = k_malloc(CONFIG_NRF70BUS_MEMTEST_LENGTH * 4);
if (buff == NULL) {
LOG_ERR("Failed to allocate memory for buff");
return -1;
}

rxbuff = k_malloc(CONFIG_NRF70BUS_MEMTEST_LENGTH * 4);
if (rxbuff == NULL) {
LOG_ERR("Failed to allocate memory for rxbuff");
k_free(buff);
return -1;
}

while (rem_words > 0) {
test_chunk = (rem_words < CONFIG_NRF70BUS_MEMTEST_LENGTH) ?
rem_words : CONFIG_NRF70BUS_MEMTEST_LENGTH;

for (i = 0; i < test_chunk; i++) {
buff[i] = pattern +
(i + chunk_no * CONFIG_NRF70BUS_MEMTEST_LENGTH) * offset;
}

addr = addr + chunk_no * CONFIG_NRF70BUS_MEMTEST_LENGTH;

if (rpu_write(addr, buff, test_chunk * 4) ||
rpu_read(addr, rxbuff, test_chunk * 4)) {
goto err;
}

err_count = 0;
for (i = 0; i < test_chunk; i++) {
if (buff[i] != rxbuff[i]) {
err_count++;
LOG_ERR("%s: failed (%d), Expected 0x%x, Read 0x%x",
__func__, i, buff[i], rxbuff[i]);
if (err_count > 4)
goto err;
}
}
if (err_count) {
goto err;
}
rem_words -= CONFIG_NRF70BUS_MEMTEST_LENGTH;
chunk_no++;
}
ret = 0;
err:
k_free(rxbuff);
k_free(buff);
return ret;
}

static int test_sysbus(void)
{
int val, i;
/* List of some SYS bus addresses and default values to test bus read
* integrity
*/
const uint32_t addr[] = {0x714, 0x71c, 0x720,
0x728, 0x734, 0x738};
const uint32_t val_arr[] = {
0x000003f3, 0x0110f13f, 0x000003f3,
0x0003073f, 0x0003073f, 0x03013f8f};

for (i = 0; i < ARRAY_SIZE(addr); i++) {
rpu_read(addr[i], &val, 4);
if (val != val_arr[i]) {
LOG_ERR("%s: SYSBUS R/W failed (%d) : read = 0x%x, expected = 0x%x",
__func__, i, val, val_arr[i]);
return -1;
}
}
return 0;
}

static int test_peripbus(void)
{
uint32_t val;
int i;
/* Some Perip bus addresses that we can write/read to validate bus access*/
const uint32_t addr[] = {0x62820, 0x62830, 0x62840, 0x62850, 0x62860, 0x62870};

for (i = 0; i < ARRAY_SIZE(addr); i++) {
val = 0xA5A5A5A5; /* Test pattern */
rpu_write(addr[i], &val, 4);
val = 0;
rpu_read(addr[i], &val, 4);
/* Perip bus is 24-bit and hence LS 8 bits read are invalid, so discard them
* in the check
*/
if (val >> 8 != 0xA5A5A5) {
LOG_ERR("%s: PERIP BUS R/W failed (%d): read = 0x%x",
__func__, i, val >> 8);
return -1;
}
}
return 0;
}

ZTEST_SUITE(bustest_suite, NULL, (void *)wifi_on, NULL, NULL, wifi_off);

ZTEST(bustest_suite, test_sysbus)
{
zassert_equal(0, test_sysbus(), "SYSBUS read validation failed!!!");
}

ZTEST(bustest_suite, test_peripbus)
{
zassert_equal(0, test_peripbus(), "PERIP BUS read/write validation failed!!!");
}

ZTEST(bustest_suite, test_dataram)
{
zassert_equal(0, memtest(DATARAM_ADDR, "DATA RAM"), "DATA RAM memtest failed!!!");
}
20 changes: 20 additions & 0 deletions tests/boards/nrf/nrf70/bustest/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
tests:
nrf_wifi.bustest.nrf7002:
sysbuild: true
build_only: true
integration_platforms:
- nrf7002dk/nrf5340/cpuapp
platform_allow: nrf7002dk/nrf5340/cpuapp

nrf_wifi.bustest.nrf7002ek:
sysbuild: true
build_only: true
extra_args: SHIELD=nrf7002ek
integration_platforms:
- nrf5340dk/nrf5340/cpuapp
- nrf52840dk/nrf52840
- nucleo_h723zg
platform_allow:
- nrf5340dk/nrf5340/cpuapp
- nrf52840dk/nrf52840
- nucleo_h723zg

0 comments on commit 82eddf1

Please sign in to comment.