@@ -58,7 +58,7 @@ void QspiCommand::set_dummy_cycles(int dummy_cycles)
58
58
59
59
void QspiCommand::build (int instruction, int address, int alt)
60
60
{
61
- _cmd.instruction .disabled = (instruction == QSPI_NONE );
61
+ _cmd.instruction .disabled = (instruction == QSPI_NO_INST );
62
62
if (!_cmd.instruction .disabled ) {
63
63
_cmd.instruction .value = instruction;
64
64
}
@@ -127,17 +127,33 @@ void flash_init(Qspi &qspi)
127
127
ret = qspi_command_transfer (&qspi.handle , qspi.cmd .get (), NULL , 0 , status, QSPI_STATUS_REG_SIZE);
128
128
TEST_ASSERT_EQUAL (QSPI_STATUS_OK, ret);
129
129
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);
133
135
134
- WAIT_FOR (WRSR_MAX_TIME, qspi);
136
+ WAIT_FOR (WRSR_MAX_TIME, qspi);
137
+ }
135
138
136
139
qspi.cmd .build (QSPI_CMD_RST);
137
140
ret = qspi_command_transfer (&qspi.handle , qspi.cmd .get (), NULL , 0 , NULL , 0 );
138
141
TEST_ASSERT_EQUAL (QSPI_STATUS_OK, ret);
139
142
140
143
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);
141
157
}
142
158
143
159
0 commit comments