Skip to content

Commit 2526b9f

Browse files
author
Kyle Kearney
committed
QSPIF: Handle fast mode enable via vendor quirks
Use a vendor id check to only perform this enable on devices which define the second configuration register where the fast mode enable bit lives. Change _enable_fast_mode to use the standard status register reading and writing functions
1 parent 02dbf68 commit 2526b9f

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
165165
// Until proven otherwise, assume no quad enable
166166
_quad_enable_register_idx = QSPIF_NO_QUAD_ENABLE;
167167
_quad_enable_bit = QSPIF_NO_QUAD_ENABLE;
168+
_needs_fast_mode = false;
168169

169170
// Default Bus Setup 1_1_1 with 0 dummy and mode cycles
170171
_inst_width = QSPI_CFG_BUS_SINGLE;
@@ -734,7 +735,9 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
734735
// Detect and Set fastest Bus mode (default 1-1-1)
735736
_sfdp_detect_best_bus_read_mode(param_table, basic_table_size, shouldSetQuadEnable, is_qpi_mode);
736737
if (true == shouldSetQuadEnable) {
737-
_enable_fast_mode();
738+
if (_needs_fast_mode) {
739+
_enable_fast_mode();
740+
}
738741
// Set Quad Enable and QPI Bus modes if Supported
739742
tr_debug("Init - Setting Quad Enable");
740743
if (0 != _sfdp_set_quad_enabled(param_table)) {
@@ -1243,6 +1246,7 @@ int QSPIFBlockDevice::_handle_vendor_quirks()
12431246
// 1. Have one status register and 2 config registers, with a nonstandard instruction for reading the config registers
12441247
// 2. Require setting a "fast mode" bit in config register 2 to operate at higher clock rates
12451248
tr_debug("Applying quirks for macronix");
1249+
_needs_fast_mode = true;
12461250
_num_status_registers = 3;
12471251
_read_status_reg_2_inst = QSPIF_INST_RDCR;
12481252
break;
@@ -1342,11 +1346,13 @@ int QSPIFBlockDevice::_set_write_enable()
13421346

13431347
int QSPIFBlockDevice::_enable_fast_mode()
13441348
{
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};
13481352

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;
13501356

13511357
// Configure BUS Mode to 1_1_1 for all commands other than Read
13521358
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()
13561362

13571363
}
13581364

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]);
13641367
} else {
13651368
tr_error("Reading Config Register failed");
13661369
return -1;
13671370
}
13681371

13691372
// 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;
13731374

13741375
// Write new Status Register Setup
13751376
if (_set_write_enable() != 0) {
1376-
tr_error("Write Enabe failed");
1377+
tr_error("Write Enable failed");
13771378
return -1;
13781379
}
13791380

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)) {
13831382
tr_debug("fast mode enable - Writing Config Register Success: value = 0x%x",
13841383
(int)status_reg[2]);
13851384
} else {
@@ -1394,10 +1393,8 @@ int QSPIFBlockDevice::_enable_fast_mode()
13941393

13951394
// For Debug
13961395
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]);
14011398
} else {
14021399
tr_error("Verifying Config Register failed");
14031400
return -1;

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
369369
int _quad_enable_register_idx;
370370
int _quad_enable_bit;
371371

372+
bool _needs_fast_mode;
373+
372374
// Clear block protection
373375
qspif_clear_protection_method_t _clear_protection_method;
374376

0 commit comments

Comments
 (0)