Skip to content

Commit d963fc0

Browse files
ananglkartben
authored andcommitted
tests: boards: nrf: Add test for external flash XIP handling
Add nRF specific test to check if it possible for multiple users to enable XIP independently and also if XIP can be successfully re-enabled (see fb1d078). Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
1 parent 2d9ede3 commit d963fc0

File tree

8 files changed

+212
-0
lines changed

8 files changed

+212
-0
lines changed

tests/boards/nrf/xip/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(xip)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
10+
11+
zephyr_code_relocate(FILES src/extflash.c LOCATION EXTFLASH_TEXT NOCOPY)
12+
zephyr_code_relocate(FILES src/extflash.c LOCATION EXTFLASH_RODATA NOCOPY)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dut: &mx25r64 {
2+
status = "okay";
3+
};

tests/boards/nrf/xip/extflash.ld

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/linker/sections.h>
8+
#include <zephyr/devicetree.h>
9+
10+
#include <zephyr/linker/linker-defs.h>
11+
#include <zephyr/linker/linker-tool.h>
12+
13+
#define EXTFLASH_NODE DT_NODELABEL(dut)
14+
#define EXTFLASH_SIZE DT_PROP_OR(EXTFLASH_NODE, size_in_bytes, \
15+
DT_PROP(EXTFLASH_NODE, size) / 8)
16+
17+
#if defined(CONFIG_NORDIC_QSPI_NOR) && defined(CONFIG_SOC_NRF5340_CPUAPP)
18+
19+
#define EXTFLASH_ADDR 0x10000000
20+
21+
#elif defined(CONFIG_FLASH_MSPI_NOR) && defined(CONFIG_SOC_NRF54H20_CPUAPP)
22+
23+
#define EXTFLASH_ADDR 0x60000000
24+
25+
#else
26+
27+
#error Unsupported target
28+
29+
#endif
30+
31+
MEMORY
32+
{
33+
EXTFLASH (rx) : ORIGIN = EXTFLASH_ADDR, LENGTH = EXTFLASH_SIZE
34+
}
35+
36+
#include <zephyr/arch/arm/cortex_m/scripts/linker.ld>

tests/boards/nrf/xip/prj.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_FLASH=y
3+
CONFIG_CODE_DATA_RELOCATION=y
4+
CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y
5+
CONFIG_CUSTOM_LINKER_SCRIPT="extflash.ld"

tests/boards/nrf/xip/src/extflash.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/ztest.h>
8+
9+
#include "extflash.h"
10+
11+
const char extflash_string[] = EXPECTED_EXTFLASH_STRING;
12+
13+
void extflash_function1(void)
14+
{
15+
TC_PRINT("Executing %s at %p\n", __func__, &extflash_function1);
16+
}
17+
18+
void extflash_function2(void)
19+
{
20+
TC_PRINT("Executing %s at %p\n", __func__, &extflash_function2);
21+
}

tests/boards/nrf/xip/src/extflash.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define EXPECTED_EXTFLASH_STRING "Nordic Semiconductor"
8+
extern const char extflash_string[];
9+
10+
void extflash_function1(void);
11+
void extflash_function2(void);

tests/boards/nrf/xip/src/main.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/ztest.h>
9+
#if defined(CONFIG_NORDIC_QSPI_NOR)
10+
#include <zephyr/drivers/flash/nrf_qspi_nor.h>
11+
#endif
12+
13+
#include "extflash.h"
14+
15+
#define EXTFLASH_NODE DT_NODELABEL(dut)
16+
17+
static const struct device *dev_flash = DEVICE_DT_GET(EXTFLASH_NODE);
18+
19+
static void check_extflash_string(void)
20+
{
21+
TC_PRINT("Accessing extflash_string at %p: %s\n",
22+
extflash_string, extflash_string);
23+
zassert_equal(0, strcmp(extflash_string, EXPECTED_EXTFLASH_STRING));
24+
}
25+
26+
static void xip_enable(bool enable)
27+
{
28+
#if defined(CONFIG_NORDIC_QSPI_NOR)
29+
nrf_qspi_nor_xip_enable(dev_flash, enable);
30+
#endif
31+
}
32+
33+
ZTEST(xip, test_xip_enable_disable)
34+
{
35+
xip_enable(true);
36+
extflash_function1();
37+
check_extflash_string();
38+
xip_enable(false);
39+
40+
/* This is to ensure that the next XIP access will result in a new
41+
* transfer from the flash chip, as the required data will not be
42+
* available in cache.
43+
*/
44+
k_sleep(K_MSEC(10));
45+
46+
xip_enable(true);
47+
extflash_function2();
48+
check_extflash_string();
49+
xip_enable(false);
50+
}
51+
52+
ZTEST(xip, test_xip_enabled_at_boot)
53+
{
54+
if (!IS_ENABLED(CONFIG_NORDIC_QSPI_NOR_XIP)) {
55+
ztest_test_skip();
56+
}
57+
58+
extflash_function1();
59+
check_extflash_string();
60+
61+
xip_enable(true);
62+
extflash_function2();
63+
xip_enable(false);
64+
65+
k_sleep(K_MSEC(10));
66+
67+
/* XIP enabled at boot should stay active after it is temporarily
68+
* enabled at runtime.
69+
*/
70+
extflash_function1();
71+
check_extflash_string();
72+
}
73+
74+
static void third_xip_user(void)
75+
{
76+
xip_enable(true);
77+
check_extflash_string();
78+
xip_enable(false);
79+
}
80+
81+
static void second_xip_user(void)
82+
{
83+
xip_enable(true);
84+
85+
extflash_function2();
86+
87+
third_xip_user();
88+
89+
xip_enable(false);
90+
}
91+
92+
ZTEST(xip, test_xip_multiple_users)
93+
{
94+
xip_enable(true);
95+
96+
extflash_function1();
97+
98+
second_xip_user();
99+
100+
extflash_function1();
101+
check_extflash_string();
102+
103+
xip_enable(false);
104+
}
105+
106+
ZTEST_SUITE(xip, NULL, NULL, NULL, NULL, NULL);

tests/boards/nrf/xip/testcase.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
common:
2+
harness: ztest
3+
tags:
4+
- drivers
5+
- flash
6+
tests:
7+
boards.nrf.xip:
8+
platform_allow:
9+
- nrf5340dk/nrf5340/cpuapp
10+
integration_platforms:
11+
- nrf5340dk/nrf5340/cpuapp
12+
boards.nrf.xip.enabled_at_boot.qspi:
13+
extra_configs:
14+
- CONFIG_NORDIC_QSPI_NOR_XIP=y
15+
platform_allow:
16+
- nrf5340dk/nrf5340/cpuapp
17+
integration_platforms:
18+
- nrf5340dk/nrf5340/cpuapp

0 commit comments

Comments
 (0)