Skip to content

Commit ba41273

Browse files
Matthew MacovskyKyle Kearney
authored andcommitted
Move configuration of QSPI format to within commands where it is necessary
1 parent 08a0b3d commit ba41273

File tree

2 files changed

+60
-59
lines changed

2 files changed

+60
-59
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ using namespace mbed;
4343

4444
/* SFDP Header Parsing */
4545
/***********************/
46+
#define QSPIF_RSFDP_DUMMY_CYCLES 8
4647
#define QSPIF_SFDP_HEADER_SIZE 8
4748
#define QSPIF_PARAM_HEADER_SIZE 8
4849

@@ -190,6 +191,14 @@ int QSPIFBlockDevice::init()
190191

191192
_mutex.lock();
192193

194+
// All commands other than Read and RSFDP use default 1-1-1 bus mode (Program/Erase are constrained by flash memory performance more than bus performance)
195+
if (QSPI_STATUS_OK != _qspi.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, _address_size, QSPI_CFG_BUS_SINGLE,
196+
0, QSPI_CFG_BUS_SINGLE, 0)) {
197+
tr_error("_qspi_configure_format failed");
198+
status = QSPIF_BD_ERROR_DEVICE_ERROR;
199+
goto exit_point;
200+
}
201+
193202
if (!_is_initialized) {
194203
_init_ref_count = 0;
195204
}
@@ -254,14 +263,6 @@ int QSPIFBlockDevice::init()
254263
}
255264
}
256265

257-
// Configure BUS Mode to 1_1_1 for all commands other than Read
258-
if (QSPI_STATUS_OK != _qspi_configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
259-
0, QSPI_CFG_BUS_SINGLE, 0)) {
260-
tr_error("_qspi_configure_format failed");
261-
status = QSPIF_BD_ERROR_DEVICE_ERROR;
262-
goto exit_point;
263-
}
264-
265266
if (0 != _clear_block_protection()) {
266267
tr_error("Init - clearing block protection failed");
267268
status = QSPIF_BD_ERROR_PARSING_FAILED;
@@ -320,28 +321,11 @@ int QSPIFBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
320321

321322
_mutex.lock();
322323

323-
// Configure Bus for Reading
324-
if (QSPI_STATUS_OK != _qspi_configure_format(_inst_width, _address_width, _address_size, _address_width, // Alt width == address width
325-
_alt_size, _data_width, _dummy_cycles)) {
326-
tr_error("_qspi_configure_format failed");
327-
status = QSPIF_BD_ERROR_DEVICE_ERROR;
328-
goto exit_point;
329-
}
330-
331324
if (QSPI_STATUS_OK != _qspi_send_read_command(_read_instruction, buffer, addr, size)) {
332325
tr_error("Read Command failed");
333326
status = QSPIF_BD_ERROR_DEVICE_ERROR;
334-
goto exit_point;
335-
}
336-
337-
// All commands other than Read use default 1-1-1 Bus mode (Program/Erase are constrained by flash memory performance more than bus performance)
338-
if (QSPI_STATUS_OK != _qspi_configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE, 0, QSPI_CFG_BUS_SINGLE, 0)) {
339-
tr_error("_qspi_configure_format failed");
340-
status = QSPIF_BD_ERROR_DEVICE_ERROR;
341-
goto exit_point;
342327
}
343328

344-
exit_point:
345329
_mutex.unlock();
346330

347331
return status;
@@ -625,14 +609,7 @@ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_
625609
size_t data_length = QSPIF_SFDP_HEADER_SIZE;
626610
bd_addr_t addr = 0x0;
627611

628-
// Set 1-1-1 bus mode for SFDP header parsing
629-
if (QSPI_STATUS_OK != _qspi_configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
630-
0, QSPI_CFG_BUS_SINGLE, 8)) {
631-
tr_error("_qspi_configure_format failed");
632-
return -1;
633-
}
634-
635-
qspi_status_t status = _qspi_send_read_command(QSPIF_SFDP, (char *)sfdp_header, addr /*address*/, data_length);
612+
qspi_status_t status = _qspi_send_read_sfdp_command(addr, (char*) sfdp_header, data_length);
636613
if (status != QSPI_STATUS_OK) {
637614
tr_error("Init - Read SFDP Failed");
638615
return -1;
@@ -657,8 +634,7 @@ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_
657634

658635
// Loop over Param Headers and parse them (currently supported Basic Param Table and Sector Region Map Table)
659636
for (int i_ind = 0; i_ind < number_of_param_headers; i_ind++) {
660-
661-
status = _qspi_send_read_command(QSPIF_SFDP, (char *)param_header, addr, data_length);
637+
status = _qspi_send_read_sfdp_command(addr, (char *) param_header, data_length);
662638
if (status != QSPI_STATUS_OK) {
663639
tr_error("Init - Read Param Table %d Failed", i_ind + 1);
664640
return -1;
@@ -696,8 +672,7 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
696672
{
697673
uint8_t param_table[SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES]; /* Up To 16 DWORDS = 64 Bytes */
698674

699-
qspi_status_t status = _qspi_send_read_command(QSPIF_SFDP, (char *)param_table, basic_table_addr /*address*/,
700-
basic_table_size);
675+
qspi_status_t status = _qspi_send_read_sfdp_command(basic_table_addr, (char*) param_table, basic_table_size);
701676
if (status != QSPI_STATUS_OK) {
702677
tr_error("Init - Read SFDP First Table Failed");
703678
return -1;
@@ -804,13 +779,6 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
804779
return 0;
805780
}
806781

807-
// Configure BUS Mode to 1_1_1 for all commands other than Read
808-
if (QSPI_STATUS_OK != _qspi_configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
809-
0, QSPI_CFG_BUS_SINGLE, 0)) {
810-
tr_error("_qspi_configure_format failed");
811-
return -1;
812-
}
813-
814782
// Read existing status register values
815783
_qspi_read_status_registers(status_regs);
816784

@@ -1176,9 +1144,7 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
11761144
// Default set to all type bits 1-4 are common
11771145
int min_common_erase_type_bits = ERASE_BITMASK_ALL;
11781146

1179-
1180-
qspi_status_t status = _qspi_send_read_command(QSPIF_SFDP, (char *)sector_map_table, sector_map_table_addr /*address*/,
1181-
sector_map_table_size);
1147+
qspi_status_t status = _qspi_send_read_sfdp_command(sector_map_table_addr, (char *) sector_map_table, sector_map_table_size);
11821148
if (status != QSPI_STATUS_OK) {
11831149
tr_error("Init - Read SFDP First Table Failed");
11841150
return -1;
@@ -1435,7 +1401,25 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(qspi_inst_t read_inst, v
14351401
}
14361402

14371403
// Send read command to device driver
1438-
status = _qspi.read(read_inst, -1, (unsigned int)addr, (char *)buffer, &buf_len);
1404+
// Read commands use the best bus mode supported by the part
1405+
status = _qspi.configure_format(_inst_width, _address_width, _address_size, _address_width, // Alt width should be the same as address width
1406+
_alt_size, _data_width, _dummy_cycles);
1407+
if (QSPI_STATUS_OK != status) {
1408+
tr_error("_qspi_configure_format failed");
1409+
return status;
1410+
}
1411+
1412+
// Don't check the read status until after we've configured the format back to 1-1-1, to avoid leaving the interface in an
1413+
// incorrect state if the read fails.
1414+
status = _qspi.read(read_inst, (_alt_size == 0) ? -1 : QSPI_ALT_DEFAULT_VALUE, (unsigned int)addr, (char *)buffer, &buf_len);
1415+
1416+
// All commands other than Read and RSFDP use default 1-1-1 bus mode (Program/Erase are constrained by flash memory performance more than bus performance)
1417+
qspi_status_t format_status = _qspi.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, _address_size, QSPI_CFG_BUS_SINGLE, 0, QSPI_CFG_BUS_SINGLE, 0);
1418+
if (QSPI_STATUS_OK != format_status) {
1419+
tr_error("_qspi_configure_format failed");
1420+
return format_status;
1421+
}
1422+
14391423
if (QSPI_STATUS_OK != status) {
14401424
tr_error("QSPI Read failed");
14411425
return status;
@@ -1507,15 +1491,34 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(qspi_inst_t instructi
15071491
return QSPI_STATUS_OK;
15081492
}
15091493

1510-
qspi_status_t QSPIFBlockDevice::_qspi_configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width,
1511-
qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width,
1512-
int dummy_cycles)
1494+
qspi_status_t QSPIFBlockDevice::_qspi_send_read_sfdp_command(bd_addr_t addr, void *rx_buffer, bd_size_t rx_length)
15131495
{
1514-
// Configure QSPI driver Bus format
1515-
qspi_status_t status = _qspi.configure_format(inst_width, address_width, address_size, alt_width, alt_size, data_width,
1516-
dummy_cycles);
1496+
size_t rx_len = rx_length;
15171497

1518-
return status;
1498+
// SFDP read instruction requires 1-1-1 bus mode with 8 dummy cycles and a 3-byte address
1499+
qspi_status_t status = _qspi.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE, 0, QSPI_CFG_BUS_SINGLE, QSPIF_RSFDP_DUMMY_CYCLES);
1500+
if (QSPI_STATUS_OK != status) {
1501+
tr_error("_qspi_configure_format failed");
1502+
return status;
1503+
}
1504+
1505+
// Don't check the read status until after we've configured the format back to 1-1-1, to avoid leaving the interface in an
1506+
// incorrect state if the read fails.
1507+
status = _qspi.read(QSPIF_INST_RSFDP, -1, (unsigned int) addr, (char *) rx_buffer, &rx_len);
1508+
1509+
qspi_status_t format_status = _qspi.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, _address_size, QSPI_CFG_BUS_SINGLE, 0, QSPI_CFG_BUS_SINGLE, 0);
1510+
// All commands other than Read and RSFDP use default 1-1-1 bus mode (Program/Erase are constrained by flash memory performance more than bus performance)
1511+
if (QSPI_STATUS_OK != format_status) {
1512+
tr_error("_qspi_configure_format failed");
1513+
return format_status;
1514+
}
1515+
1516+
if (QSPI_STATUS_OK != status) {
1517+
tr_error("Sending SFDP read instruction");
1518+
return status;
1519+
}
1520+
1521+
return QSPI_STATUS_OK;
15191522
}
15201523

15211524
qspi_status_t QSPIFBlockDevice::_qspi_read_status_registers(uint8_t *reg_buffer)

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,8 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
248248
qspi_status_t _qspi_send_general_command(mbed::qspi_inst_t instruction_int, mbed::bd_addr_t addr, const char *tx_buffer,
249249
mbed::bd_size_t tx_length, const char *rx_buffer, mbed::bd_size_t rx_length);
250250

251-
// Send Bus configure_format command to Driver
252-
qspi_status_t _qspi_configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width,
253-
qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width,
254-
int dummy_cycles);
251+
// Send command to read from the SFDP table
252+
qspi_status_t _qspi_send_read_sfdp_command(mbed::bd_addr_t addr, void *rx_buffer, mbed::bd_size_t rx_length);
255253

256254
// Read the contents of status registers 1 and 2 into a buffer (buffer must have a length of 2)
257255
qspi_status_t _qspi_read_status_registers(uint8_t *reg_buffer);

0 commit comments

Comments
 (0)