From f8d608093f51ab6fe97b32c7a23bf131a10b6f9c Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 7 Jul 2023 03:41:27 +0200 Subject: [PATCH] stm32/otg: implement `EndpointError::Disabled` for reads. It was implemented only for writes. --- embassy-stm32/src/usb_otg/usb.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/usb_otg/usb.rs b/embassy-stm32/src/usb_otg/usb.rs index 492b7758..d0284746 100644 --- a/embassy-stm32/src/usb_otg/usb.rs +++ b/embassy-stm32/src/usb_otg/usb.rs @@ -1154,14 +1154,22 @@ impl<'d, T: Instance> embassy_usb_driver::EndpointOut for Endpoint<'d, T, Out> { trace!("read start len={}", buf.len()); poll_fn(|cx| { + let r = T::regs(); let index = self.info.addr.index(); let state = T::state(); state.ep_out_wakers[index].register(cx.waker()); + let doepctl = r.doepctl(index).read(); + trace!("read ep={:?}: doepctl {:08x}", self.info.addr, doepctl.0,); + if !doepctl.usbaep() { + trace!("read ep={:?} error disabled", self.info.addr); + return Poll::Ready(Err(EndpointError::Disabled)); + } + let len = state.ep_out_size[index].load(Ordering::Relaxed); if len != EP_OUT_BUFFER_EMPTY { - trace!("read done len={}", len); + trace!("read ep={:?} done len={}", self.info.addr, len); if len as usize > buf.len() { return Poll::Ready(Err(EndpointError::BufferOverflow)); @@ -1214,7 +1222,12 @@ impl<'d, T: Instance> embassy_usb_driver::EndpointIn for Endpoint<'d, T, In> { let diepctl = r.diepctl(index).read(); let dtxfsts = r.dtxfsts(index).read(); - trace!("diepctl {:08x} ftxfsts {:08x}", diepctl.0, dtxfsts.0); + trace!( + "write ep={:?}: diepctl {:08x} ftxfsts {:08x}", + self.info.addr, + diepctl.0, + dtxfsts.0 + ); if !diepctl.usbaep() { trace!("write ep={:?} wait for prev: error disabled", self.info.addr); Poll::Ready(Err(EndpointError::Disabled))