Skip to content

Commit 96bb654

Browse files
Kyle Kearneyadbridge
authored andcommitted
QSPIF: Add back enable_fast_mode
This function writes a "config" register to ensure that the flash part is in high performance mode, not low-power mode. This is required at by at least MX25R6435F in order to operate at frequencies > 33MHz (for reference, DISCO_L475VG_IOT01A runs the QSPI interface at 80 MHz). The config register that this writes does not appear to be covered by the SFDP spec (JESD216D.01) so this remains the status quo of unconditional execution, as has been done on master since #8352.
1 parent 8c82524 commit 96bb654

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
716716
// Detect and Set fastest Bus mode (default 1-1-1)
717717
_sfdp_detect_best_bus_read_mode(param_table, basic_table_size, shouldSetQuadEnable, is_qpi_mode);
718718
if (true == shouldSetQuadEnable) {
719+
_enable_fast_mode();
719720
// Set Quad Enable and QPI Bus modes if Supported
720721
tr_debug("Init - Setting Quad Enable");
721722
if (0 != _sfdp_set_quad_enabled(param_table)) {
@@ -1279,6 +1280,73 @@ int QSPIFBlockDevice::_set_write_enable()
12791280
return status;
12801281
}
12811282

1283+
int QSPIFBlockDevice::_enable_fast_mode()
1284+
{
1285+
const int NUM_REGISTERS = QSPI_STATUS_REGISTER_COUNT + 1; // Status registers + one config register
1286+
char status_reg[NUM_REGISTERS] = {0};
1287+
unsigned int read_conf_register_inst = 0x15;
1288+
char status_reg_qer_setup[NUM_REGISTERS] = {0};
1289+
1290+
status_reg_qer_setup[2] = 0x2; // Bit 1 of config Reg 2
1291+
1292+
// Configure BUS Mode to 1_1_1 for all commands other than Read
1293+
if (QSPI_STATUS_OK != _qspi.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
1294+
0, QSPI_CFG_BUS_SINGLE, 0)) {
1295+
tr_error("_qspi_configure_format failed");
1296+
return -1;
1297+
1298+
}
1299+
1300+
// Read Status Register
1301+
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
1302+
&status_reg[1],
1303+
NUM_REGISTERS - 1)) { // store received values in status_value
1304+
tr_debug("Reading Config Register Success: value = 0x%x", (int)status_reg[2]);
1305+
} else {
1306+
tr_error("Reading Config Register failed");
1307+
return -1;
1308+
}
1309+
1310+
// Set Bits for Quad Enable
1311+
for (int i = 0; i < NUM_REGISTERS; i++) {
1312+
status_reg[i] |= status_reg_qer_setup[i];
1313+
}
1314+
1315+
// Write new Status Register Setup
1316+
if (_set_write_enable() != 0) {
1317+
tr_error("Write Enabe failed");
1318+
return -1;
1319+
}
1320+
1321+
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_INST_WSR1, QSPI_NO_ADDRESS_COMMAND, status_reg,
1322+
NUM_REGISTERS, NULL,
1323+
0)) { // Write Fast mode bit to status_register
1324+
tr_debug("fast mode enable - Writing Config Register Success: value = 0x%x",
1325+
(int)status_reg[2]);
1326+
} else {
1327+
tr_error("fast mode enable - Writing Config Register failed");
1328+
return -1;
1329+
}
1330+
1331+
if (false == _is_mem_ready()) {
1332+
tr_error("Device not ready after write, failed");
1333+
return -1;
1334+
}
1335+
1336+
// For Debug
1337+
memset(status_reg, 0, NUM_REGISTERS);
1338+
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
1339+
&status_reg[1],
1340+
NUM_REGISTERS - 1)) { // store received values in status_value
1341+
tr_debug("Verifying Config Register Success: value = 0x%x", (int)status_reg[2]);
1342+
} else {
1343+
tr_error("Verifying Config Register failed");
1344+
return -1;
1345+
}
1346+
1347+
return 0;
1348+
}
1349+
12821350
bool QSPIFBlockDevice::_is_mem_ready()
12831351
{
12841352
// Check Status Register Busy Bit to Verify the Device isn't Busy

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
275275
// Wait on status register until write not-in-progress
276276
bool _is_mem_ready();
277277

278+
// Enable Fast Mode - for flash chips with low power default
279+
int _enable_fast_mode();
280+
278281
/****************************************/
279282
/* SFDP Detection and Parsing Functions */
280283
/****************************************/

0 commit comments

Comments
 (0)