From 06142ffedca8f14b5d7200aace24f26546a0006a Mon Sep 17 00:00:00 2001 From: Kaido Kert Date: Mon, 26 May 2025 08:36:35 -0700 Subject: [PATCH 1/2] Fix isochronous IN transfers For IN endpoint transfers, it's required to set EVEN/ODD frames correctly. Otherwise 50% of the frames do not get delivered. --- src/endpoint.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/endpoint.rs b/src/endpoint.rs index c6e3be1..83e03ea 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -1,5 +1,5 @@ use crate::endpoint_memory::{EndpointBuffer, EndpointBufferState}; -use crate::ral::{endpoint0_out, endpoint_in, endpoint_out, modify_reg, read_reg, write_reg}; +use crate::ral::{endpoint0_out, endpoint_in, endpoint_out, otg_device, modify_reg, read_reg, write_reg}; use crate::target::{fifo_write, UsbRegisters}; use crate::transition::EndpointDescriptor; use crate::UsbPeripheral; @@ -139,7 +139,21 @@ impl EndpointIn { #[cfg(feature = "hs")] write_reg!(endpoint_in, ep, DIEPTSIZ, MCNT: 1, PKTCNT: 1, XFRSIZ: buf.len() as u32); - modify_reg!(endpoint_in, ep, DIEPCTL, CNAK: 1, EPENA: 1); + // For isochronous endpoints, we need to set EVEN/ODD frames here + if matches!(self.descriptor.ep_type,usb_device::endpoint::EndpointType::Isochronous{ .. }) { + let mut fnsof = 0; + critical_section::with(|cs| { + let regs = self.usb.device(); + fnsof = read_reg!(otg_device, regs, DSTS, FNSOF); + }); + if fnsof & 1 == 1 { + modify_reg!(endpoint_in, ep, DIEPCTL, CNAK: 1, EPENA: 1, SD0PID_SEVNFRM: 1); + } else { + modify_reg!(endpoint_in, ep, DIEPCTL, CNAK: 1, EPENA: 1, SODDFRM_SD1PID: 1); + } + } else { + modify_reg!(endpoint_in, ep, DIEPCTL, CNAK: 1, EPENA: 1); + } fifo_write(self.usb, self.index(), buf); From 8d0f9388003d8a6db6b2051a4f3e85015cac39a1 Mon Sep 17 00:00:00 2001 From: Kaido Kert Date: Mon, 26 May 2025 08:37:43 -0700 Subject: [PATCH 2/2] Add a stub cortex-m feature Add back a cortex-m feature, as usb-device depends on it --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index d25d028..80dc619 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,3 +23,4 @@ features = ['fs'] hs = [] fs = [] xcvrdly = [] +cortex-m = []