Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ports/atmel-samd/usb_mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,22 @@ int32_t usb_msc_xfer_done(uint8_t lun) {
// drive into our cache and trigger the USB DMA to output the
// sector. Once the sector is transmitted, xfer_done will be called.
void usb_msc_background(void) {
if (active_read && !usb_busy) {
// Check USB busy first because we never want to queue another transfer if it is. Checking
// active_read or active_write first leaves the possibility that they are true, an xfer done
// interrupt occurs (setting them false), turning off usb_busy and causing us to queue a
// spurious transfer.
if (usb_busy) {
return;
}
if (active_read) {
fs_user_mount_t * vfs = get_vfs(active_lun);
disk_read(vfs, sector_buffer, active_addr, 1);
CRITICAL_SECTION_ENTER();
int32_t result = mscdf_xfer_blocks(true, sector_buffer, 1);
usb_busy = result == ERR_NONE;
CRITICAL_SECTION_LEAVE();
}
if (active_write && !usb_busy) {
if (active_write) {
if (sector_loaded) {
fs_user_mount_t * vfs = get_vfs(active_lun);
disk_write(vfs, sector_buffer, active_addr, 1);
Expand Down