Skip to content

Commit 22c828d

Browse files
jcbudacmaglie
authored andcommitted
update for USB, USB High Speed software, for betatest, need some improvment. USBCV not passed, USB3.0 passed
1 parent 656b83b commit 22c828d

File tree

4 files changed

+64
-55
lines changed

4 files changed

+64
-55
lines changed

Diff for: hardware/arduino/sam/cores/arduino/USB/CDC.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#ifdef CDC_ENABLED
2121

22-
#define CDC_SERIAL_BUFFER_SIZE 64
22+
#define CDC_SERIAL_BUFFER_SIZE 512
2323

2424
/* For information purpose only since RTS is not always handled by the terminal application */
2525
#define CDC_LINESTATE_DTR 0x01 // Data Terminal Ready
@@ -45,7 +45,13 @@ typedef struct
4545
uint8_t lineState;
4646
} LineInfo;
4747

48-
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
48+
static volatile LineInfo _usbLineInfo = {
49+
57600, // dWDTERate
50+
0x00, // bCharFormat
51+
0x00, // bParityType
52+
0x08, // bDataBits
53+
0x00 // lineState
54+
};
4955

5056
_Pragma("pack(1)")
5157
static const CDCDescriptor _cdcInterface =
@@ -62,8 +68,8 @@ static const CDCDescriptor _cdcInterface =
6268

6369
// CDC data interface
6470
D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0),
65-
D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,0x200,0),
66-
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x200,0)
71+
D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,512,0),
72+
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,512,0)
6773
};
6874
_Pragma("pack()")
6975

@@ -228,7 +234,6 @@ size_t Serial_::write(const uint8_t *buffer, size_t size)
228234

229235
if (r > 0)
230236
{
231-
USBD_Flush(CDC_TX);
232237
return r;
233238
} else
234239
{

Diff for: hardware/arduino/sam/cores/arduino/USB/USBCore.cpp

+42-34
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ static const uint32_t EndPoints[] =
2626
EP_TYPE_CONTROL,
2727

2828
#ifdef CDC_ENABLED
29-
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
30-
EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
3129
EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM
30+
EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
31+
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
3232
#endif
3333

3434
#ifdef HID_ENABLED
@@ -153,45 +153,42 @@ uint32_t USBD_Recv(uint32_t ep)
153153
}
154154

155155
// Space in send EP
156-
uint32_t USBD_SendSpace(uint32_t ep)
157-
{
158-
LockEP lock(ep);
159-
if (!UDD_ReadWriteAllowed(ep & 0xF))
160-
return 0;
161-
return 64 - UDD_FifoByteCount(ep & 0xF);
162-
}
156+
//uint32_t USBD_SendSpace(uint32_t ep)
157+
//{
158+
//LockEP lock(ep);
159+
//// if (!UDD_ReadWriteAllowed(ep & 0xF))
160+
////{
161+
////printf("pb "); // UOTGHS->UOTGHS_DEVEPTISR[%d]=0x%X\n\r", ep, UOTGHS->UOTGHS_DEVEPTISR[ep]);
162+
////return 0;
163+
////}
164+
165+
//if(ep==0) return 64 - UDD_FifoByteCount(ep & 0xF); // EP0_SIZE jcb
166+
//else return 512 - UDD_FifoByteCount(ep & 0xF); // EPX_SIZE jcb
167+
//}
163168

164169
// Blocking Send of data to an endpoint
165170
uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
166171
{
167-
if (!_usbConfiguration)
168-
return -1;
169-
172+
uint32_t n;
170173
int r = len;
171174
const uint8_t* data = (const uint8_t*)d;
172-
uint8_t timeout = 250; // 250ms timeout on send? TODO
175+
176+
if (!_usbConfiguration)
177+
{
178+
printf("pb conf\n\r");
179+
return -1;
180+
}
173181

174182
while (len)
175183
{
176-
uint8_t n = USBD_SendSpace(ep);
177-
if (n == 0)
178-
{
179-
if (!(--timeout))
180-
return -1;
181-
delay(1);
182-
continue;
183-
}
184-
184+
if(ep==0) n= EP0_SIZE;
185+
else n = EPX_SIZE;
185186
if (n > len)
186187
n = len;
187188
len -= n;
188189

189190
UDD_Send(ep & 0xF, data, n);
190-
191-
//if (!UDD_ReadWriteAllowed(ep & 0xF) || ((len == 0) && (ep & TRANSFER_RELEASE))){ // Release full buffer
192-
//UDD_ReleaseTX(ep & 0xF);
193-
//}
194-
}
191+
}
195192
//TXLED1; // light the TX LED
196193
//TxLEDPulse = TX_RX_LED_PULSE_MS;
197194
return r;
@@ -345,15 +342,24 @@ static bool USBD_SendDescriptor(Setup& setup)
345342
else if (USB_STRING_DESCRIPTOR_TYPE == t)
346343
{
347344
TRACE_CORE(puts("=> USBD_SendDescriptor : USB_STRING_DESCRIPTOR_TYPE\r\n");)
348-
if (setup.wValueL == 0)
345+
if (setup.wValueL == 0) {
349346
desc_addr = (const uint8_t*)&STRING_LANGUAGE;
350-
else if (setup.wValueL == IPRODUCT)
347+
printf("St1=%d\n\r", *desc_addr);
348+
}
349+
else if (setup.wValueL == IPRODUCT) {
351350
desc_addr = (const uint8_t*)&STRING_IPRODUCT;
352-
else if (setup.wValueL == IMANUFACTURER)
351+
printf("St2=%d\n\r", *desc_addr);
352+
}
353+
else if (setup.wValueL == IMANUFACTURER) {
353354
desc_addr = (const uint8_t*)&STRING_IMANUFACTURER;
355+
printf("St3=%d\n\r", *desc_addr);
356+
}
354357
else {
355358
return false;
356359
}
360+
if( *desc_addr > setup.wLength ) {
361+
desc_length = setup.wLength;
362+
}
357363
}
358364
else if (USB_DEVICE_QUALIFIER == t)
359365
{
@@ -386,10 +392,13 @@ static bool USBD_SendDescriptor(Setup& setup)
386392
return true;
387393
}
388394

395+
//unsigned int iii=0;
389396
// Endpoint 0 interrupt
390397
static void USB_ISR(void)
391398
{
392-
// End of Reset
399+
// printf("ISR=0x%X\n\r", UOTGHS->UOTGHS_DEVISR); // jcb
400+
// if( iii++ > 1500 ) while(1); // jcb
401+
// End of bus reset
393402
if (Is_udd_reset())
394403
{
395404
TRACE_CORE(printf(">>> End of Reset\r\n");)
@@ -422,14 +431,13 @@ static void USB_ISR(void)
422431
if (Is_udd_sof())
423432
{
424433
udd_ack_sof();
425-
// USBD_Flush(CDC_TX);
434+
// USBD_Flush(CDC_TX); // jcb
426435
}
427436
#endif
428437

429438
// EP 0 Interrupt
430-
if (Is_udd_endpoint_interrupt(0))
439+
if (Is_udd_endpoint_interrupt(0) )
431440
{
432-
433441
if (!UDD_ReceivedSetupInt())
434442
{
435443
return;

Diff for: hardware/arduino/sam/system/libsam/include/uotghs_device.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define MAX_ENDPOINTS 10
3535
#define EP0 0
3636
#define EP0_SIZE 64
37-
#define EPX_SIZE 1024
37+
#define EPX_SIZE 512
3838

3939
#define EP_SINGLE_64 (0x32UL) // EP0
4040
#define EP_DOUBLE_64 (0x36UL) // Other endpoints
@@ -116,7 +116,7 @@
116116
//! Get maximal number of banks of endpoints
117117
#define udd_get_endpoint_bank_max_nbr(ep) ((ep == 0) ? 1 : (( ep <= 2) ? 3 : 2))
118118
//! Get maximal size of endpoint (3X, 1024/64)
119-
#define udd_get_endpoint_size_max(ep) (((ep) == 0) ? 64 : 1024)
119+
#define udd_get_endpoint_size_max(ep) (((ep) == 0) ? 64 : 512) // for bulk
120120
//! Get DMA support of endpoints
121121
#define Is_udd_endpoint_dma_supported(ep) ((((ep) >= 1) && ((ep) <= 6)) ? true : false)
122122
//! Get High Band Width support of endpoints

Diff for: hardware/arduino/sam/system/libsam/source/uotghs_device.c

+10-14
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void UDD_Attach(void)
115115

116116
// Enable USB line events
117117
udd_enable_reset_interrupt();
118-
udd_enable_sof_interrupt();
118+
// udd_enable_sof_interrupt();
119119

120120
cpu_irq_restore(flags);
121121
}
@@ -139,6 +139,7 @@ void UDD_InitEP( uint32_t ul_ep_nb, uint32_t ul_ep_cfg )
139139

140140
if (!Is_udd_endpoint_configured(ul_ep_nb)) {
141141
TRACE_UOTGHS_DEVICE(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %lu\r\n", ul_ep_nb);)
142+
while(1);
142143
}
143144
}
144145

@@ -156,6 +157,7 @@ void UDD_InitEndpoints(const uint32_t* eps_table, const uint32_t ul_eps_table_si
156157

157158
if (!Is_udd_endpoint_configured(ul_ep_nb)) {
158159
TRACE_UOTGHS_DEVICE(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %lu\r\n", ul_ep_nb);)
160+
while(1);
159161
}
160162
}
161163
}
@@ -215,41 +217,35 @@ uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len)
215217

216218
TRACE_UOTGHS_DEVICE(printf("=> UDD_Send (1): ep=%lu ul_send_fifo_ptr=%lu len=%lu\r\n", ep, ul_send_fifo_ptr[ep], len);)
217219

220+
while( UOTGHS_DEVEPTISR_TXINI != (UOTGHS->UOTGHS_DEVEPTISR[ep] & UOTGHS_DEVEPTISR_TXINI )) {}
221+
218222
if (ep == EP0)
219223
{
220224
if (ul_send_fifo_ptr[ep] + len > EP0_SIZE)
221225
len = EP0_SIZE - ul_send_fifo_ptr[ep];
222226
}
223227
else
224228
{
225-
if (ul_send_fifo_ptr[ep] + len > EPX_SIZE)
226-
len = EPX_SIZE - ul_send_fifo_ptr[ep];
229+
ul_send_fifo_ptr[ep] = 0;
227230
}
228-
229231
for (i = 0, ptr_dest += ul_send_fifo_ptr[ep]; i < len; ++i)
230232
*ptr_dest++ = *ptr_src++;
231233

232234
ul_send_fifo_ptr[ep] += i;
233235

234-
235236
if (ep == EP0)
236237
{
237238
TRACE_UOTGHS_DEVICE(printf("=> UDD_Send (2): ep=%lu ptr_dest=%lu maxlen=%d\r\n", ep, ul_send_fifo_ptr[ep], EP0_SIZE);)
238239
if (ul_send_fifo_ptr[ep] == EP0_SIZE)
239240
{
240-
UDD_ClearIN(); // Fifo is full, release this packet
241-
UDD_WaitIN(); // Wait for new FIFO buffer to be ready
242-
}
241+
UDD_ClearIN(); // Fifo is full, release this packet // UOTGHS->UOTGHS_DEVEPTICR[EP0] = UOTGHS_DEVEPTICR_TXINIC;
242+
}
243243
}
244244
else
245245
{
246-
if (ul_send_fifo_ptr[ep] == EPX_SIZE)
247-
{
248-
UDD_ClearIN(); // Fifo is full, release this packet
249-
UDD_WaitIN(); // Wait for new FIFO buffer to be ready
250-
}
246+
UOTGHS->UOTGHS_DEVEPTICR[ep] = UOTGHS_DEVEPTICR_TXINIC;
247+
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
251248
}
252-
253249
return len;
254250
}
255251

0 commit comments

Comments
 (0)