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

Fixes bug in tuh_msc_ready #2085

Merged
merged 1 commit into from Jun 27, 2023
Merged

Conversation

georgeboc
Copy link
Contributor

Description
The documentation in msc_host.h specifies that:

// Check if the interface is currently ready or busy transferring data
bool tuh_msc_ready(uint8_t dev_addr);

An interface can be busy either receiving or sending data. The current code contemplates only the data reception, but not the data transmission.

See the following example for reference:

tuh_msc_read10(dev_addr, 0, &buffer, 0, 1, read_complete_cb, 0);

while (!tuh_msc_ready(dev_addr)) {
    tuh_task();
}

tuh_msc_inquiry(dev_addr, 0, &inquiry_resp, inquiry_complete_cb, 0);

while (!tuh_msc_ready(dev_addr)) {
    tuh_task();
}

The above example currently fails because the USB BULK transfers have no reserved bandwidth on the bus, so it is possible to have a race condition when the following steps happen:

  1. send read command when calling tuh_msc_read10,
  2. there is no bandwith available to send the command yet, but the processor continues,
  3. we run the inquiry command when calling tuh_msc_inquiry,
  4. we reach this line of code and we fail the assertion, as the interface is still busy trying to send the previous command.

This PR solves the problem by verifying in the tuh_msc_ready function that the output endpoint is not busy.

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spot on, thank you for the fix

@hathach hathach merged commit fe77b67 into hathach:master Jun 27, 2023
35 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants