@@ -691,7 +691,6 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
691
691
modify_reg ! ( otg_global, regs. global( ) , GRSTCTL , TXFNUM : epnum, TXFFLSH : 1 ) ;
692
692
while read_reg ! ( otg_global, regs. global( ) , GRSTCTL , TXFFLSH ) == 1 { }
693
693
}
694
- ep_setup |= 1 << epnum;
695
694
}
696
695
0x03 | 0x04 => {
697
696
// OUT completed | SETUP completed
@@ -701,6 +700,18 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
701
700
// reading GRXSTSP.
702
701
read_reg ! ( otg_global, regs. global( ) , GRXSTSP ) ; // pop GRXSTSP
703
702
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
+
704
715
// Re-enable the endpoint, F429-like chips only
705
716
if core_id == 0x0000_1000
706
717
|| core_id == 0x0000_1200
@@ -760,7 +771,9 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
760
771
ep_out |= 1 << ep. address ( ) . index ( ) ;
761
772
}
762
773
EndpointBufferState :: DataSetup => {
763
- ep_setup |= 1 << ep. address ( ) . index ( ) ;
774
+ if core_id > 0x0000_1000 {
775
+ ep_setup |= 1 << ep. address ( ) . index ( ) ;
776
+ }
764
777
}
765
778
EndpointBufferState :: Empty => { }
766
779
}
0 commit comments