Skip to content

Commit b72ea62

Browse files
committed
Don't disable OUT endpoints after USB reset on GD32V
1 parent 7153dc0 commit b72ea62

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/bus.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<USB: UsbPeripheral> UsbBus<USB> {
111111
}
112112
}
113113

114-
fn deconfigure_all(&self, cs: CriticalSection<'_>) {
114+
fn deconfigure_all(&self, cs: &CriticalSection<'_>, core_id: u32) {
115115
let regs = self.regs.borrow(cs);
116116

117117
// disable interrupts
@@ -125,7 +125,7 @@ impl<USB: UsbPeripheral> UsbBus<USB> {
125125

126126
for ep in &self.allocator.endpoints_out {
127127
if let Some(ep) = ep {
128-
ep.deconfigure(cs);
128+
ep.deconfigure(cs, core_id);
129129
}
130130
}
131131
}
@@ -605,7 +605,7 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
605605
if reset != 0 {
606606
write_reg!(otg_global, regs.global(), GINTSTS, USBRST: 1);
607607

608-
self.deconfigure_all(cs);
608+
self.deconfigure_all(cs, core_id);
609609

610610
// Flush RX
611611
modify_reg!(otg_global, regs.global(), GRSTCTL, RXFFLSH: 1);

src/endpoint.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,18 @@ impl EndpointOut {
189189
}
190190
}
191191

192-
pub fn deconfigure(&self, _cs: CriticalSection<'_>) {
192+
pub fn deconfigure(&self, _cs: &CriticalSection<'_>, core_id: u32) {
193193
let regs = self.usb.endpoint_out(self.index() as usize);
194194

195-
// deactivating endpoint
196-
modify_reg!(endpoint_out, regs, DOEPCTL, USBAEP: 0);
195+
// GD32VF103 doesn't support endpoint deactivation after reset, so skip this.
196+
if core_id > 0x0000_1000 {
197+
// deactivating endpoint
198+
modify_reg!(endpoint_out, regs, DOEPCTL, USBAEP: 0);
197199

198-
// disabling endpoint
199-
if read_reg!(endpoint_out, regs, DOEPCTL, EPENA) != 0 && self.index() != 0 {
200-
modify_reg!(endpoint_out, regs, DOEPCTL, EPDIS: 1)
200+
// disabling endpoint
201+
if read_reg!(endpoint_out, regs, DOEPCTL, EPENA) != 0 && self.index() != 0 {
202+
modify_reg!(endpoint_out, regs, DOEPCTL, EPDIS: 1)
203+
}
201204
}
202205

203206
// clean EP interrupts

0 commit comments

Comments
 (0)