qspi_hal_test - randomize flash RW addres

randomize flash address during test to extend flash life
pull/7925/head
Maciej Bocianski 2018-08-29 14:47:39 +02:00
parent 82c81900bf
commit b41ce6c090
3 changed files with 19 additions and 1 deletions

View File

@ -52,6 +52,8 @@
#define QSPI_PAGE_PROG_MAX_TIME 11500 // 10ms #define QSPI_PAGE_PROG_MAX_TIME 11500 // 10ms
#define QSPI_PAGE_SIZE 256 // 256B #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 // Commands for reading
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode #define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode

View File

@ -65,6 +65,8 @@
#define QSPI_PAGE_PROG_MAX_TIME 5750 // 5ms #define QSPI_PAGE_PROG_MAX_TIME 5750 // 5ms
#define QSPI_PAGE_SIZE 256 // 256B #define QSPI_PAGE_SIZE 256 // 256B
#define QSPI_SECTOR_SIZE 4096 // 4kB
#define QSPI_SECTOR_COUNT 4096
// Commands for reading // Commands for reading
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode #define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode

View File

@ -74,6 +74,13 @@ uint8_t rx_buf[DATA_SIZE_1024];
#define QCSN static_cast<PinName>(QSPI_FLASH1_CSN) #define QCSN static_cast<PinName>(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) static void log_data(const char *str, uint8_t *data, uint32_t size)
{ {
utest_printf("%s: ", str); utest_printf("%s: ", str);
@ -246,6 +253,13 @@ void qspi_write_read_test(void)
{ {
qspi_status_t ret; qspi_status_t ret;
Qspi qspi; 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_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); 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, 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_width, read_data_width, read_alt_width, read_cmd, read_dummy_cycles,
read_addr_size, read_alt_size, read_frequency, read_count, test_count, read_addr_size, read_alt_size, read_frequency, read_count, test_count,
data_size, flash_addr); data_size, addr);
ret = fast_mode_disable(qspi); ret = fast_mode_disable(qspi);
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret); TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);