Skip to content

Commit 006f70c

Browse files
committed
Indicate SETUP event only after 'SETUP completed' for GD32V
1 parent 721123b commit 006f70c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/bus.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
691691
modify_reg!(otg_global, regs.global(), GRSTCTL, TXFNUM: epnum, TXFFLSH: 1);
692692
while read_reg!(otg_global, regs.global(), GRSTCTL, TXFFLSH) == 1 {}
693693
}
694-
ep_setup |= 1 << epnum;
695694
}
696695
0x03 | 0x04 => {
697696
// OUT completed | SETUP completed
@@ -701,6 +700,18 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
701700
// reading GRXSTSP.
702701
read_reg!(otg_global, regs.global(), GRXSTSP); // pop GRXSTSP
703702

703+
if status == 0x04 && core_id == 0x0000_1000 {
704+
// For GD32VF103 report SETUP event only after the "SETUP completed"
705+
// event. For newer chips SETUP event is reported after successful
706+
// read from the endpoint FIFO to the buffer.
707+
ep_setup |= 1 << epnum;
708+
709+
// We indicate presence of SETUP packet here, because otherwise
710+
// usb-device starts IN transfer after the "SETUP received" event.
711+
// This transfer gets interrupted by the "SETUP completed" event:
712+
// USB peripheral automatically disables EP0 IN endpoint.
713+
}
714+
704715
// Re-enable the endpoint, F429-like chips only
705716
if core_id == 0x0000_1000
706717
|| core_id == 0x0000_1200
@@ -760,7 +771,9 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
760771
ep_out |= 1 << ep.address().index();
761772
}
762773
EndpointBufferState::DataSetup => {
763-
ep_setup |= 1 << ep.address().index();
774+
if core_id > 0x0000_1000 {
775+
ep_setup |= 1 << ep.address().index();
776+
}
764777
}
765778
EndpointBufferState::Empty => {}
766779
}

0 commit comments

Comments
 (0)