Index: umsboot/src/app/umsboot/ums.c |
— | — | @@ -562,8 +562,7 @@ |
563 | 563 | switch (request->setup.bRequest.raw) |
564 | 564 | { |
565 | 565 | case 0xfe: // GET_MAX_LUN |
566 | | - request->raw[0] = 0; |
567 | | - *response = request; |
| 566 | + data->buffer->raw[0] = 0; |
568 | 567 | size = 1; |
569 | 568 | break; |
570 | 569 | case 0xff: // STORAGE_RESET |
Index: umsboot/src/app/umsboot/usbglue.c |
— | — | @@ -134,7 +134,7 @@ |
135 | 135 | usb_config1_descriptors.c1_i0_a0_e1in.wMaxPacketSize = highspeed ? 512 : 64; |
136 | 136 | } |
137 | 137 | |
138 | | -static struct usb_interface usb_c1_i0 = |
| 138 | +static const struct usb_interface usb_c1_i0 = |
139 | 139 | { |
140 | 140 | .bus_reset = ums_bus_reset, |
141 | 141 | .ctrl_request = ums_ctrl_request, |
— | — | @@ -162,7 +162,10 @@ |
163 | 163 | |
164 | 164 | static UMSBOOT_USB_DRIVER_STATE_TYPE usb_driver_state = UMSBOOT_USB_DRIVER_STATE; |
165 | 165 | |
166 | | -static struct usb_state usb_state; |
| 166 | +static struct usb_state usb_state = |
| 167 | +{ |
| 168 | + .interface_altsetting = { 0 }, |
| 169 | +}; |
167 | 170 | |
168 | 171 | static union usb_ep0_buffer usb_buffer __attribute__((section(".dmabss.usb_buffer"),aligned(CACHEALIGN_SIZE))); |
169 | 172 | |
— | — | @@ -175,7 +178,6 @@ |
176 | 179 | .buffer = &usb_buffer, |
177 | 180 | .bus_reset = usbglue_bus_reset, |
178 | 181 | .ep0_setup_hook = NULL, |
179 | | - .ep0_data_hook = NULL, |
180 | 182 | .configuration_count = 1, |
181 | 183 | .stringdescriptor_count = 3, |
182 | 184 | .devicedescriptor = &usb_devicedescriptor, |
Index: umsboot/src/protocol/usb/usb.c |
— | — | @@ -1,5 +1,6 @@ |
2 | 2 | #include "global.h" |
3 | 3 | #include "protocol/usb/usb.h" |
| 4 | +#include "sys/util.h" |
4 | 5 | |
5 | 6 | void usb_start_rx(const struct usb_instance* data, union usb_endpoint_number ep, void* buf, int size) |
6 | 7 | { |
— | — | @@ -16,27 +17,35 @@ |
17 | 18 | data->driver->set_stall(data, ep, stall); |
18 | 19 | } |
19 | 20 | |
20 | | -void usb_ep0_start_rx(const struct usb_instance* data, int non_setup) |
| 21 | +void usb_ep0_start_rx(const struct usb_instance* data, int non_setup, bool (*callback)(const struct usb_instance* data, int bytesleft)) |
21 | 22 | { |
| 23 | + data->state->ep0_rx_callback = callback; |
22 | 24 | data->driver->ep0_start_rx(data, non_setup); |
23 | 25 | } |
24 | 26 | |
25 | | -void usb_ep0_start_tx(const struct usb_instance* data, const void* buf, int len) |
| 27 | +bool usb_ep0_rx_callback(const struct usb_instance* data, int bytesleft) |
26 | 28 | { |
| 29 | + usb_ep0_start_rx(data, 0, NULL); |
| 30 | + return true; |
| 31 | +} |
| 32 | + |
| 33 | +void usb_ep0_start_tx(const struct usb_instance* data, const void* buf, int len, bool last, bool (*callback)(const struct usb_instance* data, int bytesleft)) |
| 34 | +{ |
27 | 35 | // Expect zero-length ACK if we are about to actually send data, otherwise expect SETUP. |
28 | | - usb_ep0_start_rx(data, !!len); |
| 36 | + if (last) usb_ep0_start_rx(data, !!len, usb_ep0_rx_callback); |
29 | 37 | |
| 38 | + data->state->ep0_tx_callback = callback; |
30 | 39 | data->driver->ep0_start_tx(data, buf, len); |
31 | 40 | } |
32 | 41 | |
33 | | -void usb_ep0_expect_setup(const struct usb_instance* data) |
| 42 | +bool usb_ep0_tx_callback(const struct usb_instance* data, int bytesleft) |
34 | 43 | { |
35 | | - // The next packet needs to be a SETUP, so lock out everything on the IN pipe. |
36 | | - union usb_endpoint_number ep = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN }; |
37 | | - usb_set_stall(data, ep, 1); |
38 | | - |
39 | | - // Set up the OUT pipe for the SETUP packet, STALLing everything else. |
40 | | - usb_ep0_start_rx(data, 0); |
| 44 | + if (bytesleft || !data->state->ep0_tx_len) return false; |
| 45 | + int len = MIN(64, data->state->ep0_tx_len); |
| 46 | + data->state->ep0_tx_ptr += 64; |
| 47 | + data->state->ep0_tx_len -= len; |
| 48 | + usb_ep0_start_tx(data, data->state->ep0_tx_ptr, len, !!data->state->ep0_tx_len, usb_ep0_tx_callback); |
| 49 | + return true; |
41 | 50 | } |
42 | 51 | |
43 | 52 | void usb_unconfigure_ep(const struct usb_instance* data, union usb_endpoint_number ep) |
— | — | @@ -68,10 +77,10 @@ |
69 | 78 | int i; |
70 | 79 | for (i = 0; i < configuration->interface_count; i++) |
71 | 80 | { |
72 | | - struct usb_interface* interface = configuration->interfaces[i]; |
73 | | - const struct usb_altsetting* altsetting = interface->altsettings[interface->current_altsetting]; |
| 81 | + const struct usb_interface* interface = configuration->interfaces[i]; |
| 82 | + const struct usb_altsetting* altsetting = interface->altsettings[data->state->interface_altsetting[i]]; |
74 | 83 | if (altsetting->unset_altsetting) |
75 | | - altsetting->unset_altsetting(data, i, interface->current_altsetting); |
| 84 | + altsetting->unset_altsetting(data, i, data->state->interface_altsetting[i]); |
76 | 85 | } |
77 | 86 | if (configuration->unset_configuration) |
78 | 87 | configuration->unset_configuration(data, configid); |
— | — | @@ -91,7 +100,7 @@ |
92 | 101 | for (*ifidx = 0; *ifidx < configuration->interface_count; (*ifidx)++) |
93 | 102 | { |
94 | 103 | const struct usb_interface* interface = configuration->interfaces[*ifidx]; |
95 | | - const struct usb_altsetting* altsetting = interface->altsettings[interface->current_altsetting]; |
| 104 | + const struct usb_altsetting* altsetting = interface->altsettings[data->state->interface_altsetting[*ifidx]]; |
96 | 105 | for (*epidx = 0; *epidx < altsetting->endpoint_count; (*epidx)++) |
97 | 106 | { |
98 | 107 | const struct usb_endpoint* endpoint = altsetting->endpoints[*epidx]; |
— | — | @@ -108,7 +117,7 @@ |
109 | 118 | // size == -1: try to run default handler, or send STALL if none exists |
110 | 119 | // size == 0: send ACK |
111 | 120 | // size > 0: send <size> bytes at <addr>, then expect ACK |
112 | | - const void* addr = NULL; |
| 121 | + const void* addr = data->buffer; |
113 | 122 | int size = -1; |
114 | 123 | switch (buffer->setup.bmRequestType.recipient) |
115 | 124 | { |
— | — | @@ -125,7 +134,6 @@ |
126 | 135 | || !data->state->current_address || buffer->setup.wValue) break; |
127 | 136 | data->buffer->raw[0] = 0; |
128 | 137 | data->buffer->raw[1] = 1; |
129 | | - addr = data->buffer; |
130 | 138 | size = 2; |
131 | 139 | break; |
132 | 140 | case USB_SETUP_BREQUEST_SET_ADDRESS: |
— | — | @@ -162,7 +170,6 @@ |
163 | 171 | if (buffer->setup.wLength != 1 || buffer->setup.wIndex |
164 | 172 | || !data->state->current_address || buffer->setup.wValue) break; |
165 | 173 | data->buffer->raw[0] = data->state->current_configuration; |
166 | | - addr = data->buffer; |
167 | 174 | size = 1; |
168 | 175 | break; |
169 | 176 | case USB_SETUP_BREQUEST_SET_CONFIGURATION: |
— | — | @@ -180,8 +187,8 @@ |
181 | 188 | int i; |
182 | 189 | for (i = 0; i < configuration->interface_count; i++) |
183 | 190 | { |
184 | | - struct usb_interface* interface = configuration->interfaces[i]; |
185 | | - interface->current_altsetting = 0; |
| 191 | + const struct usb_interface* interface = configuration->interfaces[i]; |
| 192 | + data->state->interface_altsetting[i] = 0; |
186 | 193 | const struct usb_altsetting* altsetting = interface->altsettings[0]; |
187 | 194 | if (altsetting->set_altsetting) altsetting->set_altsetting(data, i, 0); |
188 | 195 | } |
— | — | @@ -198,9 +205,9 @@ |
199 | 206 | if (!data->state->current_configuration) break; |
200 | 207 | int configid = data->state->current_configuration; |
201 | 208 | const struct usb_configuration* configuration = data->configurations[configid - 1]; |
202 | | - if (buffer->setup.wIndex >= configuration->interface_count) break; |
203 | 209 | int intfid = buffer->setup.wIndex; |
204 | | - struct usb_interface* interface = configuration->interfaces[intfid]; |
| 210 | + if (intfid >= configuration->interface_count) break; |
| 211 | + const struct usb_interface* interface = configuration->interfaces[intfid]; |
205 | 212 | if (interface->ctrl_request) size = interface->ctrl_request(data, intfid, buffer, &addr); |
206 | 213 | if (size != -1) break; |
207 | 214 | switch (buffer->setup.bmRequestType.type) |
— | — | @@ -212,13 +219,11 @@ |
213 | 220 | if (buffer->setup.wLength != 2 || buffer->setup.wValue) break; |
214 | 221 | data->buffer->raw[0] = 0; |
215 | 222 | data->buffer->raw[1] = 0; |
216 | | - addr = data->buffer; |
217 | 223 | size = 2; |
218 | 224 | break; |
219 | 225 | case USB_SETUP_BREQUEST_GET_INTERFACE: |
220 | 226 | if (buffer->setup.wLength != 1 || buffer->setup.wValue) break; |
221 | | - data->buffer->raw[0] = interface->current_altsetting; |
222 | | - addr = data->buffer; |
| 227 | + data->buffer->raw[0] = data->state->interface_altsetting[intfid]; |
223 | 228 | size = 1; |
224 | 229 | break; |
225 | 230 | case USB_SETUP_BREQUEST_SET_INTERFACE: |
— | — | @@ -225,13 +230,13 @@ |
226 | 231 | { |
227 | 232 | if (buffer->setup.wLength |
228 | 233 | || buffer->setup.wValue > interface->altsetting_count) break; |
229 | | - const struct usb_altsetting* altsetting = interface->altsettings[interface->current_altsetting]; |
| 234 | + const struct usb_altsetting* altsetting = interface->altsettings[data->state->interface_altsetting[intfid]]; |
230 | 235 | if (altsetting->unset_altsetting) |
231 | | - altsetting->unset_altsetting(data, intfid, interface->current_altsetting); |
232 | | - interface->current_altsetting = buffer->setup.wValue; |
233 | | - altsetting = interface->altsettings[interface->current_altsetting]; |
| 236 | + altsetting->unset_altsetting(data, intfid, data->state->interface_altsetting[intfid]); |
| 237 | + data->state->interface_altsetting[intfid] = buffer->setup.wValue; |
| 238 | + altsetting = interface->altsettings[data->state->interface_altsetting[intfid]]; |
234 | 239 | if (altsetting->set_altsetting) |
235 | | - altsetting->set_altsetting(data, intfid, interface->current_altsetting); |
| 240 | + altsetting->set_altsetting(data, intfid, data->state->interface_altsetting[intfid]); |
236 | 241 | break; |
237 | 242 | } |
238 | 243 | default: break; |
— | — | @@ -283,17 +288,24 @@ |
284 | 289 | } |
285 | 290 | } |
286 | 291 | // See comment at the top of this function |
287 | | - if (size == 0) usb_ep0_start_tx(data, NULL, 0); |
288 | | - else if (size > 0) usb_ep0_start_tx(data, addr, size); |
289 | | - else if (size >= -2) usb_ep0_expect_setup(data); |
| 292 | + if (size == 0) usb_ep0_start_tx(data, NULL, 0, true, NULL); |
| 293 | + else if (size > 0) |
| 294 | + { |
| 295 | + usb_ep0_start_rx(data, 0, NULL); |
| 296 | + int len = MIN(64, size); |
| 297 | + data->state->ep0_tx_ptr = addr; |
| 298 | + data->state->ep0_tx_len = size - len; |
| 299 | + usb_ep0_start_tx(data, addr, len, !data->state->ep0_tx_len, usb_ep0_tx_callback); |
| 300 | + } |
| 301 | + else if (size >= -2) |
| 302 | + { |
| 303 | + union usb_endpoint_number ep = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN }; |
| 304 | + usb_set_stall(data, ep, 1); |
| 305 | + ep.direction = USB_ENDPOINT_DIRECTION_OUT; |
| 306 | + usb_set_stall(data, ep, 1); |
| 307 | + } |
290 | 308 | } |
291 | 309 | |
292 | | -static void usb_handle_ep0_data(const struct usb_instance* data, union usb_ep0_buffer* buffer, int size) |
293 | | -{ |
294 | | - // We don't accept any commands that have an OUT payload. Just STALL it, no matter what it was. |
295 | | - usb_ep0_expect_setup(data); |
296 | | -} |
297 | | - |
298 | 310 | void usb_handle_bus_reset(const struct usb_instance* data, int highspeed) |
299 | 311 | { |
300 | 312 | data->state->current_address = 0; |
— | — | @@ -305,18 +317,20 @@ |
306 | 318 | const struct usb_configuration* configuration = data->configurations[c]; |
307 | 319 | for (i = 0; i < configuration->interface_count; i++) |
308 | 320 | { |
309 | | - struct usb_interface* interface = configuration->interfaces[i]; |
| 321 | + const struct usb_interface* interface = configuration->interfaces[i]; |
310 | 322 | if (interface->bus_reset) interface->bus_reset(data, c, i, highspeed); |
311 | 323 | } |
312 | 324 | } |
| 325 | + |
| 326 | + // Prime EP0 for the first setup packet. |
| 327 | + usb_ep0_start_rx(data, 0, NULL); |
313 | 328 | } |
314 | 329 | |
315 | 330 | void usb_handle_timeout(const struct usb_instance* data, union usb_endpoint_number epnum, int bytesleft) |
316 | 331 | { |
317 | | - // Hm, the host didn't fetch our EP0 IN packet, so we feel a bit offended. |
318 | | - // Refuse to accept any transfers, until we get a new SETUP token. |
319 | | - if (!epnum.number) usb_ep0_expect_setup(data); |
320 | | - else |
| 332 | + // If the host doesn't fetch an EP0 IN packet, we can't do much about it. |
| 333 | + // This will be recovered by the next SETUP packet. |
| 334 | + if (epnum.number) |
321 | 335 | { |
322 | 336 | int epidx; |
323 | 337 | int ifidx; |
— | — | @@ -330,11 +344,18 @@ |
331 | 345 | { |
332 | 346 | if (!epnum.number) |
333 | 347 | { |
334 | | - // If this was EP0 IN, stall the pipe. There will only ever be one transfer for each |
335 | | - // SETUP transaction, and the next SETUP packet will clear the stall. |
336 | | - if (epnum.direction == USB_ENDPOINT_DIRECTION_IN) usb_set_stall(data, epnum, 1); |
337 | | - else if (!data->ep0_data_hook || !data->ep0_data_hook(data, data->buffer, 64 - bytesleft)) |
338 | | - usb_handle_ep0_data(data, data->buffer, 64 - bytesleft); |
| 348 | + bool (*callback)(const struct usb_instance* data, int size); |
| 349 | + if (epnum.direction == USB_ENDPOINT_DIRECTION_OUT) |
| 350 | + { |
| 351 | + callback = data->state->ep0_rx_callback; |
| 352 | + data->state->ep0_rx_callback = NULL; |
| 353 | + } |
| 354 | + else |
| 355 | + { |
| 356 | + callback = data->state->ep0_tx_callback; |
| 357 | + data->state->ep0_tx_callback = NULL; |
| 358 | + } |
| 359 | + if (callback) callback(data, bytesleft); |
339 | 360 | } |
340 | 361 | else |
341 | 362 | { |
— | — | @@ -346,16 +367,11 @@ |
347 | 368 | } |
348 | 369 | } |
349 | 370 | |
350 | | -void usb_handle_setup_received(const struct usb_instance* data, union usb_endpoint_number epnum, int back2back) |
| 371 | +void usb_handle_setup_received(const struct usb_instance* data, union usb_endpoint_number epnum) |
351 | 372 | { |
352 | 373 | if (!epnum.number) |
353 | 374 | { |
354 | | - // Figure out the location of the newest SETUP packet if there were |
355 | | - // multiple back to back ones. If there were more than 3 SETUP packets |
356 | | - // in a row, the OTG will take care of it, so we're on the safe side here. |
357 | | - void* addr = &data->buffer->raw[8 * (back2back - 1)]; |
358 | | - union usb_ep0_buffer* buffer = (union usb_ep0_buffer*)addr; |
359 | | - if (!data->ep0_setup_hook || !data->ep0_setup_hook(data, buffer)) usb_handle_ep0_setup(data, buffer); |
| 375 | + if (!data->ep0_setup_hook || !data->ep0_setup_hook(data, data->buffer)) usb_handle_ep0_setup(data, data->buffer); |
360 | 376 | } |
361 | 377 | else |
362 | 378 | { |
— | — | @@ -363,7 +379,7 @@ |
364 | 380 | int ifidx; |
365 | 381 | const struct usb_endpoint* endpoint = usb_find_endpoint(data, epnum, &epidx, &ifidx); |
366 | 382 | if (!endpoint) usb_unconfigure_ep(data, epnum); |
367 | | - else if (endpoint->setup_received) endpoint->setup_received(data, ifidx, epidx, back2back); |
| 383 | + else if (endpoint->setup_received) endpoint->setup_received(data, ifidx, epidx); |
368 | 384 | } |
369 | 385 | } |
370 | 386 | |
Index: umsboot/src/protocol/usb/usb.h |
— | — | @@ -194,7 +194,7 @@ |
195 | 195 | void (*xfer_complete)(const struct usb_instance* data, int interface, int endpoint, int bytesleft); |
196 | 196 | union __attribute__((packed)) |
197 | 197 | { |
198 | | - void (*setup_received)(const struct usb_instance* data, int interface, int endpoint, int back2back); |
| 198 | + void (*setup_received)(const struct usb_instance* data, int interface, int endpoint); |
199 | 199 | void (*timeout)(const struct usb_instance* data, int interface, int endpoint, int bytesleft); |
200 | 200 | }; |
201 | 201 | }; |
— | — | @@ -216,7 +216,7 @@ |
217 | 217 | int (*ctrl_request)(const struct usb_instance* data, int interface, union usb_ep0_buffer* request, const void** response); |
218 | 218 | uint8_t reserved1; |
219 | 219 | uint8_t reserved2; |
220 | | - uint8_t current_altsetting; |
| 220 | + uint8_t reserved3; |
221 | 221 | uint8_t altsetting_count; |
222 | 222 | const struct usb_altsetting* altsettings[]; |
223 | 223 | }; |
— | — | @@ -230,15 +230,18 @@ |
231 | 231 | uint8_t reserved2; |
232 | 232 | uint8_t reserved3; |
233 | 233 | uint8_t interface_count; |
234 | | - struct usb_interface* interfaces[]; |
| 234 | + const struct usb_interface* interfaces[]; |
235 | 235 | }; |
236 | 236 | |
237 | 237 | struct __attribute__((packed,aligned(4))) usb_state |
238 | 238 | { |
| 239 | + bool (*ep0_rx_callback)(const struct usb_instance* data, int bytesleft); |
| 240 | + bool (*ep0_tx_callback)(const struct usb_instance* data, int bytesleft); |
| 241 | + const void* ep0_tx_ptr; |
| 242 | + uint16_t ep0_tx_len; |
239 | 243 | uint8_t current_address; |
240 | 244 | uint8_t current_configuration; |
241 | | - uint8_t reserved1; |
242 | | - uint8_t reserved2; |
| 245 | + uint8_t interface_altsetting[]; |
243 | 246 | }; |
244 | 247 | |
245 | 248 | struct __attribute__((packed,aligned(4))) usb_driver |
— | — | @@ -267,7 +270,6 @@ |
268 | 271 | void (*bus_reset)(const struct usb_instance* data, int highspeed); |
269 | 272 | int (*ctrl_request)(const struct usb_instance* data, union usb_ep0_buffer* request, const void** response); |
270 | 273 | int (*ep0_setup_hook)(const struct usb_instance* data, union usb_ep0_buffer* buf); |
271 | | - int (*ep0_data_hook)(const struct usb_instance* data, union usb_ep0_buffer* buf, int size); |
272 | 274 | uint8_t configuration_count; |
273 | 275 | uint8_t stringdescriptor_count; |
274 | 276 | uint8_t reserved1; |
— | — | @@ -282,9 +284,9 @@ |
283 | 285 | extern void usb_handle_bus_reset(const struct usb_instance* data, int highspeed); |
284 | 286 | extern void usb_handle_timeout(const struct usb_instance* data, union usb_endpoint_number epnum, int bytesleft); |
285 | 287 | extern void usb_handle_xfer_complete(const struct usb_instance* data, union usb_endpoint_number epnum, int bytesleft); |
286 | | -extern void usb_handle_setup_received(const struct usb_instance* data, union usb_endpoint_number epnum, int back2back); |
287 | | -extern void usb_ep0_start_rx(const struct usb_instance* data, int non_setup); |
288 | | -extern void usb_ep0_start_tx(const struct usb_instance* data, const void* buf, int len); |
| 288 | +extern void usb_handle_setup_received(const struct usb_instance* data, union usb_endpoint_number epnum); |
| 289 | +extern void usb_ep0_start_rx(const struct usb_instance* data, int non_setup, bool (*callback)(const struct usb_instance* data, int bytesleft)); |
| 290 | +extern void usb_ep0_start_tx(const struct usb_instance* data, const void* buf, int len, bool last, bool (*callback)(const struct usb_instance* data, int bytesleft)); |
289 | 291 | extern void usb_ep0_expect_setup(const struct usb_instance* data); |
290 | 292 | extern void usb_start_rx(const struct usb_instance* data, union usb_endpoint_number ep, void* buf, int size); |
291 | 293 | extern void usb_start_tx(const struct usb_instance* data, union usb_endpoint_number ep, const void* buf, int size); |
Index: umsboot/src/core/synopsysotg/synopsysotg.c |
— | — | @@ -229,10 +229,6 @@ |
230 | 230 | const struct synopsysotg_config* data = (const struct synopsysotg_config*)instance->driver_config; |
231 | 231 | struct synopsysotg_state* state = (struct synopsysotg_state*)instance->driver_state; |
232 | 232 | |
233 | | - // If we don't expect a non-SETUP packet, we can stall the OUT pipe, |
234 | | - // SETUP packets will ignore that. |
235 | | - if (!non_setup) data->core->outep_regs[0].doepctl.b.stall = 1; |
236 | | - |
237 | 233 | // Set up data destination |
238 | 234 | if (data->use_dma) data->core->outep_regs[0].doepdma = instance->buffer; |
239 | 235 | else state->endpoints[0].rxaddr = (uint32_t*)instance->buffer; |
— | — | @@ -245,7 +241,7 @@ |
246 | 242 | // Enable the endpoint |
247 | 243 | union synopsysotg_depctl depctl = data->core->outep_regs[0].doepctl; |
248 | 244 | depctl.b.epena = 1; |
249 | | - depctl.b.cnak = 1; |
| 245 | + depctl.b.cnak = non_setup; |
250 | 246 | data->core->outep_regs[0].doepctl = depctl; |
251 | 247 | } |
252 | 248 | |
— | — | @@ -295,9 +291,6 @@ |
296 | 292 | union synopsysotg_depctl depctl = { .b = { .usbactep = 1, .nextep = data->core->inep_regs[0].diepctl.b.nextep } }; |
297 | 293 | data->core->outep_regs[0].doepctl = depctl; |
298 | 294 | data->core->inep_regs[0].diepctl = depctl; |
299 | | - |
300 | | - // Prime EP0 for the first setup packet. |
301 | | - usb_ep0_expect_setup(instance); |
302 | 295 | } |
303 | 296 | |
304 | 297 | void synopsysotg_irq(const struct usb_instance* instance) |
— | — | @@ -315,8 +308,8 @@ |
316 | 309 | |
317 | 310 | if (gintsts.b.enumdone) |
318 | 311 | { |
| 312 | + usb_handle_bus_reset(instance, data->core->dregs.dsts.b.enumspd == 0); |
319 | 313 | synopsysotg_ep0_init(instance); |
320 | | - usb_handle_bus_reset(instance, data->core->dregs.dsts.b.enumspd == 0); |
321 | 314 | } |
322 | 315 | |
323 | 316 | if (gintsts.b.rxstsqlvl) |
— | — | @@ -389,10 +382,8 @@ |
390 | 383 | if (epints.b.setup) |
391 | 384 | { |
392 | 385 | if (data->use_dma) invalidate_dcache(instance->buffer, sizeof(instance->buffer)); |
393 | | - union synopsysotg_dep0xfrsiz deptsiz = { .d32 = data->core->outep_regs[0].doeptsiz.d32 }; |
394 | | - int back2back = 3 - deptsiz.b.supcnt; |
395 | 386 | synopsysotg_flush_in_endpoint(instance, ep); |
396 | | - usb_handle_setup_received(instance, epnum, back2back); |
| 387 | + usb_handle_setup_received(instance, epnum); |
397 | 388 | } |
398 | 389 | else if (epints.b.xfercompl) |
399 | 390 | { |