Skip to content

Commit 65af7eb

Browse files
committed
stmhal: Put CDC last in config descriptors to match with iface nums.
Apparently the order of interface numbers should be sequential and increasing in a config descriptor. So as to retain compatibility with Windows drivers for the CDC+MSC and CDC+HID modes, we move the CDC configs to the end of the descriptors, instead of changing the interface numbers. See PR micropython#957 for background.
1 parent 39ce2db commit 65af7eb

File tree

1 file changed

+69
-69
lines changed

1 file changed

+69
-69
lines changed

stmhal/usbdev/class/src/usbd_cdc_msc_hid.c

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define CDC_TEMPLATE_CONFIG_DESC_SIZE (67)
3232
#define CDC_MSC_TEMPLATE_CONFIG_DESC_SIZE (98)
3333
#define CDC_HID_TEMPLATE_CONFIG_DESC_SIZE (100)
34-
#define CDC_HID_TEMPLATE_HID_DESC_OFFSET (CDC_HID_TEMPLATE_CONFIG_DESC_SIZE - 25)
34+
#define CDC_HID_TEMPLATE_HID_DESC_OFFSET (9)
3535
#define HID_DESC_OFFSET_SUBCLASS (6)
3636
#define HID_DESC_OFFSET_PROTOCOL (7)
3737
#define HID_DESC_OFFSET_SUBDESC (9)
@@ -128,6 +128,39 @@ static const uint8_t cdc_msc_template_config_desc[CDC_MSC_TEMPLATE_CONFIG_DESC_S
128128
0x80, // bmAttributes: bus powered; 0xc0 for self powered
129129
0xfa, // bMaxPower: in units of 2mA
130130

131+
//==========================================================================
132+
// MSC only has 1 interface so doesn't need an IAD
133+
134+
//--------------------------------------------------------------------------
135+
// Interface Descriptor
136+
0x09, // bLength: Interface Descriptor size
137+
USB_DESC_TYPE_INTERFACE, // bDescriptorType: interface descriptor
138+
MSC_IFACE_NUM_WITH_CDC, // bInterfaceNumber: Number of Interface
139+
0x00, // bAlternateSetting: Alternate setting
140+
0x02, // bNumEndpoints
141+
0x08, // bInterfaceClass: MSC Class
142+
0x06, // bInterfaceSubClass : SCSI transparent
143+
0x50, // nInterfaceProtocol
144+
0x00, // iInterface:
145+
146+
// Endpoint IN descriptor
147+
0x07, // bLength: Endpoint descriptor length
148+
USB_DESC_TYPE_ENDPOINT, // bDescriptorType: Endpoint descriptor type
149+
MSC_IN_EP, // bEndpointAddress: IN, address 3
150+
0x02, // bmAttributes: Bulk endpoint type
151+
LOBYTE(MSC_MAX_PACKET), // wMaxPacketSize
152+
HIBYTE(MSC_MAX_PACKET),
153+
0x00, // bInterval: ignore for Bulk transfer
154+
155+
// Endpoint OUT descriptor
156+
0x07, // bLength: Endpoint descriptor length
157+
USB_DESC_TYPE_ENDPOINT, // bDescriptorType: Endpoint descriptor type
158+
MSC_OUT_EP, // bEndpointAddress: OUT, address 3
159+
0x02, // bmAttributes: Bulk endpoint type
160+
LOBYTE(MSC_MAX_PACKET), // wMaxPacketSize
161+
HIBYTE(MSC_MAX_PACKET),
162+
0x00, // bInterval: ignore for Bulk transfer
163+
131164
//==========================================================================
132165
// Interface Association for CDC VCP
133166
0x08, // bLength: 8 bytes
@@ -216,39 +249,6 @@ static const uint8_t cdc_msc_template_config_desc[CDC_MSC_TEMPLATE_CONFIG_DESC_S
216249
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),// wMaxPacketSize:
217250
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
218251
0x00, // bInterval: ignore for Bulk transfer
219-
220-
//==========================================================================
221-
// MSC only has 1 interface so doesn't need an IAD
222-
223-
//--------------------------------------------------------------------------
224-
// Interface Descriptor
225-
0x09, // bLength: Interface Descriptor size
226-
USB_DESC_TYPE_INTERFACE, // bDescriptorType: interface descriptor
227-
MSC_IFACE_NUM_WITH_CDC, // bInterfaceNumber: Number of Interface
228-
0x00, // bAlternateSetting: Alternate setting
229-
0x02, // bNumEndpoints
230-
0x08, // bInterfaceClass: MSC Class
231-
0x06, // bInterfaceSubClass : SCSI transparent
232-
0x50, // nInterfaceProtocol
233-
0x00, // iInterface:
234-
235-
// Endpoint IN descriptor
236-
0x07, // bLength: Endpoint descriptor length
237-
USB_DESC_TYPE_ENDPOINT, // bDescriptorType: Endpoint descriptor type
238-
MSC_IN_EP, // bEndpointAddress: IN, address 3
239-
0x02, // bmAttributes: Bulk endpoint type
240-
LOBYTE(MSC_MAX_PACKET), // wMaxPacketSize
241-
HIBYTE(MSC_MAX_PACKET),
242-
0x00, // bInterval: ignore for Bulk transfer
243-
244-
// Endpoint OUT descriptor
245-
0x07, // bLength: Endpoint descriptor length
246-
USB_DESC_TYPE_ENDPOINT, // bDescriptorType: Endpoint descriptor type
247-
MSC_OUT_EP, // bEndpointAddress: OUT, address 3
248-
0x02, // bmAttributes: Bulk endpoint type
249-
LOBYTE(MSC_MAX_PACKET), // wMaxPacketSize
250-
HIBYTE(MSC_MAX_PACKET),
251-
0x00, // bInterval: ignore for Bulk transfer
252252
};
253253

254254
// USB CDC HID device Configuration Descriptor
@@ -265,6 +265,41 @@ static const uint8_t cdc_hid_template_config_desc[CDC_HID_TEMPLATE_CONFIG_DESC_S
265265
0x80, // bmAttributes: bus powered; 0xc0 for self powered
266266
0xfa, // bMaxPower: in units of 2mA
267267

268+
//==========================================================================
269+
// HID only has 1 interface so doesn't need an IAD
270+
271+
//--------------------------------------------------------------------------
272+
// Interface Descriptor
273+
0x09, // bLength: Interface Descriptor size
274+
USB_DESC_TYPE_INTERFACE, // bDescriptorType: interface descriptor
275+
HID_IFACE_NUM_WITH_CDC, // bInterfaceNumber: Number of Interface
276+
0x00, // bAlternateSetting: Alternate setting
277+
0x01, // bNumEndpoints
278+
0x03, // bInterfaceClass: HID Class
279+
0x01, // bInterfaceSubClass: 0=no sub class, 1=boot
280+
0x02, // nInterfaceProtocol: 0=none, 1=keyboard, 2=mouse
281+
0x00, // iInterface:
282+
283+
// HID descriptor
284+
0x09, // bLength: HID Descriptor size
285+
HID_DESCRIPTOR_TYPE, // bDescriptorType: HID
286+
0x11, // bcdHID: HID Class Spec release number
287+
0x01,
288+
0x00, // bCountryCode: Hardware target country
289+
0x01, // bNumDescriptors: Number of HID class descriptors to follow
290+
0x22, // bDescriptorType
291+
USBD_HID_MOUSE_REPORT_DESC_SIZE, // wItemLength: Total length of Report descriptor
292+
0x00,
293+
294+
// Endpoint IN descriptor
295+
0x07, // bLength: Endpoint descriptor length
296+
USB_DESC_TYPE_ENDPOINT, // bDescriptorType: Endpoint descriptor type
297+
HID_IN_EP_WITH_CDC, // bEndpointAddress: IN
298+
0x03, // bmAttributes: Interrupt endpoint type
299+
LOBYTE(USBD_HID_MOUSE_MAX_PACKET), // wMaxPacketSize
300+
HIBYTE(USBD_HID_MOUSE_MAX_PACKET),
301+
0x08, // bInterval: Polling interval
302+
268303
//==========================================================================
269304
// Interface Association for CDC VCP
270305
0x08, // bLength: 8 bytes
@@ -353,41 +388,6 @@ static const uint8_t cdc_hid_template_config_desc[CDC_HID_TEMPLATE_CONFIG_DESC_S
353388
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),// wMaxPacketSize:
354389
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
355390
0x00, // bInterval: ignore for Bulk transfer
356-
357-
//==========================================================================
358-
// HID only has 1 interface so doesn't need an IAD
359-
360-
//--------------------------------------------------------------------------
361-
// Interface Descriptor
362-
0x09, // bLength: Interface Descriptor size
363-
USB_DESC_TYPE_INTERFACE, // bDescriptorType: interface descriptor
364-
HID_IFACE_NUM_WITH_CDC, // bInterfaceNumber: Number of Interface
365-
0x00, // bAlternateSetting: Alternate setting
366-
0x01, // bNumEndpoints
367-
0x03, // bInterfaceClass: HID Class
368-
0x01, // bInterfaceSubClass: 0=no sub class, 1=boot
369-
0x02, // nInterfaceProtocol: 0=none, 1=keyboard, 2=mouse
370-
0x00, // iInterface:
371-
372-
// HID descriptor
373-
0x09, // bLength: HID Descriptor size
374-
HID_DESCRIPTOR_TYPE, // bDescriptorType: HID
375-
0x11, // bcdHID: HID Class Spec release number
376-
0x01,
377-
0x00, // bCountryCode: Hardware target country
378-
0x01, // bNumDescriptors: Number of HID class descriptors to follow
379-
0x22, // bDescriptorType
380-
USBD_HID_MOUSE_REPORT_DESC_SIZE, // wItemLength: Total length of Report descriptor
381-
0x00,
382-
383-
// Endpoint IN descriptor
384-
0x07, // bLength: Endpoint descriptor length
385-
USB_DESC_TYPE_ENDPOINT, // bDescriptorType: Endpoint descriptor type
386-
HID_IN_EP_WITH_CDC, // bEndpointAddress: IN
387-
0x03, // bmAttributes: Interrupt endpoint type
388-
LOBYTE(USBD_HID_MOUSE_MAX_PACKET), // wMaxPacketSize
389-
HIBYTE(USBD_HID_MOUSE_MAX_PACKET),
390-
0x08, // bInterval: Polling interval
391391
};
392392

393393
static const uint8_t cdc_template_config_desc[CDC_TEMPLATE_CONFIG_DESC_SIZE] = {

0 commit comments

Comments
 (0)