diff --git a/TESTS/mbed_hal/qspi/flash_configs/MX25RXX35F_config.h b/TESTS/mbed_hal/qspi/flash_configs/MX25RXX35F_config.h index 54f895c0ef..01be2c219b 100644 --- a/TESTS/mbed_hal/qspi/flash_configs/MX25RXX35F_config.h +++ b/TESTS/mbed_hal/qspi/flash_configs/MX25RXX35F_config.h @@ -52,6 +52,8 @@ #define QSPI_PAGE_PROG_MAX_TIME 11500 // 10ms #define QSPI_PAGE_SIZE 256 // 256B +#define QSPI_SECTOR_SIZE 4096 // 4kB +#define QSPI_SECTOR_COUNT 32 // adjusted to MX25R1035F smallest one from MX25RXX35F family // Commands for reading #define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode diff --git a/TESTS/mbed_hal/qspi/flash_configs/N25Q128A_config.h b/TESTS/mbed_hal/qspi/flash_configs/N25Q128A_config.h index 326b91f279..30590b7c93 100644 --- a/TESTS/mbed_hal/qspi/flash_configs/N25Q128A_config.h +++ b/TESTS/mbed_hal/qspi/flash_configs/N25Q128A_config.h @@ -65,6 +65,8 @@ #define QSPI_PAGE_PROG_MAX_TIME 5750 // 5ms #define QSPI_PAGE_SIZE 256 // 256B +#define QSPI_SECTOR_SIZE 4096 // 4kB +#define QSPI_SECTOR_COUNT 4096 // Commands for reading #define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode diff --git a/TESTS/mbed_hal/qspi/main.cpp b/TESTS/mbed_hal/qspi/main.cpp index 58e9680852..647f7cc467 100644 --- a/TESTS/mbed_hal/qspi/main.cpp +++ b/TESTS/mbed_hal/qspi/main.cpp @@ -74,6 +74,13 @@ uint8_t rx_buf[DATA_SIZE_1024]; #define QCSN static_cast(QSPI_FLASH1_CSN) +static uint32_t gen_flash_address() +{ + srand(ticker_read(get_us_ticker_data())); + uint32_t address = (((uint32_t)rand()) % QSPI_SECTOR_COUNT) * QSPI_SECTOR_SIZE; + return address; +} + static void log_data(const char *str, uint8_t *data, uint32_t size) { utest_printf("%s: ", str); @@ -246,6 +253,13 @@ void qspi_write_read_test(void) { qspi_status_t ret; Qspi qspi; + + uint32_t addr = flash_addr; + if (addr == 0) { + // if no specified address selected, use random one to extend flash life + addr = gen_flash_address(); + } + qspi_init(&qspi.handle, QPIN_0, QPIN_1, QPIN_2, QPIN_3, QSCK, QCSN, QSPI_COMMON_MAX_FREQUENCY, 0); qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8); @@ -270,7 +284,7 @@ void qspi_write_read_test(void) write_addr_size, write_alt_size, write_frequency, write_count, read_inst_width, read_addr_width, read_data_width, read_alt_width, read_cmd, read_dummy_cycles, read_addr_size, read_alt_size, read_frequency, read_count, test_count, - data_size, flash_addr); + data_size, addr); ret = fast_mode_disable(qspi); TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);