@@ -178,6 +178,8 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
178
178
_write_status_reg_2_inst = QSPIF_INST_WSR2_DEFAULT;
179
179
_read_status_reg_2_inst = QSPIF_INST_RSR2_DEFAULT;
180
180
181
+ _clear_protection_method = QSPIF_BP_CLEAR_SR;
182
+
181
183
// Set default 4-byte addressing extension register write instruction
182
184
_4byte_msb_reg_write_inst = QSPIF_INST_4BYTE_REG_WRITE_DEFAULT;
183
185
}
@@ -235,6 +237,12 @@ int QSPIFBlockDevice::init()
235
237
goto exit_point;
236
238
}
237
239
240
+ if (0 != _handle_vendor_quirks ()) {
241
+ tr_error (" Init - Could not read vendor id" );
242
+ status = QSPIF_BD_ERROR_DEVICE_ERROR;
243
+ goto exit_point;
244
+ }
245
+
238
246
/* *************************** Parse SFDP Header ***********************************/
239
247
if (0 != _sfdp_parse_sfdp_headers (basic_table_addr, basic_table_size, sector_map_table_addr, sector_map_table_size)) {
240
248
tr_error (" Init - Parse SFDP Headers Failed" );
@@ -1204,16 +1212,9 @@ int QSPIFBlockDevice::_sfdp_parse_sector_map_table(uint32_t sector_map_table_add
1204
1212
return 0 ;
1205
1213
}
1206
1214
1207
- int QSPIFBlockDevice::_clear_block_protection ()
1215
+ int QSPIFBlockDevice::_handle_vendor_quirks ()
1208
1216
{
1209
1217
uint8_t vendor_device_ids[QSPI_RDID_DATA_LENGTH] = {0 };
1210
- uint8_t status_regs[QSPI_STATUS_REGISTER_COUNT] = {0 };
1211
-
1212
- if (false == _is_mem_ready ()) {
1213
- tr_error (" Device not ready, clearing block protection failed" );
1214
- return -1 ;
1215
- }
1216
-
1217
1218
/* Read Manufacturer ID (1byte), and Device ID (2bytes) */
1218
1219
qspi_status_t status = _qspi_send_general_command (QSPIF_INST_RDID, QSPI_NO_ADDRESS_COMMAND,
1219
1220
NULL , 0 ,
@@ -1224,8 +1225,31 @@ int QSPIFBlockDevice::_clear_block_protection()
1224
1225
}
1225
1226
1226
1227
tr_debug (" Vendor device ID = 0x%x 0x%x 0x%x" , vendor_device_ids[0 ], vendor_device_ids[1 ], vendor_device_ids[2 ]);
1228
+
1227
1229
switch (vendor_device_ids[0 ]) {
1228
1230
case 0xbf :
1231
+ // SST devices come preset with block protection
1232
+ // enabled for some regions, issue global protection unlock to clear
1233
+ tr_debug (" Applying quirks for SST" );
1234
+ _clear_protection_method = QSPIF_BP_ULBPR;
1235
+ break ;
1236
+ }
1237
+
1238
+ return 0 ;
1239
+ }
1240
+
1241
+ int QSPIFBlockDevice::_clear_block_protection ()
1242
+ {
1243
+ uint8_t status_regs[QSPI_STATUS_REGISTER_COUNT] = {0 };
1244
+
1245
+ if (false == _is_mem_ready ()) {
1246
+ tr_error (" Device not ready, clearing block protection failed" );
1247
+ return -1 ;
1248
+ }
1249
+ qspi_status_t status;
1250
+ switch (_clear_protection_method) {
1251
+ case QSPIF_BP_ULBPR:
1252
+ tr_debug (" Clearing block protection via ULBPR" );
1229
1253
// SST devices come preset with block protection
1230
1254
// enabled for some regions, issue global protection unlock to clear
1231
1255
if (0 != _set_write_enable ()) {
@@ -1238,9 +1262,10 @@ int QSPIFBlockDevice::_clear_block_protection()
1238
1262
return -1 ;
1239
1263
}
1240
1264
break ;
1241
- default :
1265
+ case QSPIF_BP_CLEAR_SR :
1242
1266
// For all other devices, to clear the block protection bits clear all bits
1243
1267
// in status register 1 that aren't the WIP or WEL bits, or the QE bit (if it is in SR 1)
1268
+ tr_debug (" Clearing block protection via status register protection bits" );
1244
1269
status = _qspi_read_status_registers (status_regs);
1245
1270
if (QSPI_STATUS_OK != status) {
1246
1271
tr_error (" _clear_block_protection - Status register read failed" );
0 commit comments