@@ -165,6 +165,7 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
165
165
// Until proven otherwise, assume no quad enable
166
166
_quad_enable_register_idx = QSPIF_NO_QUAD_ENABLE;
167
167
_quad_enable_bit = QSPIF_NO_QUAD_ENABLE;
168
+ _needs_fast_mode = false ;
168
169
169
170
// Default Bus Setup 1_1_1 with 0 dummy and mode cycles
170
171
_inst_width = QSPI_CFG_BUS_SINGLE;
@@ -734,7 +735,9 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
734
735
// Detect and Set fastest Bus mode (default 1-1-1)
735
736
_sfdp_detect_best_bus_read_mode (param_table, basic_table_size, shouldSetQuadEnable, is_qpi_mode);
736
737
if (true == shouldSetQuadEnable) {
737
- _enable_fast_mode ();
738
+ if (_needs_fast_mode) {
739
+ _enable_fast_mode ();
740
+ }
738
741
// Set Quad Enable and QPI Bus modes if Supported
739
742
tr_debug (" Init - Setting Quad Enable" );
740
743
if (0 != _sfdp_set_quad_enabled (param_table)) {
@@ -1243,6 +1246,7 @@ int QSPIFBlockDevice::_handle_vendor_quirks()
1243
1246
// 1. Have one status register and 2 config registers, with a nonstandard instruction for reading the config registers
1244
1247
// 2. Require setting a "fast mode" bit in config register 2 to operate at higher clock rates
1245
1248
tr_debug (" Applying quirks for macronix" );
1249
+ _needs_fast_mode = true ;
1246
1250
_num_status_registers = 3 ;
1247
1251
_read_status_reg_2_inst = QSPIF_INST_RDCR;
1248
1252
break ;
@@ -1342,11 +1346,13 @@ int QSPIFBlockDevice::_set_write_enable()
1342
1346
1343
1347
int QSPIFBlockDevice::_enable_fast_mode ()
1344
1348
{
1345
- char status_reg[QSPI_MAX_STATUS_REGISTERS] = { 0 } ;
1346
- unsigned int read_conf_register_inst = 0x15 ;
1347
- char status_reg_qer_setup [QSPI_MAX_STATUS_REGISTERS] = {0 };
1349
+ tr_debug ( " enabling fast mode " ) ;
1350
+ MBED_ASSERT (_num_status_registers == 3 ); // Make sure the register for fast mode enable exists
1351
+ uint8_t status_reg [QSPI_MAX_STATUS_REGISTERS] = {0 };
1348
1352
1349
- status_reg_qer_setup[2 ] = 0x2 ; // Bit 1 of config Reg 2
1353
+ // Bit 1 of config reg 2 (aka "status register 3" in our generic register representation)
1354
+ const int QER_REG_IDX = 2 ;
1355
+ const int QER_REG_VALUE = 0x2 ;
1350
1356
1351
1357
// Configure BUS Mode to 1_1_1 for all commands other than Read
1352
1358
if (QSPI_STATUS_OK != _qspi.configure_format (QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
@@ -1356,30 +1362,23 @@ int QSPIFBlockDevice::_enable_fast_mode()
1356
1362
1357
1363
}
1358
1364
1359
- // Read Status Register
1360
- if (QSPI_STATUS_OK == _qspi_send_general_command (read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL , 0 ,
1361
- &status_reg[1 ],
1362
- QSPI_MAX_STATUS_REGISTERS - 1 )) { // store received values in status_value
1363
- tr_debug (" Reading Config Register Success: value = 0x%x" , (int )status_reg[2 ]);
1365
+ if (QSPI_STATUS_OK == _qspi_read_status_registers (status_reg)) {
1366
+ tr_debug (" Reading Config Register Success: value = 0x%x" , status_reg[2 ]);
1364
1367
} else {
1365
1368
tr_error (" Reading Config Register failed" );
1366
1369
return -1 ;
1367
1370
}
1368
1371
1369
1372
// Set Bits for Quad Enable
1370
- for (int i = 0 ; i < QSPI_MAX_STATUS_REGISTERS; i++) {
1371
- status_reg[i] |= status_reg_qer_setup[i];
1372
- }
1373
+ status_reg[QER_REG_IDX] |= QER_REG_VALUE;
1373
1374
1374
1375
// Write new Status Register Setup
1375
1376
if (_set_write_enable () != 0 ) {
1376
- tr_error (" Write Enabe failed" );
1377
+ tr_error (" Write Enable failed" );
1377
1378
return -1 ;
1378
1379
}
1379
1380
1380
- if (QSPI_STATUS_OK == _qspi_send_general_command (QSPIF_INST_WSR1, QSPI_NO_ADDRESS_COMMAND, status_reg,
1381
- QSPI_MAX_STATUS_REGISTERS, NULL ,
1382
- 0 )) { // Write Fast mode bit to status_register
1381
+ if (QSPI_STATUS_OK == _qspi_write_status_registers (status_reg)) {
1383
1382
tr_debug (" fast mode enable - Writing Config Register Success: value = 0x%x" ,
1384
1383
(int )status_reg[2 ]);
1385
1384
} else {
@@ -1394,10 +1393,8 @@ int QSPIFBlockDevice::_enable_fast_mode()
1394
1393
1395
1394
// For Debug
1396
1395
memset (status_reg, 0 , QSPI_MAX_STATUS_REGISTERS);
1397
- if (QSPI_STATUS_OK == _qspi_send_general_command (read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL , 0 ,
1398
- &status_reg[1 ],
1399
- QSPI_MAX_STATUS_REGISTERS - 1 )) { // store received values in status_value
1400
- tr_debug (" Verifying Config Register Success: value = 0x%x" , (int )status_reg[2 ]);
1396
+ if (QSPI_STATUS_OK == _qspi_read_status_registers (status_reg)) {
1397
+ tr_debug (" Verifying Register Success: status = 0x%x config 1 = 0x%x config 2 = 0x%x" , (int )status_reg[0 ], (int )status_reg[1 ], (int )status_reg[2 ]);
1401
1398
} else {
1402
1399
tr_error (" Verifying Config Register failed" );
1403
1400
return -1 ;
0 commit comments