diff --git a/lib/usb/usb_msc.c b/lib/usb/usb_msc.c index ba18b49c94..0b8c6133f7 100644 --- a/lib/usb/usb_msc.c +++ b/lib/usb/usb_msc.c @@ -594,6 +594,21 @@ static void msc_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) trans->current_block++; } } + + /* Fix "writes aren't acknowledged" bug on Linux (PR #409) */ + if (false == trans->csw_valid) { + scsi_command(ms, trans, EVENT_NEED_STATUS); + trans->csw_valid = true; + } + left = sizeof(struct usb_msc_csw) - trans->csw_sent; + if (0 < left) { + max_len = MIN(ms->ep_out_size, left); + p = &trans->csw.buf[trans->csw_sent]; + len = usbd_ep_write_packet(usbd_dev, ms->ep_in, p, + max_len); + trans->csw_sent += len; + } + } else if (trans->byte_count < trans->bytes_to_write) { if (0 < trans->block_count) { if ((0 == trans->byte_count) && (NULL != ms->lock)) {