diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-05-12 16:46:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-12 16:46:35 +0000 |
commit | 13bcb5ffb692997df192ab3bf8c20b4fb2a1d172 (patch) | |
tree | 9fd3242c8ab8bc9a8d552730511466803064906a /embassy-nrf | |
parent | 45c0f1ab88edb7a635faf3bb0941d81772100da1 (diff) | |
parent | 0764fad5871fb2296fe3efbef57364028cf0b0c1 (diff) | |
download | embassy-13bcb5ffb692997df192ab3bf8c20b4fb2a1d172.zip |
Merge #768
768: nrf/usb: fix control out transfers getting corrupted due to ep0rcvout sticking from earlier. r=Dirbaio a=Dirbaio
bors r+
Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Diffstat (limited to 'embassy-nrf')
-rw-r--r-- | embassy-nrf/src/usb.rs | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 1162946a..8d589aed 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs @@ -9,7 +9,6 @@ use embassy::interrupt::InterruptExt; use embassy::util::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; -use embassy_usb::control::Request; use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; use futures::future::poll_fn; @@ -526,10 +525,6 @@ unsafe fn read_dma<T: Instance>(i: usize, buf: &mut [u8]) -> Result<usize, Endpo return Err(EndpointError::BufferOverflow); } - if i == 0 { - regs.events_ep0datadone.reset(); - } - let epout = [ ®s.epout0, ®s.epout1, @@ -640,7 +635,7 @@ pub struct ControlPipe<'d, T: Instance> { } impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { - type SetupFuture<'a> = impl Future<Output = Request> + 'a where Self: 'a; + type SetupFuture<'a> = impl Future<Output = [u8;8]> + 'a where Self: 'a; type DataOutFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a; type DataInFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a; @@ -652,11 +647,11 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { async move { let regs = T::regs(); + // Reset shorts + regs.shorts.write(|w| w); + // Wait for SETUP packet - regs.intenset.write(|w| { - w.ep0setup().set(); - w.ep0datadone().set() - }); + regs.intenset.write(|w| w.ep0setup().set()); poll_fn(|cx| { EP0_WAKER.register(cx.waker()); let regs = T::regs(); @@ -668,8 +663,6 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { }) .await; - // Reset shorts - regs.shorts.write(|w| w); regs.events_ep0setup.reset(); let mut buf = [0; 8]; @@ -682,14 +675,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { buf[6] = regs.wlengthl.read().wlengthl().bits(); buf[7] = regs.wlengthh.read().wlengthh().bits(); - let req = Request::parse(&buf); - - if req.direction == UsbDirection::Out { - regs.tasks_ep0rcvout - .write(|w| w.tasks_ep0rcvout().set_bit()); - } - - req + buf } } @@ -697,6 +683,12 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { async move { let regs = T::regs(); + regs.events_ep0datadone.reset(); + + // This starts a RX on EP0. events_ep0datadone notifies when done. + regs.tasks_ep0rcvout + .write(|w| w.tasks_ep0rcvout().set_bit()); + // Wait until ready regs.intenset.write(|w| { w.usbreset().set(); @@ -728,13 +720,13 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { async move { let regs = T::regs(); regs.events_ep0datadone.reset(); - unsafe { - write_dma::<T>(0, buf); - } regs.shorts .write(|w| w.ep0datadone_ep0status().bit(last_packet)); + // This starts a TX on EP0. events_ep0datadone notifies when done. + unsafe { write_dma::<T>(0, buf) } + regs.intenset.write(|w| { w.usbreset().set(); w.ep0setup().set(); |