From 88d9599a63a89a1ba2c107671945e034e16a3f30 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 7 Mar 2022 00:24:13 +0100 Subject: [PATCH] common/usb/serial: add some trace logging. --- embassy-hal-common/src/usb/usb_serial.rs | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/embassy-hal-common/src/usb/usb_serial.rs b/embassy-hal-common/src/usb/usb_serial.rs index 2592d05a..20a1840b 100644 --- a/embassy-hal-common/src/usb/usb_serial.rs +++ b/embassy-hal-common/src/usb/usb_serial.rs @@ -167,6 +167,7 @@ impl<'bus, 'a, B: UsbBus> AsyncWrite for UsbSerial<'bus, 'a, B> { let write_buf = this.write_buf.push_buf(); if write_buf.is_empty() { + trace!("buf full, registering waker"); this.write_waker.register(cx.waker()); return Poll::Pending; } @@ -244,10 +245,18 @@ impl<'bus, 'a, B: UsbBus> UsbSerial<'bus, 'a, B> { }; if !buf.is_empty() { + trace!("writing packet len {}", buf.len()); let count = match self.inner.write_packet(buf) { - Ok(c) => c, - Err(UsbError::WouldBlock) => 0, + Ok(c) => { + trace!("write packet: OK {}", c); + c + } + Err(UsbError::WouldBlock) => { + trace!("write packet: WouldBlock"); + 0 + } Err(_) => { + trace!("write packet: error"); self.write_error = true; return; } @@ -260,11 +269,20 @@ impl<'bus, 'a, B: UsbBus> UsbSerial<'bus, 'a, B> { } self.write_buf.pop(count); } else if full_size_packets > 0 { - if let Err(e) = self.inner.write_packet(&[]) { - if !matches!(e, UsbError::WouldBlock) { - self.write_error = true; + trace!("writing empty packet"); + match self.inner.write_packet(&[]) { + Ok(_) => { + trace!("write empty packet: OK"); + } + Err(UsbError::WouldBlock) => { + trace!("write empty packet: WouldBlock"); + return; + } + Err(_) => { + trace!("write empty packet: Error"); + self.write_error = true; + return; } - return; } self.write_state = WriteState::Idle; } @@ -287,7 +305,9 @@ where } fn endpoint_in_complete(&mut self, addr: EndpointAddress) { + trace!("DONE endpoint_in_complete"); if addr == self.inner.write_ep_address() { + trace!("DONE writing packet, waking"); self.write_waker.wake(); self.flush_write();