Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB MSC: Writes aren't acknowledged #409

Closed
Spritetm opened this issue Feb 21, 2015 · 2 comments
Closed

USB MSC: Writes aren't acknowledged #409

Spritetm opened this issue Feb 21, 2015 · 2 comments

Comments

@Spritetm
Copy link

The USB MSC code has a bug: if a write request is sent, the MSC code will handle it but won't send an CSW back, leaving the host to wait forever. This is actually visible in the examples in the example repo: if you flash a msc example and try to write to the resulting drive, at least under Linux the device hangs.

Here's the fix I used to solve it. I'm not a USB expert by far, but as far as I can tell this fixes the issue:

--- usb_msc.c   2015-01-28 17:38:50.275440725 +0100
+++ usb_msc_mine.c  2015-02-21 23:04:41.681417393 +0100
@@ -586,6 +588,19 @@ static void msc_data_rx_cb(usbd_device *
                trans->current_block++;
            }
        }
+
+       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)) {
@klenSA
Copy link

klenSA commented Nov 9, 2015

I confirm the problem under Linux, and the decision of the bug above
code
thanks Spritetm

schnommus pushed a commit to schnommus/libopencm3 that referenced this issue Feb 2, 2018
schnommus pushed a commit to schnommus/libopencm3 that referenced this issue Feb 6, 2018
schnommus pushed a commit to schnommus/libopencm3 that referenced this issue Feb 10, 2018
schnommus pushed a commit to schnommus/libopencm3 that referenced this issue Feb 19, 2018
karlp pushed a commit to karlp/libopencm3 that referenced this issue Feb 24, 2018
@karlp karlp closed this as completed in 64a6f36 Mar 2, 2018
@Spritetm
Copy link
Author

Spritetm commented Mar 3, 2018

Whoah, that took a while. Thanks for taking care of this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants