From fa7c9275b420e08823f931e59290c69a912bd50c Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Sat, 30 Jul 2022 10:09:20 +0100 Subject: [PATCH] Fix missed ep0-data-out transaction The ep0-out buffer must not be marked as available unless required. Otherwise, the controller will acknowledge the data-out packet but won't reflect that in its status registers. This patch forces the controller to nack the data-out phase until we have processed the setup packet. --- rp2040-hal/src/usb.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rp2040-hal/src/usb.rs b/rp2040-hal/src/usb.rs index 6178565..b50741f 100644 --- a/rp2040-hal/src/usb.rs +++ b/rp2040-hal/src/usb.rs @@ -352,8 +352,12 @@ impl Inner { w.full_0().clear_bit(); w.pid_0().bit(!r.pid_0().bit()) }); - cortex_m::asm::delay(12); - buf_control.modify(|_, w| w.available_0().set_bit()); + if index != 0 || len == ep.max_packet_size.into() { + // only mark as available on the control endpoint if and only if the packet was + // max_packet_size + cortex_m::asm::delay(12); + buf_control.modify(|_, w| w.available_0().set_bit()); + } Ok(len) } }