Skip to content

Commit a8d208a

Browse files
cmagliefacchinm
authored andcommitted
USBDevice: interrupts are now enabled on init
This change allow to rationalize EP initalization logic in one single place.
1 parent 8ac782d commit a8d208a

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

cores/arduino/USB/CDC.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
#ifdef CDC_ENABLED
2929

30-
extern USBDevice_SAMD21G18x usbd;
31-
3230
#define CDC_SERIAL_BUFFER_SIZE 256
3331

3432
/* For information purpose only since RTS is not always handled by the terminal application */
@@ -186,11 +184,6 @@ Serial_::Serial_(USBDeviceClass &_usb) : PluggableUSBModule(3, 2, epType), usb(_
186184
PluggableUSB().plug(this);
187185
}
188186

189-
void Serial_::enableInterrupt() {
190-
usbd.epBank1EnableTransferComplete(CDC_ENDPOINT_ACM);
191-
usbd.epBank0EnableTransferComplete(CDC_ENDPOINT_OUT);
192-
}
193-
194187
void Serial_::begin(uint32_t /* baud_count */)
195188
{
196189
// uart config is ignored in USB-CDC

cores/arduino/USB/CDC.h

-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ class Serial_ : public Stream, public PluggableUSBModule {
143143
bool setup(USBSetup& setup);
144144
uint8_t getShortName(char* name);
145145
void handleEndpoint(int ep);
146-
void enableInterrupt();
147146

148147
friend USBDeviceClass;
149148

cores/arduino/USB/USBCore.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
394394
usbd.epBank1SetSize(ep, 64);
395395
usbd.epBank1SetAddress(ep, &udd_ep_in_cache_buffer[ep]);
396396
usbd.epBank1SetType(ep, 4); // INTERRUPT IN
397+
usbd.epBank1EnableTransferComplete(ep);
397398
}
398399
else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_OUT(0)))
399400
{
@@ -411,6 +412,9 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
411412
usbd.epBank1ResetReady(ep);
412413

413414
usbd.epBank1SetType(ep, 3); // BULK IN
415+
416+
// XXX: this somehow interfere with CDC rx - WHY???
417+
// usbd.epBank1EnableTransferComplete(ep);
414418
}
415419
else if (config == USB_ENDPOINT_TYPE_CONTROL)
416420
{
@@ -426,6 +430,9 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
426430

427431
// Release OUT EP
428432
usbd.epReleaseOutBank0(ep, 64);
433+
434+
// Enable Setup-Received interrupt
435+
usbd.epBank0EnableSetupReceived(ep);
429436
}
430437
}
431438

@@ -763,10 +770,6 @@ bool USBDeviceClass::handleStandardSetup(USBSetup &setup)
763770
initEndpoints();
764771
_usbConfiguration = setup.wValueL;
765772

766-
#ifdef CDC_ENABLED
767-
SerialUSB.enableInterrupt();
768-
#endif
769-
770773
sendZlp(0);
771774
return true;
772775
} else {
@@ -801,9 +804,6 @@ void USBDeviceClass::ISRHandler()
801804
// Configure EP 0
802805
initEP(0, USB_ENDPOINT_TYPE_CONTROL);
803806

804-
// Enable Setup-Received interrupt
805-
usbd.epBank0EnableSetupReceived(0);
806-
807807
_usbConfiguration = 0;
808808
}
809809

0 commit comments

Comments
 (0)