Skip to content

[AVR] Fixed USB_SendControl for buffer size > 64 #4325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions hardware/arduino/avr/cores/arduino/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,31 +425,21 @@ static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len, uint8_t f
}

// Does not timeout or cross fifo boundaries
// Will only work for transfers <= 64 bytes
// Use USB_RecvControlLong for longer transfers
int USB_RecvControl(void* d, int len)
{
WaitOUT();
Recv((u8*)d,len);
ClearOUT();
return len;
}

// Does not timeout or cross fifo boundaries
int USB_RecvControlLong(void* d, int len)
{
auto bytesleft = len;
while(bytesleft > 0)
{
// Dont receive more than the USB Control EP has to offer
// Use fixed 64 because control EP always have 64 bytes even on 16u2.
auto recvLength = bytesleft;
if(recvLength > 64){
recvLength = 64;
uint8_t *buff = (uint8_t *)d;
int remaining = len;
while (remaining > 0) {
WaitOUT();
if (remaining > 64) {
Recv(buff, 64);
buff += 64;
remaining -= 64;
} else {
Recv(buff, remaining);
remaining = 0;
}

// Write data to fit to the beginning of the array
bytesleft -= USB_RecvControl((u8*)d + len - bytesleft, recvLength);
ClearOUT();
}
return len;
}
Expand Down