Skip to content

Commit 8157248

Browse files
committed
Move usb read finish into interrupt.
Having the `active_read = false` in the background function left a chance that a new_write occurs before active_read is set to false. In that case, we'll read the appropriate data rather than write it and never clear the active write. Hopefully fixes adafruit#655.
1 parent 9d928b5 commit 8157248

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

ports/atmel-samd/usb_mass_storage.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ int32_t usb_msc_xfer_done(uint8_t lun) {
260260
if (active_read) {
261261
active_addr += 1;
262262
active_nblocks--;
263+
if (active_nblocks == 0) {
264+
active_read = false;
265+
}
263266
}
264267

265268
if (active_write) {
@@ -278,10 +281,6 @@ int32_t usb_msc_xfer_done(uint8_t lun) {
278281
// sector. Once the sector is transmitted, xfer_done will be called.
279282
void usb_msc_background(void) {
280283
if (active_read && !usb_busy) {
281-
if (active_nblocks == 0) {
282-
active_read = false;
283-
return;
284-
}
285284
fs_user_mount_t * vfs = get_vfs(active_lun);
286285
disk_read(vfs, sector_buffer, active_addr, 1);
287286
CRITICAL_SECTION_ENTER();

0 commit comments

Comments
 (0)