@@ -40,6 +40,7 @@ using namespace mbed;
40
40
// Status Register Bits
41
41
#define QSPIF_STATUS_BIT_WIP 0x1 // Write In Progress
42
42
#define QSPIF_STATUS_BIT_WEL 0x2 // Write Enable Latch
43
+ #define QSPIF_NO_QUAD_ENABLE (-1 )
43
44
44
45
/* SFDP Header Parsing */
45
46
/* **********************/
@@ -157,6 +158,10 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
157
158
_regions_count = 1 ;
158
159
_region_erase_types_bitfield[0 ] = ERASE_BITMASK_NONE;
159
160
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
+
160
165
// Default Bus Setup 1_1_1 with 0 dummy and mode cycles
161
166
_inst_width = QSPI_CFG_BUS_SINGLE;
162
167
_address_width = QSPI_CFG_BUS_SINGLE;
@@ -756,28 +761,40 @@ int QSPIFBlockDevice::_sfdp_set_quad_enabled(uint8_t *basic_param_table_ptr)
756
761
return 0 ;
757
762
case 1 :
758
763
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 ;
760
767
tr_debug (" Setting QE Bit, Bit 1 of Status Reg 2" );
761
768
break ;
762
769
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 ;
764
773
tr_debug (" Setting QE Bit, Bit 6 of Status Reg 1" );
765
774
break ;
766
775
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 ;
768
779
_write_status_reg_2_inst = 0x3E ;
769
780
_read_status_reg_2_inst = 0x3F ;
770
781
tr_debug (" Setting QE Bit, Bit 7 of Status Reg 1" );
771
782
break ;
772
783
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 ;
774
787
tr_debug (" Setting QE Bit, Bit 1 of Status Reg 2" );
775
788
break ;
776
789
default :
777
790
tr_warning (" Unsupported QER configuration" );
778
791
return 0 ;
779
792
}
780
793
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
+
781
798
// Read existing status register values
782
799
_qspi_read_status_registers (status_regs);
783
800
@@ -1222,13 +1239,18 @@ int QSPIFBlockDevice::_clear_block_protection()
1222
1239
}
1223
1240
break ;
1224
1241
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)
1226
1244
status = _qspi_read_status_registers (status_regs);
1227
1245
if (QSPI_STATUS_OK != status) {
1228
1246
tr_error (" _clear_block_protection - Status register read failed" );
1229
1247
return -1 ;
1230
1248
}
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;
1232
1254
status = _qspi_write_status_registers (status_regs);
1233
1255
if (QSPI_STATUS_OK != status) {
1234
1256
tr_error (" __clear_block_protection - Status register write failed" );
0 commit comments