Skip to content

Commit

Permalink
Don't disable OUT endpoints after USB reset on GD32V
Browse files Browse the repository at this point in the history
  • Loading branch information
Disasm committed Nov 14, 2023
1 parent 596ca02 commit 2951fbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<USB: UsbPeripheral> UsbBus<USB> {
}
}

fn deconfigure_all(&self, cs: &CriticalSection) {
fn deconfigure_all(&self, cs: &CriticalSection, core_id: u32) {
let regs = self.regs.borrow(cs);

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

for ep in &self.allocator.endpoints_out {
if let Some(ep) = ep {
ep.deconfigure(cs);
ep.deconfigure(cs, core_id);
}
}
}
Expand Down Expand Up @@ -605,7 +605,7 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
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);
Expand Down
15 changes: 9 additions & 6 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2951fbb

Please sign in to comment.