@@ -73,6 +73,11 @@ using namespace mbed;
73
73
#define QSPIF_BASIC_PARAM_ERASE_TYPE_4_SIZE_BYTE 34
74
74
#define QSPIF_BASIC_PARAM_4K_ERASE_TYPE_BYTE 1
75
75
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
+
76
81
// Erase Types Per Region BitMask
77
82
#define ERASE_BITMASK_TYPE4 0x08
78
83
#define ERASE_BITMASK_TYPE1 0x01
@@ -190,15 +195,6 @@ int QSPIFBlockDevice::init()
190
195
goto exit_point;
191
196
}
192
197
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
-
202
198
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
203
199
qspi_status = _qspi_send_general_command (QSPIF_RDID, QSPI_NO_ADDRESS_COMMAND, NULL , 0 , (char *)vendor_device_ids,
204
200
data_length);
@@ -722,6 +718,11 @@ int QSPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, s
722
718
// Set Page Size (QSPI write must be done on Page limits)
723
719
_page_size_bytes = _sfdp_detect_page_size (param_table, basic_table_size);
724
720
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
+
725
726
// Detect and Set Erase Types
726
727
bool shouldSetQuadEnable = false ;
727
728
bool is_qpi_mode = false ;
@@ -1032,6 +1033,41 @@ int QSPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table
1032
1033
return 0 ;
1033
1034
}
1034
1035
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
+ }
1035
1071
1036
1072
int QSPIFBlockDevice::_sfdp_parse_sector_map_table (uint32_t sector_map_table_addr, size_t sector_map_table_size)
1037
1073
{
@@ -1092,49 +1128,6 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
1092
1128
return 0 ;
1093
1129
}
1094
1130
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
-
1138
1131
int QSPIFBlockDevice::_set_write_enable ()
1139
1132
{
1140
1133
// Check Status Register Busy Bit to Verify the Device isn't Busy
0 commit comments