Skip to content

Commit 90d2f80

Browse files
facchinmcmaglie
authored andcommitted
USB: fix CDC endpoints
* fix in_endpoint buffer size (was too big) * use the same EP for CDC_ENDPOINT_OUT and CDC_ENDPOINT_IN (different buffers) * fix CDC_ENDPOINT_IN ep type
1 parent 3ddf463 commit 90d2f80

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

cores/arduino/USB/USBCore.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ const DeviceDescriptor USB_DeviceDescriptor = D_DEVICE(0x00, 0x00, 0x00, 64, USB
6868
volatile uint32_t _usbConfiguration = 0;
6969
volatile uint32_t _usbSetInterface = 0;
7070

71-
static __attribute__((__aligned__(4))) /*__attribute__((__section__(".bss_hram0")))*/
71+
static __attribute__((__aligned__(8))) //__attribute__((__section__(".bss_hram0")))
7272
uint8_t udd_ep_out_cache_buffer[4][64];
7373

74-
static __attribute__((__aligned__(4))) /*__attribute__((__section__(".bss_hram0")))*/
75-
uint8_t udd_ep_in_cache_buffer[4][128];
74+
static __attribute__((__aligned__(8))) //__attribute__((__section__(".bss_hram0")))
75+
uint8_t udd_ep_in_cache_buffer[4][64];
7676

7777
//==================================================================
7878

@@ -375,7 +375,7 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
375375
{
376376
if (config == (USB_ENDPOINT_TYPE_INTERRUPT | USB_ENDPOINT_IN(0)))
377377
{
378-
usbd.epBank1SetSize(ep, 8);
378+
usbd.epBank1SetSize(ep, 64);
379379
usbd.epBank1SetAddress(ep, &udd_ep_in_cache_buffer[ep]);
380380
usbd.epBank1SetType(ep, 4); // INTERRUPT IN
381381
}
@@ -580,7 +580,13 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
580580
if (!_usbConfiguration)
581581
return -1;
582582

583-
armSend(ep, data, len);
583+
//armSend(ep, data, len);
584+
585+
/* memcopy could be safer in multithreaded environment */
586+
memcpy(&udd_ep_in_cache_buffer[ep], data, len);
587+
588+
usbd.epBank1SetAddress(ep, &udd_ep_in_cache_buffer[ep]);
589+
usbd.epBank1SetByteCount(ep, len);
584590

585591
// Clear the transfer complete flag
586592
usbd.epBank1AckTransferComplete(ep);
@@ -712,9 +718,9 @@ bool USBDeviceClass::handleStandardSetup(Setup &setup)
712718
#endif
713719

714720
#if defined(CDC_ENABLED)
715-
initEP(CDC_ENDPOINT_ACM, USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN(0));
721+
initEP(CDC_ENDPOINT_ACM, USB_ENDPOINT_TYPE_INTERRUPT | USB_ENDPOINT_IN(0));
716722
initEP(CDC_ENDPOINT_OUT, USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_OUT(0));
717-
initEP(CDC_ENDPOINT_IN, USB_ENDPOINT_TYPE_INTERRUPT | USB_ENDPOINT_IN(0));
723+
initEP(CDC_ENDPOINT_IN, USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN(0));
718724
#endif
719725
_usbConfiguration = setup.wValueL;
720726

cores/arduino/USB/USBDesc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
#define CDC_DATA_INTERFACE 1 // CDC Data
2929
#define CDC_ENDPOINT_ACM 1
3030
#define CDC_ENDPOINT_OUT 2
31-
#define CDC_ENDPOINT_IN 3
31+
#define CDC_ENDPOINT_IN 2
3232

3333
// HID
3434
#define HID_INTERFACE 2 // HID
35-
#define HID_ENDPOINT_INT 4
35+
#define HID_ENDPOINT_INT 3
3636

3737
// Defined string description
3838
#define IMANUFACTURER 1

0 commit comments

Comments
 (0)