diff options
| author | Matt Johnston <[email protected]> | 2022-10-21 22:02:13 +0800 |
|---|---|---|
| committer | Matt Johnston <[email protected]> | 2022-10-21 22:02:13 +0800 |
| commit | 866a42f3aeb196e2b0f854a52683ee07cffc4ccd (patch) | |
| tree | b0b49dcd07f9c164e329c44999b608e6877a1560 /embassy-rp/src/usb.rs | |
| parent | bf0ad38640bd683401489ea68926aebd25272858 (diff) | |
rp usb: wait for accept() completion
This ensures that the current response has finished being sent
before the subsequent set_address() happens. Otherwise connecting
a device is intermittent, can fail depending on timing.
Diffstat (limited to 'embassy-rp/src/usb.rs')
| -rw-r--r-- | embassy-rp/src/usb.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index 0a904aab3..7a83dcb4a 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs | |||
| @@ -811,8 +811,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 811 | async move { | 811 | async move { |
| 812 | trace!("control: accept"); | 812 | trace!("control: accept"); |
| 813 | 813 | ||
| 814 | let bufcontrol = T::dpram().ep_in_buffer_control(0); | ||
| 814 | unsafe { | 815 | unsafe { |
| 815 | let bufcontrol = T::dpram().ep_in_buffer_control(0); | ||
| 816 | bufcontrol.write(|w| { | 816 | bufcontrol.write(|w| { |
| 817 | w.set_length(0, 0); | 817 | w.set_length(0, 0); |
| 818 | w.set_pid(0, true); | 818 | w.set_pid(0, true); |
| @@ -826,6 +826,18 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 826 | w.set_available(0, true); | 826 | w.set_available(0, true); |
| 827 | }); | 827 | }); |
| 828 | } | 828 | } |
| 829 | |||
| 830 | // wait for completion before returning, needed so | ||
| 831 | // set_address() doesn't happen early. | ||
| 832 | poll_fn(|cx| { | ||
| 833 | EP_IN_WAKERS[0].register(cx.waker()); | ||
| 834 | if unsafe { bufcontrol.read().available(0) } { | ||
| 835 | Poll::Pending | ||
| 836 | } else { | ||
| 837 | Poll::Ready(()) | ||
| 838 | } | ||
| 839 | }) | ||
| 840 | .await; | ||
| 829 | } | 841 | } |
| 830 | } | 842 | } |
| 831 | 843 | ||
