Привожу дескриптор конфигурации:
CODE
0x09, 0x02, VIRTUAL_COM_PORT_SIZ_CONFIG_DESC, 0x00, 0x03, 0x01, 0x00, 0x80, 0x32, // Config
// MIDI
0x09, 0x04, 0x00, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, // Interface 1
0x07, 0x24, 0x01, 0x00, 0x01, 0x41, 0x00, // CS Interface (midi)
0x06, 0x24, 0x02, 0x01, 0x01, 0x00, // IN Jack 1 (emb)
0x06, 0x24, 0x02, 0x02, 0x02, 0x00, // IN Jack 2 (ext)
0x09, 0x24, 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, // OUT Jack 3 (emb)
0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x01, 0x01, 0x00, // OUT Jack 4 (ext)
0x09, 0x05, 0x01, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, // Endpoint OUT
0x05, 0x25, 0x01, 0x01, 0x01, // CS EP IN Jack
0x09, 0x05, 0x81, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, // Endpoint IN
0x05, 0x25, 0x01, 0x01, 0x03,
0x08, /*length*/
0x0B, /*Interface association descriptor type*/
0x01, /*The first associated interface */
0x02, /*Number of continuous associated interface*/
0x02, /*bInterfaceClass of the first interface*/
0x02, /*bInterfaceSubclass of the first interface*/
0x02, /*bInterfaceProtocol of the first interface*/
0x00, /*Interface string index*/
/*Interface Descriptor*/
0x09, /* bLength: Interface Descriptor size */
USB_DESCRIPTOR_INTERFACE_TYPE, /* bDescriptorType: Interface */
/* Interface descriptor type */
0x01, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x01, /* bNumEndpoints: One endpoints used */
0x02, /* bInterfaceClass: Communication Interface Class */
0x02, /* bInterfaceSubClass: Abstract Control Model */
0x01, /* bInterfaceProtocol: Common AT commands */
0x00, /* iInterface: */
/*Header Functional Descriptor*/
0x05, /* bLength: Endpoint Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x00, /* bDescriptorSubtype: Header Func Desc */
0x10, /* bcdCDC: spec release number */
0x01,
/*Call Management Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x01, /* bDescriptorSubtype: Call Management Func Desc */
0x00, /* bmCapabilities: D0+D1 */
0x01, /* bDataInterface: 1 */
/*ACM Functional Descriptor*/
0x04, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
0x02, /* bmCapabilities */
/*Union Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x06, /* bDescriptorSubtype: Union func desc */
0x00, /* bMasterInterface: Communication class interface */
0x01, /* bSlaveInterface0: Data Class Interface */
/*Endpoint 2 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_ENDPOINT_TYPE, /* bDescriptorType: Endpoint */
0x82, /* bEndpointAddress: (IN2) */
0x03, /* bmAttributes: Interrupt */
0x08, /* wMaxPacketSize: */
0x00,
0xFF, /* bInterval: */
/*Data class interface descriptor*/
0x09, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_INTERFACE_TYPE, /* bDescriptorType: */
0x02, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints: Two endpoints used */
0x0A, /* bInterfaceClass: CDC */
0x00, /* bInterfaceSubClass: */
0x00, /* bInterfaceProtocol: */
0x00, /* iInterface: */
/*Endpoint 3 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_ENDPOINT_TYPE, /* bDescriptorType: Endpoint */
0x03, /* bEndpointAddress: (OUT3) */
0x02, /* bmAttributes: Bulk */
0x40, /* wMaxPacketSize: */
0x00,
0x00, /* bInterval: ignore for Bulk transfer */
/*Endpoint 1 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_ENDPOINT_TYPE, /* bDescriptorType: Endpoint */
0x83, /* bEndpointAddress: (IN3) */
0x02, /* bmAttributes: Bulk */
0x40, /* wMaxPacketSize: */
0x00,
0x00, /* bInterval */
// MIDI
0x09, 0x04, 0x00, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, // Interface 1
0x07, 0x24, 0x01, 0x00, 0x01, 0x41, 0x00, // CS Interface (midi)
0x06, 0x24, 0x02, 0x01, 0x01, 0x00, // IN Jack 1 (emb)
0x06, 0x24, 0x02, 0x02, 0x02, 0x00, // IN Jack 2 (ext)
0x09, 0x24, 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, // OUT Jack 3 (emb)
0x09, 0x24, 0x03, 0x02, 0x04, 0x01, 0x01, 0x01, 0x00, // OUT Jack 4 (ext)
0x09, 0x05, 0x01, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, // Endpoint OUT
0x05, 0x25, 0x01, 0x01, 0x01, // CS EP IN Jack
0x09, 0x05, 0x81, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, // Endpoint IN
0x05, 0x25, 0x01, 0x01, 0x03,
0x08, /*length*/
0x0B, /*Interface association descriptor type*/
0x01, /*The first associated interface */
0x02, /*Number of continuous associated interface*/
0x02, /*bInterfaceClass of the first interface*/
0x02, /*bInterfaceSubclass of the first interface*/
0x02, /*bInterfaceProtocol of the first interface*/
0x00, /*Interface string index*/
/*Interface Descriptor*/
0x09, /* bLength: Interface Descriptor size */
USB_DESCRIPTOR_INTERFACE_TYPE, /* bDescriptorType: Interface */
/* Interface descriptor type */
0x01, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x01, /* bNumEndpoints: One endpoints used */
0x02, /* bInterfaceClass: Communication Interface Class */
0x02, /* bInterfaceSubClass: Abstract Control Model */
0x01, /* bInterfaceProtocol: Common AT commands */
0x00, /* iInterface: */
/*Header Functional Descriptor*/
0x05, /* bLength: Endpoint Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x00, /* bDescriptorSubtype: Header Func Desc */
0x10, /* bcdCDC: spec release number */
0x01,
/*Call Management Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x01, /* bDescriptorSubtype: Call Management Func Desc */
0x00, /* bmCapabilities: D0+D1 */
0x01, /* bDataInterface: 1 */
/*ACM Functional Descriptor*/
0x04, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
0x02, /* bmCapabilities */
/*Union Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x06, /* bDescriptorSubtype: Union func desc */
0x00, /* bMasterInterface: Communication class interface */
0x01, /* bSlaveInterface0: Data Class Interface */
/*Endpoint 2 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_ENDPOINT_TYPE, /* bDescriptorType: Endpoint */
0x82, /* bEndpointAddress: (IN2) */
0x03, /* bmAttributes: Interrupt */
0x08, /* wMaxPacketSize: */
0x00,
0xFF, /* bInterval: */
/*Data class interface descriptor*/
0x09, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_INTERFACE_TYPE, /* bDescriptorType: */
0x02, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints: Two endpoints used */
0x0A, /* bInterfaceClass: CDC */
0x00, /* bInterfaceSubClass: */
0x00, /* bInterfaceProtocol: */
0x00, /* iInterface: */
/*Endpoint 3 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_ENDPOINT_TYPE, /* bDescriptorType: Endpoint */
0x03, /* bEndpointAddress: (OUT3) */
0x02, /* bmAttributes: Bulk */
0x40, /* wMaxPacketSize: */
0x00,
0x00, /* bInterval: ignore for Bulk transfer */
/*Endpoint 1 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_DESCRIPTOR_ENDPOINT_TYPE, /* bDescriptorType: Endpoint */
0x83, /* bEndpointAddress: (IN3) */
0x02, /* bmAttributes: Bulk */
0x40, /* wMaxPacketSize: */
0x00,
0x00, /* bInterval */
код конфигурации конечных точек
CODE
void Virtual_Com_Port_Reset(void)
{
/* Set Virtual_Com_Port DEVICE as not configured */
pInformation->Current_Configuration = 0;
/* Current Feature initialization */
pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];
/* Set Virtual_Com_Port DEVICE with the default Interface*/
pInformation->Current_Interface = 0;
SetBTABLE(BTABLE_ADDRESS);
/* Initialize Endpoint 0 */
SetEPType(ENDP0, EP_CONTROL);
SetEPTxStatus(ENDP0, EP_TX_STALL);
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
Clear_Status_Out(ENDP0);
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
SetEPRxValid(ENDP0);
/* Initialize Endpoint 1 */
SetEPType(ENDP1, EP_BULK);
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
SetEPRxCount(ENDP1, 0x40);
SetEPRxStatus(ENDP1, EP_RX_VALID);
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
SetEPTxStatus(ENDP1, EP_TX_NAK);
/* Initialize Endpoint 2 */
SetEPType(ENDP2, EP_INTERRUPT);
SetEPTxAddr(ENDP2, ENDP2_TXADDR);
SetEPRxStatus(ENDP2, EP_RX_DIS);
SetEPTxStatus(ENDP2, EP_TX_NAK);
// /* Initialize Endpoint 3 */
SetEPType(ENDP3, EP_BULK);
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
SetEPRxCount(ENDP3, 0x40);
SetEPRxStatus(ENDP3, EP_RX_VALID);
SetEPTxAddr(ENDP3, ENDP3_TXADDR);
SetEPTxStatus(ENDP3, EP_TX_NAK);
/* Set this device to response on default address */
SetDeviceAddress(0);
bDeviceState = ATTACHED;
}
{
/* Set Virtual_Com_Port DEVICE as not configured */
pInformation->Current_Configuration = 0;
/* Current Feature initialization */
pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7];
/* Set Virtual_Com_Port DEVICE with the default Interface*/
pInformation->Current_Interface = 0;
SetBTABLE(BTABLE_ADDRESS);
/* Initialize Endpoint 0 */
SetEPType(ENDP0, EP_CONTROL);
SetEPTxStatus(ENDP0, EP_TX_STALL);
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
Clear_Status_Out(ENDP0);
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
SetEPRxValid(ENDP0);
/* Initialize Endpoint 1 */
SetEPType(ENDP1, EP_BULK);
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
SetEPRxCount(ENDP1, 0x40);
SetEPRxStatus(ENDP1, EP_RX_VALID);
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
SetEPTxStatus(ENDP1, EP_TX_NAK);
/* Initialize Endpoint 2 */
SetEPType(ENDP2, EP_INTERRUPT);
SetEPTxAddr(ENDP2, ENDP2_TXADDR);
SetEPRxStatus(ENDP2, EP_RX_DIS);
SetEPTxStatus(ENDP2, EP_TX_NAK);
// /* Initialize Endpoint 3 */
SetEPType(ENDP3, EP_BULK);
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
SetEPRxCount(ENDP3, 0x40);
SetEPRxStatus(ENDP3, EP_RX_VALID);
SetEPTxAddr(ENDP3, ENDP3_TXADDR);
SetEPTxStatus(ENDP3, EP_TX_NAK);
/* Set this device to response on default address */
SetDeviceAddress(0);
bDeviceState = ATTACHED;
}
определение адресов точек
Код
#define BTABLE_ADDRESS (0x00)
/* EP0 */
/* rx/tx buffer base address */
#define ENDP0_RXADDR (0x18)
#define ENDP0_TXADDR (0x58)
#define ENDP1_TXADDR (0x98)
#define ENDP1_RXADDR (0xD8)
#define ENDP2_TXADDR (0x118)
#define ENDP3_TXADDR (0x130)
#define ENDP3_RXADDR (0x150)
/* EP0 */
/* rx/tx buffer base address */
#define ENDP0_RXADDR (0x18)
#define ENDP0_TXADDR (0x58)
#define ENDP1_TXADDR (0x98)
#define ENDP1_RXADDR (0xD8)
#define ENDP2_TXADDR (0x118)
#define ENDP3_TXADDR (0x130)
#define ENDP3_RXADDR (0x150)
отправка и прием стандартные
CODE
uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length)
{
/*if max buffer is Not reached*/
if(Send_length < VIRTUAL_COM_PORT_DATA_SIZE)
{
/*Sent flag*/
packet_sent1 = 0;
/* send packet to PMA*/
UserToPMABufferCopy((unsigned char*)ptrBuffer, ENDP1_TXADDR, Send_length);
SetEPTxCount(ENDP1, Send_length);
SetEPTxValid(ENDP1);
}
else
{
return 0;
}
return 1;
}
void EP3_OUT_Callback (void)
{
receive_length = GetEPRxCount(ENDP3);
PMAToUserBufferCopy((unsigned char*)receive_Buffer, ENDP3_RXADDR, receive_length);
packet_receive = 1;
SetEPRxValid(ENDP3);
}
{
/*if max buffer is Not reached*/
if(Send_length < VIRTUAL_COM_PORT_DATA_SIZE)
{
/*Sent flag*/
packet_sent1 = 0;
/* send packet to PMA*/
UserToPMABufferCopy((unsigned char*)ptrBuffer, ENDP1_TXADDR, Send_length);
SetEPTxCount(ENDP1, Send_length);
SetEPTxValid(ENDP1);
}
else
{
return 0;
}
return 1;
}
void EP3_OUT_Callback (void)
{
receive_length = GetEPRxCount(ENDP3);
PMAToUserBufferCopy((unsigned char*)receive_Buffer, ENDP3_RXADDR, receive_length);
packet_receive = 1;
SetEPRxValid(ENDP3);
}
количество EP определено как
Код
#define EP_NUM (7)
Если что-то ещё нужно показать - говорите.