Skip to content

Commit b6b8ffb

Browse files
Kyle Kearneyadbridge
authored andcommitted
Don't clear quad enable when clearing block protection
QSPIFBlockDevice::_clear_block_protection() has logic to retain the WIP and WEL bits in status register 1, but it failed to account for the situation where the QE bit is also in status register 1. In _sfdp_set_quad_enabled, note the status register and bit therein for the quad enable, so that _clear_block_protection can retain it.
1 parent 96bb654 commit b6b8ffb

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ using namespace mbed;
4040
// Status Register Bits
4141
#define QSPIF_STATUS_BIT_WIP 0x1 // Write In Progress
4242
#define QSPIF_STATUS_BIT_WEL 0x2 // Write Enable Latch
43+
#define QSPIF_NO_QUAD_ENABLE (-1)
4344

4445
/* SFDP Header Parsing */
4546
/***********************/
@@ -157,6 +158,10 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
157158
_regions_count = 1;
158159
_region_erase_types_bitfield[0] = ERASE_BITMASK_NONE;
159160

161+
// Until proven otherwise, assume no quad enable
162+
_quad_enable_register_idx = QSPIF_NO_QUAD_ENABLE;
163+
_quad_enable_bit = QSPIF_NO_QUAD_ENABLE;
164+
160165
// Default Bus Setup 1_1_1 with 0 dummy and mode cycles
161166
_inst_width = QSPI_CFG_BUS_SINGLE;
162167
_address_width = QSPI_CFG_BUS_SINGLE;
@@ -756,28 +761,40 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
756761
return 0;
757762
case 1:
758763
case 4:
759-
status_reg_setup[1] = 1 << 1; // Bit 1 of Status Reg 2
764+
// Bit 1 of Status Reg 2
765+
_quad_enable_register_idx = 1;
766+
_quad_enable_bit = 1;
760767
tr_debug("Setting QE Bit, Bit 1 of Status Reg 2");
761768
break;
762769
case 2:
763-
status_reg_setup[0] = 1 << 6; // Bit 6 of Status Reg 1
770+
// Bit 6 of Status Reg 1
771+
_quad_enable_register_idx = 0;
772+
_quad_enable_bit = 6;
764773
tr_debug("Setting QE Bit, Bit 6 of Status Reg 1");
765774
break;
766775
case 3:
767-
status_reg_setup[0] = 1 << 7; // Bit 7 of Status Reg 1
776+
// Bit 7 of Status Reg 1
777+
_quad_enable_register_idx = 0;
778+
_quad_enable_bit = 7;
768779
_write_status_reg_2_inst = 0x3E;
769780
_read_status_reg_2_inst = 0x3F;
770781
tr_debug("Setting QE Bit, Bit 7 of Status Reg 1");
771782
break;
772783
case 5:
773-
status_reg_setup[1] = 1 << 1; // Bit 1 of status Reg 2
784+
// Bit 1 of status Reg 2
785+
_quad_enable_register_idx = 1;
786+
_quad_enable_bit = 1;
774787
tr_debug("Setting QE Bit, Bit 1 of Status Reg 2");
775788
break;
776789
default:
777790
tr_warning("Unsupported QER configuration");
778791
return 0;
779792
}
780793

794+
if (_quad_enable_register_idx != QSPIF_NO_QUAD_ENABLE && _quad_enable_bit != QSPIF_NO_QUAD_ENABLE) {
795+
status_reg_setup[_quad_enable_register_idx] = 1 << _quad_enable_bit;
796+
}
797+
781798
// Read existing status register values
782799
_qspi_read_status_registers(status_regs);
783800

@@ -1222,13 +1239,18 @@ int QSPIFBlockDevice::_clear_block_protection()
12221239
}
12231240
break;
12241241
default:
1225-
// For all other devices, clear all bits in status register 1 that aren't the WIP or WEL bits to clear the block protection bits
1242+
// For all other devices, to clear the block protection bits clear all bits
1243+
// in status register 1 that aren't the WIP or WEL bits, or the QE bit (if it is in SR 1)
12261244
status = _qspi_read_status_registers(status_regs);
12271245
if (QSPI_STATUS_OK != status) {
12281246
tr_error("_clear_block_protection - Status register read failed");
12291247
return -1;
12301248
}
1231-
status_regs[0] &= (QSPIF_STATUS_BIT_WIP | QSPIF_STATUS_BIT_WEL);
1249+
uint8_t status_mask = (QSPIF_STATUS_BIT_WIP | QSPIF_STATUS_BIT_WEL);
1250+
if (_quad_enable_register_idx == 0) {
1251+
status_mask |= 1 << _quad_enable_bit;
1252+
}
1253+
status_regs[0] &= status_mask;
12321254
status = _qspi_write_status_registers(status_regs);
12331255
if (QSPI_STATUS_OK != status) {
12341256
tr_error("__clear_block_protection - Status register write failed");

components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
356356
mbed::qspi_inst_t _erase_type_inst_arr[MAX_NUM_OF_ERASE_TYPES];
357357
unsigned int _erase_type_size_arr[MAX_NUM_OF_ERASE_TYPES];
358358

359+
// Quad mode enable status register and bit
360+
int _quad_enable_register_idx;
361+
int _quad_enable_bit;
362+
359363
// Sector Regions Map
360364
int _regions_count; //number of regions
361365
int _region_size_bytes[QSPIF_MAX_REGIONS]; //regions size in bytes

0 commit comments

Comments
 (0)