@@ -262,9 +262,6 @@ void USBDeviceClass::handleEndpoint(uint8_t ep)
262262#if defined(CDC_ENABLED)
263263 if (ep == CDC_ENDPOINT_OUT)
264264 {
265- // The RAM Buffer is empty: we can receive data
266- // usbd.epBank0ResetReady(CDC_ENDPOINT_OUT);
267-
268265 // Handle received bytes
269266 if (available (CDC_ENDPOINT_OUT))
270267 Serial.accept ();
@@ -463,10 +460,6 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
463460 }
464461 else if (config == USB_ENDPOINT_TYPE_CONTROL)
465462 {
466- // XXX: Needed?
467- // usbd.epBank0DisableAutoZLP(ep);
468- // usbd.epBank1DisableAutoZLP(ep);
469-
470463 // Setup Control OUT
471464 usbd.epBank0SetSize (ep, 64 );
472465 usbd.epBank0SetAddress (ep, &udd_ep_out_cache_buffer[ep]);
@@ -614,46 +607,14 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep)
614607// Blocking Send of data to an endpoint
615608uint32_t USBDeviceClass::send (uint32_t ep, const void *data, uint32_t len)
616609{
610+ uint32_t written = 0 ;
617611 uint32_t length = 0 ;
618612
619613 if (!_usbConfiguration)
620614 return -1 ;
621615 if (len > 16384 )
622616 return -1 ;
623617
624- #if 0
625- // This shortcut has some issues:
626- // - sometimes it fails when sending an odd number of bytes (may be
627- // due to memory alignment?)
628- // - the data pointer should point to "stable" data (and this is not
629- // guaranteed by caller, it may be some sort of temporary buffer)
630- // - the SRAM is not guaranteed to start at 0x20000000
631-
632- // All the above problems must be properly fixed before reenabling
633- // this part
634-
635- if ((unsigned int)data > 0x20000000)
636- {
637- // Buffer in RAM
638- usbd.epBank1SetAddress(ep, (void *)data);
639- usbd.epBank1SetMultiPacketSize(ep, 0);
640-
641- usbd.epBank1SetByteCount(ep, len);
642-
643- // Clear the transfer complete flag
644- usbd.epBank1AckTransferComplete(ep);
645-
646- // RAM buffer is full, we can send data (IN)
647- usbd.epBank1SetReady(ep);
648-
649- // Wait for transfer to complete
650- while (!usbd.epBank1IsTransferComplete(ep)) {
651- ; // need fire exit.
652- }
653- return 0;
654- }
655- #endif
656-
657618#ifdef PIN_LED_TXL
658619 digitalWrite (PIN_LED_TXL, LOW);
659620 txLEDPulse = TX_RX_LED_PULSE_MS;
@@ -684,10 +645,11 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
684645 while (!usbd.epBank1IsTransferComplete (ep)) {
685646 ; // need fire exit.
686647 }
648+ written += length;
687649 len -= length;
688650 data = (char *)data + length;
689651 }
690- return len ;
652+ return written ;
691653}
692654
693655uint32_t USBDeviceClass::armSend (uint32_t ep, const void * data, uint32_t len)
0 commit comments