Skip to content

Always call new DoubleBufferedEPOutHandler on reconnect #352

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

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions cores/arduino/USB/SAMD21_USBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ class DoubleBufferedEPOutHandler : public EPHandler {
release();
}

~DoubleBufferedEPOutHandler() {
free((void*)data0);
free((void*)data1);
}

virtual uint32_t recv(void *_data, uint32_t len)
{
uint8_t *data = reinterpret_cast<uint8_t *>(_data);
Expand Down
7 changes: 4 additions & 3 deletions cores/arduino/USB/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ uint8_t udd_ep_in_cache_buffer[7][64];
// Some EP are handled using EPHanlders.
// Possibly all the sparse EP handling subroutines will be
// converted into reusable EPHandlers in the future.
static EPHandler *epHandlers[7];
static EPHandler *epHandlers[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};

//==================================================================

Expand Down Expand Up @@ -454,9 +454,10 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
}
else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_OUT(0)))
{
if (epHandlers[ep] == NULL) {
epHandlers[ep] = new DoubleBufferedEPOutHandler(usbd, ep, 256);
if (epHandlers[ep] != NULL) {
delete (DoubleBufferedEPOutHandler*)epHandlers[ep];
}
epHandlers[ep] = new DoubleBufferedEPOutHandler(usbd, ep, 256);
}
else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN(0)))
{
Expand Down