Skip to content

Commit 4785e83

Browse files
Matthew MacovskyKyle Kearney
authored andcommitted
Update flash device reset to conform to SFDP standard
1 parent cd78bf9 commit 4785e83

File tree

2 files changed

+48
-54
lines changed

2 files changed

+48
-54
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ using namespace mbed;
7373
#define QSPIF_BASIC_PARAM_ERASE_TYPE_4_SIZE_BYTE 34
7474
#define QSPIF_BASIC_PARAM_4K_ERASE_TYPE_BYTE 1
7575

76+
#define QSPIF_BASIC_PARAM_TABLE_SOFT_RESET_BYTE 61
77+
78+
#define SOFT_RESET_RESET_INST_BITMASK 0b001000
79+
#define SOFT_RESET_ENABLE_AND_RESET_INST_BITMASK 0b010000
80+
7681
// Erase Types Per Region BitMask
7782
#define ERASE_BITMASK_TYPE4 0x08
7883
#define ERASE_BITMASK_TYPE1 0x01
@@ -190,15 +195,6 @@ int QSPIFBlockDevice::init()
190195
goto exit_point;
191196
}
192197

193-
// Soft Reset
194-
if (-1 == _reset_flash_mem()) {
195-
tr_error("Init - Unable to initialize flash memory, tests failed");
196-
status = QSPIF_BD_ERROR_DEVICE_ERROR;
197-
goto exit_point;
198-
} else {
199-
tr_debug("Initialize flash memory OK");
200-
}
201-
202198
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
203199
qspi_status = _qspi_send_general_command(QSPIF_RDID, QSPI_NO_ADDRESS_COMMAND, NULL, 0, (char *)vendor_device_ids,
204200
data_length);
@@ -722,6 +718,11 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
722718
// Set Page Size (QSPI write must be done on Page limits)
723719
_page_size_bytes = _sfdp_detect_page_size(param_table, basic_table_size);
724720

721+
if (_sfdp_detect_reset_protocol_and_reset(param_table) != QSPIF_BD_ERROR_OK) {
722+
tr_error("Init - Detecting reset protocol/resetting failed");
723+
return -1;
724+
}
725+
725726
// Detect and Set Erase Types
726727
bool shouldSetQuadEnable = false;
727728
bool is_qpi_mode = false;
@@ -1032,6 +1033,41 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
10321033
return 0;
10331034
}
10341035

1036+
int QSPIFBlockDevice::_sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr)
1037+
{
1038+
int status = QSPIF_BD_ERROR_OK;
1039+
uint8_t examined_byte = basic_param_table_ptr[QSPIF_BASIC_PARAM_TABLE_SOFT_RESET_BYTE];
1040+
1041+
// Ignore bit indicating need to exit 0-4-4 mode - should not enter 0-4-4 mode from QSPIFBlockDevice
1042+
if (examined_byte & SOFT_RESET_RESET_INST_BITMASK) {
1043+
// Issue instruction 0xF0 to reset the device
1044+
qspi_status_t qspi_status = _qspi_send_general_command(0xF0, QSPI_NO_ADDRESS_COMMAND, // Send reset instruction
1045+
NULL, 0, NULL, 0);
1046+
status = (qspi_status == QSPI_STATUS_OK) ? QSPIF_BD_ERROR_OK : QSPIF_BD_ERROR_PARSING_FAILED;
1047+
} else if (examined_byte & SOFT_RESET_ENABLE_AND_RESET_INST_BITMASK) {
1048+
// Issue instruction 66h to enable resets on the device
1049+
// Then issue instruction 99h to reset the device
1050+
qspi_status_t qspi_status = _qspi_send_general_command(0x66, QSPI_NO_ADDRESS_COMMAND, // Send reset enable instruction
1051+
NULL, 0, NULL, 0);
1052+
if (qspi_status == QSPI_STATUS_OK) {
1053+
qspi_status = _qspi_send_general_command(0x99, QSPI_NO_ADDRESS_COMMAND, // Send reset instruction
1054+
NULL, 0, NULL, 0);
1055+
}
1056+
status = (qspi_status == QSPI_STATUS_OK) ? QSPIF_BD_ERROR_OK : QSPIF_BD_ERROR_PARSING_FAILED;
1057+
} else {
1058+
// Soft reset either is not supported or requires direct control over data lines
1059+
status = QSPIF_BD_ERROR_PARSING_FAILED;
1060+
}
1061+
1062+
if (status == QSPIF_BD_ERROR_OK){
1063+
if (false == _is_mem_ready()) {
1064+
tr_error("Device not ready, reset failed");
1065+
status = QSPIF_BD_ERROR_READY_FAILED;
1066+
}
1067+
}
1068+
1069+
return status;
1070+
}
10351071

10361072
int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_addr, size_t sector_map_table_size)
10371073
{
@@ -1092,49 +1128,6 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
10921128
return 0;
10931129
}
10941130

1095-
int QSPIFBlockDevice::_reset_flash_mem()
1096-
{
1097-
// Perform Soft Reset of the Device prior to initialization
1098-
int status = 0;
1099-
uint8_t status_value = 0;
1100-
tr_debug("_reset_flash_mem:");
1101-
//Read the Status Register from device
1102-
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_INST_RSR1, QSPI_NO_ADDRESS_COMMAND, NULL, 0, (char *) &status_value,
1103-
1)) { // store received values in status_value
1104-
tr_debug("Reading Status Register Success: value = 0x%x", status_value);
1105-
} else {
1106-
tr_error("Reading Status Register failed: value = 0x%x", status_value);
1107-
status = -1;
1108-
}
1109-
1110-
if (0 == status) {
1111-
//Send Reset Enable
1112-
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RSTEN, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL,
1113-
0)) { // store received values in status_value
1114-
tr_debug("Sending RSTEN Success");
1115-
} else {
1116-
tr_error("Sending RSTEN failed");
1117-
status = -1;
1118-
}
1119-
1120-
1121-
if (0 == status) {
1122-
//Send Reset
1123-
if (QSPI_STATUS_OK == _qspi_send_general_command(QSPIF_RST, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL,
1124-
0)) { // store received values in status_value
1125-
tr_debug("Sending RST Success");
1126-
} else {
1127-
tr_error("Sending RST failed");
1128-
status = -1;
1129-
}
1130-
1131-
_is_mem_ready();
1132-
}
1133-
}
1134-
1135-
return status;
1136-
}
1137-
11381131
int QSPIFBlockDevice::_set_write_enable()
11391132
{
11401133
// Check Status Register Busy Bit to Verify the Device isn't Busy

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
265265
/*********************************/
266266
/* Flash Configuration Functions */
267267
/*********************************/
268-
// Soft Reset Flash Memory
269-
int _reset_flash_mem();
270268

271269
// Configure Write Enable in Status Register
272270
int _set_write_enable();
@@ -287,6 +285,9 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
287285
// Parse and read information required by Regions Secotr Map
288286
int _sfdp_parse_sector_map_table(uint32_t sector_map_table_addr, size_t sector_map_table_size);
289287

288+
// Detect the soft reset protocol and reset - returns error if soft reset is not supported
289+
int _sfdp_detect_reset_protocol_and_reset(uint8_t *basic_param_table_ptr);
290+
290291
// Detect fastest read Bus mode supported by device
291292
int _sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_ptr, int basic_param_table_size, bool &set_quad_enable,
292293
bool &is_qpi_mode, mbed::qspi_inst_t &read_inst);

0 commit comments

Comments
 (0)