@@ -43,6 +43,7 @@ using namespace mbed;
43
43
44
44
/* SFDP Header Parsing */
45
45
/* **********************/
46
+ #define QSPIF_RSFDP_DUMMY_CYCLES 8
46
47
#define QSPIF_SFDP_HEADER_SIZE 8
47
48
#define QSPIF_PARAM_HEADER_SIZE 8
48
49
@@ -190,6 +191,14 @@ int QSPIFBlockDevice::init()
190
191
191
192
_mutex.lock ();
192
193
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
+
193
202
if (!_is_initialized) {
194
203
_init_ref_count = 0 ;
195
204
}
@@ -254,14 +263,6 @@ int QSPIFBlockDevice::init()
254
263
}
255
264
}
256
265
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
-
265
266
if (0 != _clear_block_protection ()) {
266
267
tr_error (" Init - clearing block protection failed" );
267
268
status = QSPIF_BD_ERROR_PARSING_FAILED;
@@ -320,28 +321,11 @@ int QSPIFBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
320
321
321
322
_mutex.lock ();
322
323
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
-
331
324
if (QSPI_STATUS_OK != _qspi_send_read_command (_read_instruction, buffer, addr, size)) {
332
325
tr_error (" Read Command failed" );
333
326
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;
342
327
}
343
328
344
- exit_point:
345
329
_mutex.unlock ();
346
330
347
331
return status;
@@ -625,14 +609,7 @@ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_
625
609
size_t data_length = QSPIF_SFDP_HEADER_SIZE;
626
610
bd_addr_t addr = 0x0 ;
627
611
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);
636
613
if (status != QSPI_STATUS_OK) {
637
614
tr_error (" Init - Read SFDP Failed" );
638
615
return -1 ;
@@ -657,8 +634,7 @@ int QSPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_
657
634
658
635
// Loop over Param Headers and parse them (currently supported Basic Param Table and Sector Region Map Table)
659
636
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);
662
638
if (status != QSPI_STATUS_OK) {
663
639
tr_error (" Init - Read Param Table %d Failed" , i_ind + 1 );
664
640
return -1 ;
@@ -696,8 +672,7 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
696
672
{
697
673
uint8_t param_table[SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES]; /* Up To 16 DWORDS = 64 Bytes */
698
674
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);
701
676
if (status != QSPI_STATUS_OK) {
702
677
tr_error (" Init - Read SFDP First Table Failed" );
703
678
return -1 ;
@@ -804,13 +779,6 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
804
779
return 0 ;
805
780
}
806
781
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
-
814
782
// Read existing status register values
815
783
_qspi_read_status_registers (status_regs);
816
784
@@ -1176,9 +1144,7 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
1176
1144
// Default set to all type bits 1-4 are common
1177
1145
int min_common_erase_type_bits = ERASE_BITMASK_ALL;
1178
1146
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);
1182
1148
if (status != QSPI_STATUS_OK) {
1183
1149
tr_error (" Init - Read SFDP First Table Failed" );
1184
1150
return -1 ;
@@ -1435,7 +1401,25 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_read_command(qspi_inst_t read_inst, v
1435
1401
}
1436
1402
1437
1403
// 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
+
1439
1423
if (QSPI_STATUS_OK != status) {
1440
1424
tr_error (" QSPI Read failed" );
1441
1425
return status;
@@ -1507,15 +1491,34 @@ qspi_status_t QSPIFBlockDevice::_qspi_send_general_command(qspi_inst_t instructi
1507
1491
return QSPI_STATUS_OK;
1508
1492
}
1509
1493
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)
1513
1495
{
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;
1517
1497
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;
1519
1522
}
1520
1523
1521
1524
qspi_status_t QSPIFBlockDevice::_qspi_read_status_registers (uint8_t *reg_buffer)
0 commit comments