@@ -58,7 +58,7 @@ void QspiCommand::set_dummy_cycles(int dummy_cycles)
5858
5959void QspiCommand::build (int instruction, int address, int alt)
6060{
61- _cmd.instruction .disabled = (instruction == QSPI_NONE );
61+ _cmd.instruction .disabled = (instruction == QSPI_NO_INST );
6262 if (!_cmd.instruction .disabled ) {
6363 _cmd.instruction .value = instruction;
6464 }
@@ -127,17 +127,33 @@ void flash_init(Qspi &qspi)
127127 ret = qspi_command_transfer (&qspi.handle , qspi.cmd .get (), NULL , 0 , status, QSPI_STATUS_REG_SIZE);
128128 TEST_ASSERT_EQUAL (QSPI_STATUS_OK, ret);
129129
130- qspi.cmd .build (QSPI_CMD_RSTEN);
131- ret = qspi_command_transfer (&qspi.handle , qspi.cmd .get (), NULL , 0 , NULL , 0 );
132- TEST_ASSERT_EQUAL (QSPI_STATUS_OK, ret);
130+ // Only do reset enable if device needs it
131+ if (QSPI_CMD_RSTEN != 0 ) {
132+ qspi.cmd .build (QSPI_CMD_RSTEN);
133+ ret = qspi_command_transfer (&qspi.handle , qspi.cmd .get (), NULL , 0 , NULL , 0 );
134+ TEST_ASSERT_EQUAL (QSPI_STATUS_OK, ret);
133135
134- WAIT_FOR (WRSR_MAX_TIME, qspi);
136+ WAIT_FOR (WRSR_MAX_TIME, qspi);
137+ }
135138
136139 qspi.cmd .build (QSPI_CMD_RST);
137140 ret = qspi_command_transfer (&qspi.handle , qspi.cmd .get (), NULL , 0 , NULL , 0 );
138141 TEST_ASSERT_EQUAL (QSPI_STATUS_OK, ret);
139142
140143 WAIT_FOR (WAIT_MAX_TIME, qspi);
144+
145+ // Zero out status register to attempt to clear block protection bits
146+ uint8_t blanks[QSPI_STATUS_REG_SIZE] = {0 };
147+
148+ qspi.cmd .build (QSPI_CMD_WREN);
149+ ret = qspi_command_transfer (&qspi.handle , qspi.cmd .get (), NULL , 0 , NULL , 0 );
150+ TEST_ASSERT_EQUAL (QSPI_STATUS_OK, ret);
151+
152+ qspi.cmd .build (QSPI_CMD_WRSR);
153+ ret = qspi_command_transfer (&qspi.handle , qspi.cmd .get (), blanks, 1 , NULL , 0 );
154+ TEST_ASSERT_EQUAL (QSPI_STATUS_OK, ret);
155+
156+ WAIT_FOR (WRSR_MAX_TIME, qspi);
141157}
142158
143159
0 commit comments