Skip to content

Commit 656b83b

Browse files
jcbudacmaglie
authored andcommitted
correct CDC transmit, add device qualifier.
1 parent 9a505d2 commit 656b83b

File tree

4 files changed

+104
-17
lines changed

4 files changed

+104
-17
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ static const CDCDescriptor _cdcInterface =
5858
D_CDCCS(CDC_CALL_MANAGEMENT,1,1), // Device handles call management (not)
5959
D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,6), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
6060
D_CDCCS(CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
61-
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x40),
61+
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x10/*0x40*/),
6262

6363
// CDC data interface
6464
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,0x40,0),
66-
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,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)
6767
};
6868
_Pragma("pack()")
6969

@@ -227,7 +227,8 @@ size_t Serial_::write(const uint8_t *buffer, size_t size)
227227
int r = USBD_Send(CDC_TX, buffer, size);
228228

229229
if (r > 0)
230-
{
230+
{
231+
USBD_Flush(CDC_TX);
231232
return r;
232233
} else
233234
{

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

+89-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ static const uint32_t EndPoints[] =
4040
#define TX_RX_LED_PULSE_MS 100
4141
volatile uint8_t TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
4242
volatile uint8_t RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
43-
43+
static char isRemoteWakeUpEnabled = 0;
44+
static char isEndpointHalt = 0;
4445
//==================================================================
4546
//==================================================================
4647

@@ -86,6 +87,10 @@ const DeviceDescriptor USB_DeviceDescriptor =
8687
const DeviceDescriptor USB_DeviceDescriptorA =
8788
D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
8889

90+
const DeviceDescriptor USB_DeviceQualifier =
91+
D_QUALIFIER(0x00,0x00,0x00,64,1);
92+
93+
8994
//==================================================================
9095
//==================================================================
9196

@@ -183,8 +188,9 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
183188

184189
UDD_Send(ep & 0xF, data, n);
185190

186-
if (!UDD_ReadWriteAllowed(ep & 0xF) || ((len == 0) && (ep & TRANSFER_RELEASE))) // Release full buffer
187-
UDD_ReleaseTX(ep & 0xF);
191+
//if (!UDD_ReadWriteAllowed(ep & 0xF) || ((len == 0) && (ep & TRANSFER_RELEASE))){ // Release full buffer
192+
//UDD_ReleaseTX(ep & 0xF);
193+
//}
188194
}
189195
//TXLED1; // light the TX LED
190196
//TxLEDPulse = TX_RX_LED_PULSE_MS;
@@ -345,9 +351,24 @@ static bool USBD_SendDescriptor(Setup& setup)
345351
desc_addr = (const uint8_t*)&STRING_IPRODUCT;
346352
else if (setup.wValueL == IMANUFACTURER)
347353
desc_addr = (const uint8_t*)&STRING_IMANUFACTURER;
348-
else
354+
else {
349355
return false;
356+
}
350357
}
358+
else if (USB_DEVICE_QUALIFIER == t)
359+
{
360+
// Device qualifier descriptor requested
361+
desc_addr = (const uint8_t*)&USB_DeviceQualifier;
362+
}
363+
else if (USB_OTHER_SPEED_CONFIGURATION == t)
364+
{
365+
// TODO
366+
// Other configuration descriptor requested
367+
}
368+
else
369+
{
370+
//printf("Device ERROR");
371+
}
351372

352373
if (desc_addr == 0)
353374
{
@@ -401,7 +422,7 @@ static void USB_ISR(void)
401422
if (Is_udd_sof())
402423
{
403424
udd_ack_sof();
404-
USBD_Flush(CDC_TX);
425+
// USBD_Flush(CDC_TX);
405426
}
406427
#endif
407428

@@ -437,15 +458,70 @@ static void USB_ISR(void)
437458
uint8_t r = setup.bRequest;
438459
if (GET_STATUS == r)
439460
{
440-
TRACE_CORE(puts(">>> EP0 Int: GET_STATUS\r\n");)
441-
UDD_Send8(EP0, 0); // TODO
442-
UDD_Send8(EP0, 0);
461+
if( setup.bmRequestType == 0 ) // device
462+
{
463+
// Send the device status
464+
TRACE_CORE(puts(">>> EP0 Int: GET_STATUS\r\n");)
465+
// Check current configuration for power mode (if device is configured)
466+
// TODO
467+
// Check if remote wake-up is enabled
468+
// TODO
469+
UDD_Send8(EP0, 0); // TODO
470+
UDD_Send8(EP0, 0);
471+
}
472+
// if( setup.bmRequestType == 2 ) // Endpoint:
473+
else
474+
{
475+
// Send the endpoint status
476+
// Check if the endpoint if currently halted
477+
if( isEndpointHalt == 1 )
478+
UDD_Send8(EP0, 1); // TODO
479+
else
480+
UDD_Send8(EP0, 0); // TODO
481+
UDD_Send8(EP0, 0);
482+
}
443483
}
444484
else if (CLEAR_FEATURE == r)
445485
{
446-
}
486+
// Check which is the selected feature
487+
if( setup.wValueL == 1) // DEVICEREMOTEWAKEUP
488+
{
489+
// Enable remote wake-up and send a ZLP
490+
if( isRemoteWakeUpEnabled == 1 )
491+
UDD_Send8(EP0, 1);
492+
else
493+
UDD_Send8(EP0, 0);
494+
UDD_Send8(EP0, 0);
495+
}
496+
else // if( setup.wValueL == 0) // ENDPOINTHALT
497+
{
498+
isEndpointHalt = 0; // TODO
499+
UDD_Send8(EP0, 0);
500+
UDD_Send8(EP0, 0);
501+
}
502+
503+
}
447504
else if (SET_FEATURE == r)
448505
{
506+
// Check which is the selected feature
507+
if( setup.wValueL == 1) // DEVICEREMOTEWAKEUP
508+
{
509+
// Enable remote wake-up and send a ZLP
510+
isRemoteWakeUpEnabled = 1;
511+
UDD_Send8(EP0, 0);
512+
}
513+
if( setup.wValueL == 0) // ENDPOINTHALT
514+
{
515+
// Halt endpoint
516+
isEndpointHalt = 1;
517+
//USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest));
518+
UDD_Send8(EP0, 0);
519+
}
520+
if( setup.wValueL == 2) // TEST_MODE
521+
{
522+
// 7.1.20 Test Mode Support, 9.4.9 SetFeature
523+
// TODO
524+
}
449525
}
450526
else if (SET_ADDRESS == r)
451527
{
@@ -466,7 +542,7 @@ static void USB_ISR(void)
466542
else if (GET_CONFIGURATION == r)
467543
{
468544
TRACE_CORE(puts(">>> EP0 Int: GET_CONFIGURATION\r\n");)
469-
UDD_Send8(EP0, 1);
545+
UDD_Send8(EP0, _usbConfiguration);
470546
}
471547
else if (SET_CONFIGURATION == r)
472548
{
@@ -491,10 +567,13 @@ static void USB_ISR(void)
491567
}
492568
else if (GET_INTERFACE == r)
493569
{
570+
// TODO
494571
TRACE_CORE(puts(">>> EP0 Int: GET_INTERFACE\r\n");)
572+
UDD_Send8(EP0, setup.wIndex);
495573
}
496574
else if (SET_INTERFACE == r)
497575
{
576+
// TODO
498577
TRACE_CORE(puts(">>> EP0 Int: SET_INTERFACE\r\n");)
499578
}
500579
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
#define USB_STRING_DESCRIPTOR_TYPE 3
7878
#define USB_INTERFACE_DESCRIPTOR_TYPE 4
7979
#define USB_ENDPOINT_DESCRIPTOR_TYPE 5
80+
#define USB_DEVICE_QUALIFIER 6
81+
#define USB_OTHER_SPEED_CONFIGURATION 7
8082

8183
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
8284
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
@@ -291,6 +293,9 @@ _Pragma("pack()")
291293
#define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \
292294
{ 7, 5, _addr,_attr,_packetSize, _interval }
293295

296+
#define D_QUALIFIER(_class,_subClass,_proto,_packetSize0,_configs) \
297+
{ 10, 6, 0x200, _class,_subClass,_proto,_packetSize0,_configs }
298+
294299
#define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \
295300
{ 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 }
296301

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ uint32_t UDD_Init(void)
8585

8686
// Enable High Speed
8787
udd_low_speed_disable();
88-
udd_high_speed_disable();
88+
udd_high_speed_enable();
8989

9090
//otg_ack_vbus_transition();
9191
// Force Vbus interrupt in case of Vbus always with a high level
@@ -301,15 +301,17 @@ uint32_t UDD_FifoByteCount(uint32_t ep)
301301
void UDD_ReleaseRX(uint32_t ep)
302302
{
303303
TRACE_UOTGHS_DEVICE(puts("=> UDD_ReleaseRX\r\n");)
304-
UOTGHS->UOTGHS_DEVEPTICR[ep] = (UOTGHS_DEVEPTICR_NAKOUTIC | UOTGHS_DEVEPTICR_RXOUTIC);
304+
// UOTGHS->UOTGHS_DEVEPTICR[ep] = (UOTGHS_DEVEPTICR_NAKOUTIC | UOTGHS_DEVEPTICR_RXOUTIC);
305+
UOTGHS->UOTGHS_DEVEPTICR[ep] = UOTGHS_DEVEPTICR_RXOUTIC;
305306
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
306307
ul_recv_fifo_ptr[ep] = 0;
307308
}
308309

309310
void UDD_ReleaseTX(uint32_t ep)
310311
{
311312
TRACE_UOTGHS_DEVICE(printf("=> UDD_ReleaseTX ep=%lu\r\n", ep);)
312-
UOTGHS->UOTGHS_DEVEPTICR[ep] = (UOTGHS_DEVEPTICR_NAKINIC | UOTGHS_DEVEPTICR_RXOUTIC | UOTGHS_DEVEPTICR_TXINIC);
313+
// UOTGHS->UOTGHS_DEVEPTICR[ep] = (UOTGHS_DEVEPTICR_NAKINIC | UOTGHS_DEVEPTICR_RXOUTIC | UOTGHS_DEVEPTICR_TXINIC);
314+
UOTGHS->UOTGHS_DEVEPTICR[ep] = UOTGHS_DEVEPTICR_TXINIC;
313315
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
314316
ul_send_fifo_ptr[ep] = 0;
315317
}

0 commit comments

Comments
 (0)