From 73ac5e580df8093df0da0f9c52e2cd881c1ad7a7 Mon Sep 17 00:00:00 2001 From: Vadim Kaushan Date: Sun, 9 Jan 2022 22:01:20 +0200 Subject: [PATCH] Don't disable OUT endpoints after USB reset on GD32V --- src/bus.rs | 6 +++--- src/endpoint.rs | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/bus.rs b/src/bus.rs index eb9c781..c36bad7 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -111,7 +111,7 @@ impl UsbBus { } } - fn deconfigure_all(&self, cs: CriticalSection<'_>) { + fn deconfigure_all(&self, cs: CriticalSection<'_>, core_id: u32) { let regs = self.regs.borrow(cs); // disable interrupts @@ -125,7 +125,7 @@ impl UsbBus { for ep in &self.allocator.endpoints_out { if let Some(ep) = ep { - ep.deconfigure(cs); + ep.deconfigure(cs, core_id); } } } @@ -605,7 +605,7 @@ impl usb_device::bus::UsbBus for UsbBus { if reset != 0 { write_reg!(otg_global, regs.global(), GINTSTS, USBRST: 1); - self.deconfigure_all(cs); + self.deconfigure_all(cs, core_id); // Flush RX modify_reg!(otg_global, regs.global(), GRSTCTL, RXFFLSH: 1); diff --git a/src/endpoint.rs b/src/endpoint.rs index c6e3be1..d8380fe 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -189,15 +189,18 @@ impl EndpointOut { } } - pub fn deconfigure(&self, _cs: CriticalSection<'_>) { + pub fn deconfigure(&self, _cs: CriticalSection<'_>, core_id: u32) { let regs = self.usb.endpoint_out(self.index() as usize); - // deactivating endpoint - modify_reg!(endpoint_out, regs, DOEPCTL, USBAEP: 0); + // GD32VF103 doesn't support endpoint deactivation after reset, so skip this. + if core_id > 0x0000_1000 { + // deactivating endpoint + modify_reg!(endpoint_out, regs, DOEPCTL, USBAEP: 0); - // disabling endpoint - if read_reg!(endpoint_out, regs, DOEPCTL, EPENA) != 0 && self.index() != 0 { - modify_reg!(endpoint_out, regs, DOEPCTL, EPDIS: 1) + // disabling endpoint + if read_reg!(endpoint_out, regs, DOEPCTL, EPENA) != 0 && self.index() != 0 { + modify_reg!(endpoint_out, regs, DOEPCTL, EPDIS: 1) + } } // clean EP interrupts