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

STM32F407 fails to enumerate when polled periodically #9

Closed
ryan-summers opened this issue Sep 8, 2020 · 6 comments
Closed

STM32F407 fails to enumerate when polled periodically #9

ryan-summers opened this issue Sep 8, 2020 · 6 comments

Comments

@ryan-summers
Copy link
Member

If the USB device is polled periodically, the STM32F407 fails to enumerate. To recreate, use the following example:
https://github.com/stm32-rs/stm32f4xx-hal/blob/master/examples/usb_serial.rs and update the loop as follows:

let cp = cortex_m::Peripherals::take().unwrap();
let mut delay = stm32f4xx_hal::delay::Delay::new(cp.SYST, clocks);
loop {
    delay.delay_ms(1u8);
    // ... rest
}

A wireshark capture of the USB transactions with the device give some insight as to what is happening:
image

The first BOS descriptor request gets no response. The following 2 requests do get a response. However, then the first DEVICE_QUALIFIER descriptor gets a malformed packet as a response. Analysis of this packet seems to indicate that this is actually a BOS descriptor response from earlier.

This seems to indicate that the descriptor responses are offset by 1 improperly. It is unclear why the first BOS descriptor response fails, but initial debugging indicates it may be an improper ControlState setting. I'm still investigating root cause here.

@ryan-summers ryan-summers changed the title STMF407 fails to enumerate when polled periodically STM32F407 fails to enumerate when polled periodically Sep 8, 2020
@Disasm
Copy link
Member

Disasm commented Sep 8, 2020

Hmm, I think I earlier faced with a situation when device responds to the first packet with garbage data. In this case, this reply is ignored by host and next reply is used as a reply to the first request.
The cause is still unclear to me, but hopefully USB driver is able to recover from the situation and resend the request.

@ryan-summers
Copy link
Member Author

Further analysis and investigation has revealed this was a race condition in the processing order within usb-device. I've PR'd a fix in at rust-embedded-community/usb-device#41. We can either close this now, or we can choose to close it once the fix is merged in to usb-device and incorporated into this crate.

@Disasm
Copy link
Member

Disasm commented Sep 9, 2020

Thank you for investigating this!
I'd like to leave the issue open, so that other people can find it before we have the fix released. I'm not sure we need to do something to incorporate the fix into the crate, because it's a bug fix and will hopefully be released as a new patch version, so cargo update will do the job.

@Disasm
Copy link
Member

Disasm commented Oct 1, 2020

@ryan-summers Could you check/confirm that this crate works with the latest released version of usb-device? If so, we can probably close the issue.

@ryan-summers
Copy link
Member Author

I have confirmed that using usb-device 0.2.6 in my application (without using patch) appears to have resolved this. I'll close this now. :)

@Disasm
Copy link
Member

Disasm commented Oct 2, 2020

Thank you for investigating and fixing the problem!

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