@@ -169,6 +169,23 @@ impl<B: UsbBus> UsbDevice<'_, B> {
169
169
170
170
// Pending events for endpoint 0?
171
171
if ( eps & 1 ) != 0 {
172
+ // Handle EP0-IN conditions first. When both EP0-IN and EP0-OUT have completed,
173
+ // it is possible that EP0-OUT is a zero-sized out packet to complete the STATUS
174
+ // phase of the control transfer. We have to process EP0-IN first to update our
175
+ // internal state properly.
176
+ if ( ep_in_complete & 1 ) != 0 {
177
+ let completed = self . control . handle_in_complete ( ) ;
178
+
179
+ if !B :: QUIRK_SET_ADDRESS_BEFORE_STATUS {
180
+ if completed && self . pending_address != 0 {
181
+ self . bus . set_device_address ( self . pending_address ) ;
182
+ self . pending_address = 0 ;
183
+
184
+ self . device_state = UsbDeviceState :: Addressed ;
185
+ }
186
+ }
187
+ }
188
+
172
189
let req = if ( ep_setup & 1 ) != 0 {
173
190
self . control . handle_setup ( )
174
191
} else if ( ep_out & 1 ) != 0 {
@@ -185,19 +202,6 @@ impl<B: UsbBus> UsbDevice<'_, B> {
185
202
_ => ( ) ,
186
203
} ;
187
204
188
- if ( ep_in_complete & 1 ) != 0 {
189
- let completed = self . control . handle_in_complete ( ) ;
190
-
191
- if !B :: QUIRK_SET_ADDRESS_BEFORE_STATUS {
192
- if completed && self . pending_address != 0 {
193
- self . bus . set_device_address ( self . pending_address ) ;
194
- self . pending_address = 0 ;
195
-
196
- self . device_state = UsbDeviceState :: Addressed ;
197
- }
198
- }
199
- }
200
-
201
205
eps &= !1 ;
202
206
}
203
207
0 commit comments