Skip to content

Commit 9b3bca8

Browse files
author
Offir Kochalsky
committed
Enable first fast mode then quad for chips with low power default
1 parent dc45579 commit 9b3bca8

File tree

3 files changed

+78
-9
lines changed

3 files changed

+78
-9
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ using namespace mbed;
3333
#define QSPIF_DEFAULT_PROG_SIZE 1
3434
#define QSPIF_DEFAULT_PAGE_SIZE 256
3535
#define QSPIF_DEFAULT_SE_SIZE 4096
36-
#define QSPI_MAX_STATUS_REGISTER_SIZE 2
36+
#define QSPI_MAX_STATUS_REGISTER_SIZE 3
3737
#ifndef UINT64_MAX
3838
#define UINT64_MAX -1
3939
#endif
@@ -171,6 +171,9 @@ int QSPIFBlockDevice::init()
171171
_address_size = QSPI_CFG_ADDR_SIZE_24;
172172
_data_width = QSPI_CFG_BUS_SINGLE;
173173
_dummy_and_mode_cycles = 0;
174+
_write_register_inst = QSPIF_WRSR;
175+
_read_register_inst = QSPIF_RDSR;
176+
174177

175178
if (QSPI_STATUS_OK != _qspi_set_frequency(_freq)) {
176179
tr_error("QSPI Set Frequency Failed");
@@ -681,6 +684,7 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
681684
// Detect and Set fastest Bus mode (default 1-1-1)
682685
_sfdp_detect_best_bus_read_mode(param_table, basic_table_size, shouldSetQuadEnable, is_qpi_mode, _read_instruction);
683686
if (true == shouldSetQuadEnable) {
687+
_enable_fast_mdoe();
684688
// Set Quad Enable and QPI Bus modes if Supported
685689
tr_info("Init - Setting Quad Enable");
686690
if (0 != _sfdp_set_quad_enabled(param_table)) {
@@ -817,8 +821,6 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
817821

818822
char status_reg_setup[QSPI_MAX_STATUS_REGISTER_SIZE] = {0};
819823
char status_reg[QSPI_MAX_STATUS_REGISTER_SIZE] = {0};
820-
unsigned int write_register_inst = QSPIF_WRSR;
821-
unsigned int read_register_inst = QSPIF_RDSR;
822824

823825
// QUAD Enable procedure is specified by 3 bits
824826
uint8_t qer_value = (basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_QER_BYTE] & 0x70) >> 4;
@@ -844,13 +846,13 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
844846
case 3:
845847
status_reg_setup[0] = 0x80; // Bit 7 of Status Reg 1
846848
sr_write_size = 1;
847-
write_register_inst = 0x3E;
848-
read_register_inst = 0x3F;
849+
_write_register_inst = 0x3E;
850+
_read_register_inst = 0x3F;
849851
tr_debug("Setting QE Bit, Bit 7 of Status Reg 1");
850852
break;
851853
case 5:
852854
status_reg_setup[1] = 0x2; // Bit 1 of status Reg 2
853-
read_register_inst = 0x35;
855+
_read_register_inst = 0x35;
854856
sr_read_size = 1;
855857
tr_debug("Setting QE Bit, Bit 1 of Status Reg 2 -special read command");
856858
break;
@@ -864,7 +866,7 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
864866
QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0);
865867

866868
// Read Status Register
867-
if (QSPI_STATUS_OK == _qspi_send_general_command(read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
869+
if (QSPI_STATUS_OK == _qspi_send_general_command(_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
868870
status_reg,
869871
sr_read_size) ) { // store received values in status_value
870872
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_reg[0]);
@@ -884,7 +886,7 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
884886
return -1;
885887
}
886888

887-
if (QSPI_STATUS_OK == _qspi_send_general_command(write_register_inst, QSPI_NO_ADDRESS_COMMAND, (char *)status_reg,
889+
if (QSPI_STATUS_OK == _qspi_send_general_command(_write_register_inst, QSPI_NO_ADDRESS_COMMAND, (char *)status_reg,
888890
sr_write_size, NULL,
889891
0) ) { // Write QE to status_register
890892
tr_debug("_setQuadEnable - Writing Status Register Success: value = 0x%x",
@@ -902,7 +904,7 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
902904

903905
// For Debug
904906
memset(status_reg, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
905-
if (QSPI_STATUS_OK == _qspi_send_general_command(read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
907+
if (QSPI_STATUS_OK == _qspi_send_general_command(_read_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
906908
(char *)status_reg,
907909
sr_read_size) ) { // store received values in status_value
908910
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_reg[0]);
@@ -1175,6 +1177,68 @@ int QSPIFBlockDevice::_set_write_enable()
11751177
return status;
11761178
}
11771179

1180+
int QSPIFBlockDevice::_enable_fast_mdoe()
1181+
{
1182+
char status_reg[QSPI_MAX_STATUS_REGISTER_SIZE] = {0};
1183+
unsigned int read_conf_register_inst = 0x15;
1184+
char status_reg_qer_setup[QSPI_MAX_STATUS_REGISTER_SIZE] = {0};
1185+
1186+
status_reg_qer_setup[2] = 0x2; // Bit 1 of config Reg 2
1187+
1188+
// Configure BUS Mode to 1_1_1 for all commands other than Read
1189+
_qspi_configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_ADDR_SIZE_24, QSPI_CFG_BUS_SINGLE,
1190+
QSPI_CFG_ALT_SIZE_8, QSPI_CFG_BUS_SINGLE, 0);
1191+
1192+
// Read Status Register
1193+
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
1194+
&status_reg[1],
1195+
QSPI_MAX_STATUS_REGISTER_SIZE - 1) ) { // store received values in status_value
1196+
tr_debug("Reading Config Register Success: value = 0x%x", (int)status_reg[2]);
1197+
} else {
1198+
tr_error("Reading Config Register failed");
1199+
return -1;
1200+
}
1201+
1202+
// Set Bits for Quad Enable
1203+
for (int i = 0; i < QSPI_MAX_STATUS_REGISTER_SIZE; i++) {
1204+
status_reg[i] |= status_reg_qer_setup[i];
1205+
}
1206+
1207+
// Write new Status Register Setup
1208+
if (_set_write_enable() != 0) {
1209+
tr_error("Write Enabe failed");
1210+
return -1;
1211+
}
1212+
1213+
if (QSPI_STATUS_OK == _qspi_send_general_command(_write_register_inst, QSPI_NO_ADDRESS_COMMAND, status_reg,
1214+
QSPI_MAX_STATUS_REGISTER_SIZE, NULL,
1215+
0) ) { // Write Fast mode bit to status_register
1216+
tr_debug("fast mode enable - Writing Config Register Success: value = 0x%x",
1217+
(int)status_reg[2]);
1218+
} else {
1219+
tr_error("fast mode enable - Writing Config Register failed");
1220+
return -1;
1221+
}
1222+
1223+
if ( false == _is_mem_ready()) {
1224+
tr_error("Device not ready after write, failed");
1225+
return -1;
1226+
}
1227+
1228+
// For Debug
1229+
memset(status_reg, 0, QSPI_MAX_STATUS_REGISTER_SIZE);
1230+
if (QSPI_STATUS_OK == _qspi_send_general_command(read_conf_register_inst, QSPI_NO_ADDRESS_COMMAND, NULL, 0,
1231+
&status_reg[1],
1232+
QSPI_MAX_STATUS_REGISTER_SIZE - 1) ) { // store received values in status_value
1233+
tr_debug("Verifying Config Register Success: value = 0x%x", (int)status_reg[2]);
1234+
} else {
1235+
tr_error("Verifying Config Register failed");
1236+
return -1;
1237+
}
1238+
1239+
return 0;
1240+
}
1241+
11781242
/*********************************************/
11791243
/************* Utility Functions *************/
11801244
/*********************************************/

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ class QSPIFBlockDevice : public BlockDevice {
250250
// Wait on status register until write not-in-progress
251251
bool _is_mem_ready();
252252

253+
// Enable Fast Mode - for flash chips with low power default
254+
int _enable_fast_mdoe();
253255

254256
/* SFDP Detection and Parsing Functions */
255257
/****************************************/
@@ -315,6 +317,8 @@ class QSPIFBlockDevice : public BlockDevice {
315317
unsigned int _prog_instruction;
316318
unsigned int _erase_instruction;
317319
unsigned int _erase4k_inst; // Legacy 4K erase instruction (default 0x20h)
320+
unsigned int _write_register_inst; // Write status/config register instruction may vary between chips
321+
unsigned int _read_register_inst; // Read status/config register instruction may vary between chips
318322

319323
// Up To 4 Erase Types are supported by SFDP (each with its own command Instruction and Size)
320324
unsigned int _erase_type_inst_arr[MAX_NUM_OF_ERASE_TYPES];

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,7 @@
20372037
}
20382038
},
20392039
"DISCO_L475VG_IOT01A": {
2040+
"components": ["QSPIF"],
20402041
"inherits": ["FAMILY_STM32"],
20412042
"core": "Cortex-M4F",
20422043
"extra_labels_add": ["STM32L4", "STM32L475xG", "STM32L475VG"],

0 commit comments

Comments
 (0)