Skip to content

Commit 9d0d5d6

Browse files
facchinmcmaglie
authored andcommitted
fix back-to-back SerialUSB test
1 parent 90d2f80 commit 9d0d5d6

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

cores/arduino/USB/CDC.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#ifdef CDC_ENABLED
2727

28-
#define CDC_SERIAL_BUFFER_SIZE 64
28+
#define CDC_SERIAL_BUFFER_SIZE 256
2929

3030
/* For information purpose only since RTS is not always handled by the terminal application */
3131
#define CDC_LINESTATE_DTR 0x01 // Data Terminal Ready
@@ -175,9 +175,12 @@ void Serial_::accept(void)
175175
int Serial_::available(void)
176176
{
177177
ring_buffer *buffer = &cdc_rx_buffer;
178-
if (buffer->full)
178+
if (buffer->full) {
179+
USB->DEVICE.DeviceEndpoint[2].EPINTENSET.reg = ~USB_DEVICE_EPINTENCLR_RXSTP;
179180
return CDC_SERIAL_BUFFER_SIZE;
181+
}
180182
if (buffer->head == buffer->tail) {
183+
USB->DEVICE.DeviceEndpoint[2].EPINTENSET.reg = USB_DEVICE_EPINTENCLR_RXSTP;
181184
USB->DEVICE.DeviceEndpoint[2].EPINTENSET.reg = USB_DEVICE_EPINTENCLR_TRCPT(1);
182185
}
183186
return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % CDC_SERIAL_BUFFER_SIZE;

cores/arduino/USB/USBCore.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ 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__(8))) //__attribute__((__section__(".bss_hram0")))
71+
static __attribute__((__aligned__(4))) //__attribute__((__section__(".bss_hram0")))
7272
uint8_t udd_ep_out_cache_buffer[4][64];
7373

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

7777
//==================================================================
@@ -502,17 +502,19 @@ uint32_t USBDeviceClass::recv(uint32_t ep, void *_data, uint32_t len)
502502
// NAK on endpoint OUT, the bank is full.
503503
//usbd.epBank0SetReady(CDC_ENDPOINT_OUT);
504504

505-
uint8_t *buffer = udd_ep_out_cache_buffer[ep];
506-
uint8_t *data = reinterpret_cast<uint8_t *>(_data);
507-
for (uint32_t i=0; i<len; i++) {
508-
data[i] = buffer[i];
509-
}
505+
memcpy(_data, udd_ep_out_cache_buffer[ep], len);
506+
507+
// uint8_t *buffer = udd_ep_out_cache_buffer[ep];
508+
// uint8_t *data = reinterpret_cast<uint8_t *>(_data);
509+
// for (uint32_t i=0; i<len; i++) {
510+
// data[i] = buffer[i];
511+
// }
510512

511513
// release empty buffer
512514
if (len && !available(ep)) {
513515
// The RAM Buffer is empty: we can receive data
514516
usbd.epBank0ResetReady(ep);
515-
517+
516518
// Clear Transfer complete 0 flag
517519
usbd.epBank0AckTransferComplete(ep);
518520
}
@@ -553,9 +555,9 @@ uint8_t USBDeviceClass::armRecvCtrlOUT(uint32_t ep, uint32_t len)
553555

554556
uint8_t USBDeviceClass::armRecv(uint32_t ep, uint32_t len)
555557
{
556-
usbd.epBank0SetSize(ep, 64);
557-
usbd.epBank0SetAddress(ep, &udd_ep_out_cache_buffer[ep]);
558-
usbd.epBank0SetMultiPacketSize(ep, 64); // XXX: Should be "len"?
558+
//usbd.epBank0SetSize(ep, 64);
559+
//usbd.epBank0SetAddress(ep, &udd_ep_out_cache_buffer[ep]);
560+
//usbd.epBank0SetMultiPacketSize(ep, 64); // XXX: Should be "len"?
559561
uint16_t count = usbd.epBank0ByteCount(ep);
560562
if (count >= 64) {
561563
usbd.epBank0SetByteCount(ep, count - 64);

0 commit comments

Comments
 (0)