Skip to content

Commit b9daf3f

Browse files
authored
Merge pull request #13848 from LDong-Arm/qspif_program_size_fix
Q/OSPIFBlockDevice: fix misconception in minimum program size
2 parents 66c05dd + 13c5b64 commit b9daf3f

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

storage/blockdevice/COMPONENT_OSPIF/mbed_lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"OSPI_POLARITY_MODE": 0,
2424
"OSPI_FREQ": "40000000",
2525
"OSPI_MIN_READ_SIZE": "1",
26-
"OSPI_MIN_PROG_SIZE": "256"
26+
"OSPI_MIN_PROG_SIZE": "1"
2727
},
2828
"target_overrides": {
2929
"MX25LM51245G": {

storage/blockdevice/COMPONENT_QSPIF/mbed_lib.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"QSPI_POLARITY_MODE": 0,
1919
"QSPI_FREQ": "40000000",
2020
"QSPI_MIN_READ_SIZE": "1",
21-
"QSPI_MIN_PROG_SIZE": "256"
21+
"QSPI_MIN_PROG_SIZE": "1"
2222
},
2323
"target_overrides": {
2424
"MX25R6435F": {
@@ -37,15 +37,18 @@
3737
"MCU_NRF52840": {
3838
"QSPI_FREQ": "32000000",
3939
"QSPI_MIN_READ_SIZE": "4",
40-
"QSPI_MIN_PROG_SIZE": "256"
40+
"QSPI_MIN_PROG_SIZE": "4"
4141
},
4242
"MCU_PSOC6": {
43-
"QSPI_FREQ": "50000000",
44-
"QSPI_MIN_PROG_SIZE": "512"
43+
"QSPI_FREQ": "50000000"
4544
},
4645
"EFM32GG11_STK3701": {
4746
"QSPI_MIN_READ_SIZE": "4",
48-
"QSPI_MIN_PROG_SIZE": "256"
47+
"QSPI_MIN_PROG_SIZE": "4"
48+
},
49+
"MCU_LPC546XX": {
50+
"QSPI_MIN_READ_SIZE": "4",
51+
"QSPI_MIN_PROG_SIZE": "4"
4952
}
5053
}
5154
}

storage/blockdevice/tests/TESTS/blockdevice/general_block_device/main.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,18 @@ void test_contiguous_erase_write_read()
546546

547547
bd_size_t contiguous_erase_size = stop_address - start_address;
548548
TEST_ASSERT(contiguous_erase_size > 0);
549-
utest_printf("contiguous_erase_size=%d\n", contiguous_erase_size);
549+
utest_printf("contiguous_erase_size=0x%" PRIx64 "\n", contiguous_erase_size);
550550

551551
bd_size_t write_read_buf_size = program_size;
552-
if (contiguous_erase_size / program_size > 8 && contiguous_erase_size % (program_size * 8) == 0) {
553-
write_read_buf_size = program_size * 8;
552+
553+
// Reading/writing in larger chunks reduces the number of operations,
554+
// helping to avoid test timeouts. Try 256-byte chunks if contiguous_erase_size
555+
// (which should be a power of 2) is greater than that. If it's less than
556+
// that, the test finishes quickly anyway...
557+
if ((program_size < 256) && (256 % program_size == 0)
558+
&& (contiguous_erase_size >= 256) && (contiguous_erase_size % 256 == 0)) {
559+
utest_printf("using 256-byte write/read buffer\n");
560+
write_read_buf_size = 256;
554561
}
555562

556563
// Allocate write/read buffer

storage/kvstore/tests/TESTS/kvstore/general_tests_phase_2/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static void kvstore_init()
7979
// be a close enough approximation to act as a guideline for how much of the block device we
8080
// need to erase in order to ensure a stable initial condition.
8181
const size_t PAGES_ESTIMATE = 40;
82+
const size_t MIN_TDBSTORE_SIZE = 2 * 8 * 1024; // two areas, minimum 8KB per area
8283

8384
int res;
8485
size_t program_size, erase_size, ul_bd_size, rbp_bd_size;
@@ -133,8 +134,12 @@ static void kvstore_init()
133134
erase_size = sec_bd->get_erase_size();
134135
// We must be able to hold at least 10 small keys (20 program sectors) and master record + internal data
135136
// but minimum of 2 erase sectors, so that the garbage collection way work
136-
ul_bd_size = align_up(program_size * PAGES_ESTIMATE, erase_size * 2);
137-
rbp_bd_size = align_up(program_size * PAGES_ESTIMATE, erase_size * 2);
137+
// Also, the total size needs to be large enough for set_add_data_set_key_value_five_Kbytes (5KB value)
138+
// and to allow for overheads, we require at least 2 * 8KB for two areas per TDBStore
139+
ul_bd_size = program_size * PAGES_ESTIMATE;
140+
ul_bd_size = ul_bd_size > MIN_TDBSTORE_SIZE ? ul_bd_size : MIN_TDBSTORE_SIZE;
141+
ul_bd_size = align_up(ul_bd_size, erase_size * 2);
142+
rbp_bd_size = ul_bd_size;
138143

139144
res = sec_bd->deinit();
140145
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);

0 commit comments

Comments
 (0)