Skip to content

Commit 384a9d5

Browse files
MarekPorwiszrlubos
authored andcommitted
rpc: lib: samples: API for testing RRAM wear.
Added a library that allows testing if RRAM writes succesfully. Made an RPC API for invoking this command on server. Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
1 parent 0709c3b commit 384a9d5

19 files changed

Lines changed: 886 additions & 1 deletion

File tree

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
/include/caf/ @nrfconnect/ncs-si-bluebagel @nrfconnect/ncs-si-muffin @nrfconnect/ncs-si-xcake
340340
/include/debug/ @nrfconnect/ncs-co-drivers
341341
/include/debug/ppi_trace.h @nrfconnect/ncs-co-drivers @nordic-krch
342+
/include/debug/rram_wear_test.h @nrfconnect/ncs-protocols-serialization
342343
/include/dfu/ @nrfconnect/ncs-code-owners
343344
/include/drivers/flash/ @nrfconnect/ncs-co-drivers
344345
/include/drivers/gpio/ @nrfconnect/ncs-co-drivers @nrfconnect/ncs-ll-ursus
@@ -392,6 +393,7 @@
392393
/lib/fatal_error/ @nordic-krch
393394
/lib/fem_al/ @nrfconnect/ncs-dragoon
394395
/lib/flash_patch/ @nrfconnect/ncs-eris
396+
/lib/rram_wear_test/ @nrfconnect/ncs-protocols-serialization
395397
/lib/fprotect/ @nrfconnect/ncs-eris
396398
/lib/gcf_sms/ @nrfconnect/ncs-modem
397399
/lib/hw_id/ @nrfconnect/ncs-cia

include/debug/rram_wear_test.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef RRAM_WEAR_TEST_H_
8+
#define RRAM_WEAR_TEST_H_
9+
10+
#include <stdbool.h>
11+
#include <stddef.h>
12+
#include <stdint.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/**
19+
* @defgroup rram_wear_test RRAM wear test
20+
*
21+
* Writes 0x00 then 0xFF over a flash partition (or a forced custom range on the
22+
* internal flash device) and verifies readback. Intended for bring-up / stress checks.
23+
* @{
24+
*/
25+
26+
/**
27+
* @brief Flash partition (or custom range) parameters for wear test.
28+
*
29+
* For @c name @c "custom", @a addr_start and @a addr_end are byte offsets on the internal
30+
* flash device (@a addr_end exclusive). For any other name, offsets describe the partition
31+
* span from the flash map (see @ref rram_wear_test_partition_get); the verify path still
32+
* opens the area by name and ignores @a addr_* for the actual I/O.
33+
*
34+
* @a name may be an empty string when the partition has no DTS @c label (unnamed partition);
35+
* identification then relies on the flash map / node label.
36+
*/
37+
struct rram_wear_test_partition {
38+
const char *name;
39+
uint64_t addr_start;
40+
uint64_t addr_end;
41+
};
42+
43+
/**
44+
* @brief Get the number of entries in the partition table.
45+
*/
46+
size_t rram_wear_test_partition_count(void);
47+
48+
/**
49+
* @brief Fill @a out with partition name and device byte range from the flash map.
50+
*
51+
* @param index Row index in <tt>[0, rram_wear_test_partition_count())</tt>.
52+
* @param[out] out Filled on success; @a name points at build-time string storage (possibly @c ""
53+
* when the partition has no DTS @c label).
54+
*
55+
* @retval 0 on success.
56+
* @retval -EINVAL if @a out is NULL.
57+
* @retval -ENOENT if @a index is out of range or the flash area cannot be opened.
58+
*/
59+
int rram_wear_test_partition_get(size_t index, struct rram_wear_test_partition *out);
60+
61+
/**
62+
* @brief Run write/readback verify on a named flash region or custom range.
63+
*
64+
* Uses the internal partition table (see @a index), or
65+
* a custom byte range on the internal flash device when @a addr_end is greater than @a addr_start.
66+
*
67+
* @param index Partition index from the array to test.
68+
* @param addr_start Optional start offset for a custom range (used if addr_end > addr_start).
69+
* @param addr_end Optional end offset (exclusive) for a custom range.
70+
* @param force Must be true for custom ranges or @c -EPERM is returned.
71+
*
72+
* @retval 0 on success, negative errno otherwise (@c -EIO on pattern mismatch).
73+
*/
74+
int rram_wear_test(size_t index, uint64_t addr_start, uint64_t addr_end, bool force);
75+
76+
77+
/** @} */
78+
79+
#ifdef __cplusplus
80+
}
81+
#endif
82+
83+
#endif /* RRAM_WEAR_TEST_H_ */
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2026 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef NRF_RPC_RRAM_WEAR_TEST_H_
8+
#define NRF_RPC_RRAM_WEAR_TEST_H_
9+
10+
#include <debug/rram_wear_test.h>
11+
#include <stdbool.h>
12+
#include <stdint.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/**
19+
* @addtogroup nrf_rpc_utils nRF RPC utility commands
20+
* @{
21+
* @defgroup nrf_rpc_rram_wear_test nRF RPC flash wear test
22+
* @{
23+
*/
24+
25+
/** @brief Run write/readback verify on a selected remote flash region.
26+
*
27+
* @param index Partition index from the array.
28+
* @param addr_start Optional start offset for a custom range (used if addr_end > addr_start).
29+
* @param addr_end Optional end offset (exclusive) for a custom range.
30+
* @param force Must be true for custom ranges or @c -EPERM is returned.
31+
*
32+
* @retval 0 on success.
33+
* @retval -EPERM if @a region is @c custom and @a force is false.
34+
* @retval -EINVAL for invalid arguments or an out-of-bounds custom range.
35+
* @retval -ENOENT if the named partition is not present in the build.
36+
* @retval -ENODEV if the flash device cannot be resolved for a custom range.
37+
* @retval Other negative errno from flash operations, or @c -EIO on verify mismatch.
38+
* @retval -EBADMSG if the RPC response could not be decoded.
39+
*/
40+
int nrf_rpc_rram_wear_test(size_t index, uint64_t addr_start, uint64_t addr_end, bool force);
41+
42+
/** @brief Get the number of partitions from the remote server.
43+
*
44+
* @param[out] count Pointer to store the number of partitions.
45+
*
46+
* @retval 0 on success.
47+
* @retval -EBADMSG if the RPC response could not be decoded.
48+
*/
49+
int nrf_rpc_rram_wear_test_get_partition_count(size_t *count);
50+
51+
/** @brief Get partition details from the remote server.
52+
*
53+
* @param index Partition index.
54+
* @param[out] part Pointer to store the partition details. The name string will be allocated
55+
* internally and must be freed by the caller using
56+
* @ref nrf_rpc_rram_wear_test_partition_free.
57+
*
58+
* @retval 0 on success.
59+
* @retval -EBADMSG if the RPC response could not be decoded.
60+
*/
61+
int nrf_rpc_rram_wear_test_get_partition(size_t index, struct rram_wear_test_partition *part);
62+
63+
/** @brief Free memory allocated by @ref nrf_rpc_rram_wear_test_get_partition.
64+
*
65+
* @param part Pointer to the partition structure whose memory should be freed.
66+
*/
67+
void nrf_rpc_rram_wear_test_partition_free(struct rram_wear_test_partition *part);
68+
69+
/**
70+
* @}
71+
* @}
72+
*/
73+
74+
#ifdef __cplusplus
75+
}
76+
#endif
77+
78+
#endif /* NRF_RPC_RRAM_WEAR_TEST_H_ */

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_subdirectory_ifdef(CONFIG_ACCEL_TO_ANGLE accel_to_angle)
2121
add_subdirectory_ifdef(CONFIG_ADP536X adp536x)
2222
add_subdirectory_ifdef(CONFIG_ST25R3911B_LIB st25r3911b)
2323
add_subdirectory_ifdef(CONFIG_FPROTECT fprotect)
24+
add_subdirectory_ifdef(CONFIG_RRAM_WEAR_TEST rram_wear_test)
2425
add_subdirectory(flash_patch)
2526
add_subdirectory_ifdef(CONFIG_RAM_POWER_DOWN_LIBRARY ram_pwrdn)
2627
add_subdirectory(fatal_error)

lib/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rsource "accel_to_angle/Kconfig"
1414
rsource "at_monitor/Kconfig"
1515
rsource "st25r3911b/Kconfig"
1616
rsource "flash_patch/Kconfig"
17+
rsource "rram_wear_test/Kconfig"
1718
rsource "lte_link_control/Kconfig"
1819
rsource "ntn/Kconfig"
1920
rsource "fprotect/Kconfig"

lib/rram_wear_test/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Copyright (c) 2026 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
zephyr_library()
8+
9+
zephyr_library_sources(rram_wear_test.c)

lib/rram_wear_test/Kconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (c) 2026 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
config RRAM_WEAR_TEST
8+
bool "RRAM wear test library [EXPERIMENTAL]"
9+
depends on FLASH
10+
depends on FLASH_MAP
11+
depends on SOC_FLASH_NRF_RRAM
12+
select EXPERIMENTAL
13+
help
14+
Library that writes 0x00 / 0xFF patterns over a flash partition (or a forced
15+
custom range) and verifies readback. Used by nRF RPC utilities and callable
16+
directly from in-tree applications.
17+
18+
module = RRAM_WEAR_TEST
19+
module-str = rram_wear_test
20+
source "subsys/logging/Kconfig.template.log_config"

0 commit comments

Comments
 (0)