Skip to content

Commit de5a139

Browse files
committed
[AVR] Fixed USB_SendControl for buffer size > 64
See arduino#4317
1 parent 376cb56 commit de5a139

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

hardware/arduino/avr/cores/arduino/USBCore.cpp

+12-22
Original file line numberDiff line numberDiff line change
@@ -425,31 +425,21 @@ static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len, uint8_t f
425425
}
426426

427427
// Does not timeout or cross fifo boundaries
428-
// Will only work for transfers <= 64 bytes
429-
// Use USB_RecvControlLong for longer transfers
430428
int USB_RecvControl(void* d, int len)
431429
{
432-
WaitOUT();
433-
Recv((u8*)d,len);
434-
ClearOUT();
435-
return len;
436-
}
437-
438-
// Does not timeout or cross fifo boundaries
439-
int USB_RecvControlLong(void* d, int len)
440-
{
441-
auto bytesleft = len;
442-
while(bytesleft > 0)
443-
{
444-
// Dont receive more than the USB Control EP has to offer
445-
// Use fixed 64 because control EP always have 64 bytes even on 16u2.
446-
auto recvLength = bytesleft;
447-
if(recvLength > 64){
448-
recvLength = 64;
430+
uint8_t *buff = (uint8_t *)d;
431+
int remaining = len;
432+
while (remaining > 0) {
433+
WaitOUT();
434+
if (remaining > 64) {
435+
Recv(buff, 64);
436+
buff += 64;
437+
remaining -= 64;
438+
} else {
439+
Recv(buff, remaining);
440+
remaining = 0;
449441
}
450-
451-
// Write data to fit to the beginning of the array
452-
bytesleft -= USB_RecvControl((u8*)d + len - bytesleft, recvLength);
442+
ClearOUT();
453443
}
454444
return len;
455445
}

0 commit comments

Comments
 (0)