Skip to content

Commit a8bf08b

Browse files
nordic-bamijhedberg
authored andcommitted
tests: drivers: flash: Add test with buffer size over the bus packet limit
Applicable to flash devices with MSPI controller Signed-off-by: Bartosz Miller <[email protected]>
1 parent ed92ee5 commit a8bf08b

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

tests/drivers/flash/common/boards/mx25uw63_freq_256k.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
&mx25uw63 {
88
status = "okay";
99
mspi-max-frequency = <DT_FREQ_K(256)>;
10+
transfer-timeout = <500>;
1011
};

tests/drivers/flash/common/boards/mx25uw63_single_io.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@
5858
status = "okay";
5959
mspi-max-frequency = <DT_FREQ_M(50)>;
6060
mspi-io-mode = "MSPI_IO_MODE_SINGLE";
61+
transfer-timeout = <500>;
6162
};

tests/drivers/flash/common/boards/mx25uw63_single_io_4B_addr_sreset.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
<NRF_PSEL(EXMIF_DQ7, 6, 4)>;
4141
};
4242
};
43-
4443
};
4544

4645
&gpio6 {
@@ -61,4 +60,5 @@
6160
mspi-io-mode = "MSPI_IO_MODE_SINGLE";
6261
use-4byte-addressing;
6362
initial-soft-reset;
63+
transfer-timeout = <500>;
6464
};

tests/drivers/flash/common/src/main.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
#error There is no flash device enabled or it is missing Kconfig options
7272
#endif
7373

74+
#if DT_NODE_HAS_PROP(DT_BUS(TEST_AREA_DEV_NODE), packet_data_limit)
75+
#define CONTROLLER_PACKET_DATA_LIMIT DT_PROP(DT_BUS(TEST_AREA_DEV_NODE), packet_data_limit)
76+
#define BUFFER_SIZE_OVER_PACKET_LIMIT CONTROLLER_PACKET_DATA_LIMIT + 1
77+
#endif
78+
7479
static const struct device *const flash_dev = TEST_AREA_DEVICE;
7580
static struct flash_pages_info page_info;
7681
static uint8_t __aligned(4) expected[EXPECTED_SIZE];
@@ -334,6 +339,39 @@ ZTEST(flash_driver, test_flash_erase)
334339
zassert_not_equal(expected[0], erase_value, "These values shall be different");
335340
}
336341

342+
ZTEST(flash_driver, test_flash_write_read_over_the_packet_limit)
343+
{
344+
345+
#if !defined(CONTROLLER_PACKET_DATA_LIMIT)
346+
TC_PRINT("Given bus controller does not have 'packet_data_limit' property\n");
347+
ztest_test_skip();
348+
#else
349+
int rc;
350+
const uint8_t pattern = 0xA1;
351+
static uint8_t large_data_buf[BUFFER_SIZE_OVER_PACKET_LIMIT];
352+
353+
/* Flatten area corresponding to the size of two packets */
354+
rc = flash_flatten(flash_dev, page_info.start_offset, 2 * CONTROLLER_PACKET_DATA_LIMIT);
355+
zassert_equal(rc, 0, "Flash flatten failed: %d", rc);
356+
357+
/* Fill flash area with buffer size over the configured packet limit */
358+
rc = flash_fill(flash_dev, pattern, page_info.start_offset, BUFFER_SIZE_OVER_PACKET_LIMIT);
359+
zassert_equal(rc, 0, "Flash fill failed");
360+
361+
/* Read flash area with buffer size over the MSPI packet limit */
362+
rc = flash_read(flash_dev, page_info.start_offset, large_data_buf,
363+
BUFFER_SIZE_OVER_PACKET_LIMIT);
364+
zassert_equal(rc, 0, "Flash read failed");
365+
366+
/* Compare read data to the pre-defined pattern */
367+
for (int i = 0; i < BUFFER_SIZE_OVER_PACKET_LIMIT; i++) {
368+
zassert_equal(large_data_buf[i], pattern,
369+
"large_data_buf[%u]=%x read, does not match written pattern %x", i,
370+
large_data_buf[i], pattern);
371+
}
372+
#endif
373+
}
374+
337375
ZTEST(flash_driver, test_supply_gpios_control)
338376
{
339377
if (!DT_NODE_HAS_PROP(TEST_AREA_DEV_NODE, supply_gpios)) {

0 commit comments

Comments
 (0)