Skip to content

Commit 80f282f

Browse files
committed
[nrf fromlist] tests: boards: nrf: add rram_throttling test
Verifies that the throttling is working for boards that enable CONFIG_SOC_FLASH_NRF_THROTTLING Upstream PR #: 97565 Signed-off-by: Riadh Ghaddab <[email protected]> (cherry picked from commit c7a030f96113480ca6def26c94bf999a5dcd4800)
1 parent 53fe382 commit 80f282f

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(rram_throttling)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RRAM Throttling Testing
2+
#######################
3+
4+
Testing the throttling mechanism and verify that the write delay
5+
corresponds to the delay defined in CONFIG_NRF_RRAM_THROTTLING_DELAY.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_FLASH=y
5+
CONFIG_ZTEST=y
6+
CONFIG_SOC_FLASH_NRF_THROTTLING=y
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
#include <zephyr/drivers/flash.h>
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/storage/flash_map.h>
12+
13+
#define TEST_AREA storage_partition
14+
15+
/* TEST_AREA is only defined for configurations that rely on
16+
* fixed-partition nodes.
17+
*/
18+
#if defined(TEST_AREA)
19+
#define TEST_AREA_OFFSET FIXED_PARTITION_OFFSET(TEST_AREA)
20+
#define TEST_AREA_SIZE FIXED_PARTITION_SIZE(TEST_AREA)
21+
#define TEST_AREA_DEVICE FIXED_PARTITION_DEVICE(TEST_AREA)
22+
#else
23+
#error "Unsupported configuraiton"
24+
#endif
25+
26+
#define BUF_SIZE 512
27+
#define TEST_ITERATIONS 100
28+
/* Expected delay in ms: In this expression CONFIG_NRF_RRAM_THROTTLING_DELAY
29+
* is expressed in microseconds and CONFIG_NRF_RRAM_THROTTLING_DATA_BLOCK is in
30+
* number of write lines of 16 bytes each.
31+
*/
32+
#define EXPECTED_DELAY \
33+
((TEST_ITERATIONS * BUF_SIZE * CONFIG_NRF_RRAM_THROTTLING_DELAY) / \
34+
(CONFIG_NRF_RRAM_THROTTLING_DATA_BLOCK * 16 * 1000))
35+
#if !defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE) && !defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
36+
#error There is no flash device enabled or it is missing Kconfig options
37+
#endif
38+
39+
static const struct device *const flash_dev = TEST_AREA_DEVICE;
40+
static uint8_t __aligned(4) buf[BUF_SIZE];
41+
42+
static void *rram_throttling_setup(void)
43+
{
44+
zassert_true(device_is_ready(flash_dev));
45+
46+
TC_PRINT("Test will run on device %s\n", flash_dev->name);
47+
TC_PRINT("TEST_AREA_OFFSET = 0x%lx\n", (unsigned long)TEST_AREA_OFFSET);
48+
TC_PRINT("TEST_AREA_SIZE = 0x%lx\n", (unsigned long)TEST_AREA_SIZE);
49+
50+
return NULL;
51+
}
52+
53+
ZTEST(rram_throttling, test_flash_throttling)
54+
{
55+
int rc;
56+
uint32_t start = TEST_AREA_OFFSET;
57+
58+
#if !defined(CONFIG_SOC_FLASH_NRF_THROTTLING)
59+
ztest_test_skip();
60+
#endif
61+
62+
int64_t ts = k_uptime_get();
63+
64+
for (int i = 0; i < TEST_ITERATIONS; i++) {
65+
rc = flash_write(flash_dev, start, buf, BUF_SIZE);
66+
zassert_equal(rc, 0, "Cannot write to flash");
67+
}
68+
/* Delay measured in milliseconds */
69+
int64_t delta = k_uptime_delta(&ts);
70+
71+
zassert_true(delta > EXPECTED_DELAY, "Invalid delay, expected > %d, measured: %lld",
72+
EXPECTED_DELAY, delta);
73+
}
74+
75+
ZTEST_SUITE(rram_throttling, NULL, rram_throttling_setup, NULL, NULL, NULL);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
common:
5+
tags:
6+
- drivers
7+
- flash
8+
tests:
9+
flash.throttling:
10+
harness: ztest
11+
harness_config:
12+
fixture: external_flash
13+
platform_allow:
14+
- nrf54l15dk/nrf54l15/cpuapp
15+
- nrf54l15dk/nrf54l10/cpuapp

0 commit comments

Comments
 (0)