Skip to content

Commit 37da9b9

Browse files
committed
[core] Fix ordering of serial Flash read command completion
1 parent 184ab7a commit 37da9b9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/flash.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static void flash_execute_command(void) {
135135
case 0x05: // Read Status Register-1
136136
case 0x35: // Read Status Register-2
137137
case 0x15: // Read Status Register-3
138-
flash.commandStatus[0] |= 1 << 2;
138+
flash.commandStatus[0] |= 2 << 1;
139139
break;
140140
case 0x32: // Quad Input Page Program
141141
flash.commandStatus[0] |= 1 << 1;
@@ -154,6 +154,11 @@ static void flash_execute_command(void) {
154154
break;
155155
}
156156
if (!flash.commandLength && flash.commandStatus[0] & 3 << 1) {
157+
/* Zero-length reads or writes finish without any byte transfers */
158+
flash.commandStatus[0] &= ~(3 << 1);
159+
flash_finish_command();
160+
} else if (flash.commandStatus[0] & 2 << 1) {
161+
/* Reads are considered finished before the byte transfers */
157162
flash_finish_command();
158163
}
159164
}
@@ -193,8 +198,11 @@ static void flash_write_command(uint8_t byte) {
193198
}
194199
static void flash_command_byte_transferred(void) {
195200
if (!--flash.commandLength) {
201+
bool write = flash.commandStatus[0] & 1 << 1;
196202
flash.commandStatus[0] &= ~(3 << 1);
197-
flash_finish_command();
203+
if (write) {
204+
flash_finish_command();
205+
}
198206
}
199207
}
200208

0 commit comments

Comments
 (0)