Skip to content

Commit b41ce6c

Browse files
qspi_hal_test - randomize flash RW addres
randomize flash address during test to extend flash life
1 parent 82c8190 commit b41ce6c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

TESTS/mbed_hal/qspi/flash_configs/MX25RXX35F_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#define QSPI_PAGE_PROG_MAX_TIME 11500 // 10ms
5353

5454
#define QSPI_PAGE_SIZE 256 // 256B
55+
#define QSPI_SECTOR_SIZE 4096 // 4kB
56+
#define QSPI_SECTOR_COUNT 32 // adjusted to MX25R1035F smallest one from MX25RXX35F family
5557

5658
// Commands for reading
5759
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode

TESTS/mbed_hal/qspi/flash_configs/N25Q128A_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
#define QSPI_PAGE_PROG_MAX_TIME 5750 // 5ms
6666

6767
#define QSPI_PAGE_SIZE 256 // 256B
68+
#define QSPI_SECTOR_SIZE 4096 // 4kB
69+
#define QSPI_SECTOR_COUNT 4096
6870

6971
// Commands for reading
7072
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode

TESTS/mbed_hal/qspi/main.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ uint8_t rx_buf[DATA_SIZE_1024];
7474
#define QCSN static_cast<PinName>(QSPI_FLASH1_CSN)
7575

7676

77+
static uint32_t gen_flash_address()
78+
{
79+
srand(ticker_read(get_us_ticker_data()));
80+
uint32_t address = (((uint32_t)rand()) % QSPI_SECTOR_COUNT) * QSPI_SECTOR_SIZE;
81+
return address;
82+
}
83+
7784
static void log_data(const char *str, uint8_t *data, uint32_t size)
7885
{
7986
utest_printf("%s: ", str);
@@ -246,6 +253,13 @@ void qspi_write_read_test(void)
246253
{
247254
qspi_status_t ret;
248255
Qspi qspi;
256+
257+
uint32_t addr = flash_addr;
258+
if (addr == 0) {
259+
// if no specified address selected, use random one to extend flash life
260+
addr = gen_flash_address();
261+
}
262+
249263
qspi_init(&qspi.handle, QPIN_0, QPIN_1, QPIN_2, QPIN_3, QSCK, QCSN, QSPI_COMMON_MAX_FREQUENCY, 0);
250264

251265
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
@@ -270,7 +284,7 @@ void qspi_write_read_test(void)
270284
write_addr_size, write_alt_size, write_frequency, write_count, read_inst_width,
271285
read_addr_width, read_data_width, read_alt_width, read_cmd, read_dummy_cycles,
272286
read_addr_size, read_alt_size, read_frequency, read_count, test_count,
273-
data_size, flash_addr);
287+
data_size, addr);
274288

275289
ret = fast_mode_disable(qspi);
276290
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);

0 commit comments

Comments
 (0)