Skip to content

Commit 7a3f86d

Browse files
committed
Check usb_busy up front in usb background function.
Waiting to do so risks accidentally queueing another response. Hopefully fixes #655 but we'll let @jerryneedell confirm.
1 parent b64d568 commit 7a3f86d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ports/atmel-samd/usb_mass_storage.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,22 @@ int32_t usb_msc_xfer_done(uint8_t lun) {
280280
// drive into our cache and trigger the USB DMA to output the
281281
// sector. Once the sector is transmitted, xfer_done will be called.
282282
void usb_msc_background(void) {
283-
if (active_read && !usb_busy) {
283+
// Check USB busy first because we never want to queue another transfer if it is. Checking
284+
// active_read or active_write first leaves the possibility that they are true, an xfer done
285+
// interrupt occurs (setting them false), turning off usb_busy and causing us to queue a
286+
// spurious transfer.
287+
if (usb_busy) {
288+
return;
289+
}
290+
if (active_read) {
284291
fs_user_mount_t * vfs = get_vfs(active_lun);
285292
disk_read(vfs, sector_buffer, active_addr, 1);
286293
CRITICAL_SECTION_ENTER();
287294
int32_t result = mscdf_xfer_blocks(true, sector_buffer, 1);
288295
usb_busy = result == ERR_NONE;
289296
CRITICAL_SECTION_LEAVE();
290297
}
291-
if (active_write && !usb_busy) {
298+
if (active_write) {
292299
if (sector_loaded) {
293300
fs_user_mount_t * vfs = get_vfs(active_lun);
294301
disk_write(vfs, sector_buffer, active_addr, 1);

0 commit comments

Comments
 (0)