Skip to content

Commit 885ac7a

Browse files
committed
[USB] Add CDC to descriptor
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 17a0f1f commit 885ac7a

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

cores/arduino/stm32/usb/usbd_desc.c

+103-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
#define USBD_HID_INTERFACE_FS_STRING CONCATS(USB_PRODUCT, "HID Interface")
4949
#endif /* USBD_USE_HID_COMPOSITE */
5050

51+
#ifdef USBD_USE_CDC
52+
#define USBD_CDC_PID 0x5740
53+
#define USBD_CDC_PRODUCT_HS_STRING CONCATS(USB_PRODUCT, "CDC in HS Mode")
54+
#define USBD_CDC_PRODUCT_FS_STRING CONCATS(USB_PRODUCT, "CDC in FS Mode")
55+
#define USBD_CDC_CONFIGURATION_HS_STRING CONCATS(USB_PRODUCT, "CDC Config")
56+
#define USBD_CDC_INTERFACE_HS_STRING CONCATS(USB_PRODUCT, "CDC Interface")
57+
#define USBD_CDC_CONFIGURATION_FS_STRING CONCATS(USB_PRODUCT, "CDC Config")
58+
#define USBD_CDC_INTERFACE_FS_STRING CONCATS(USB_PRODUCT, "CDC Interface")
59+
#endif /* USBD_USE_CDC */
60+
5161
/* Private macro -------------------------------------------------------------*/
5262
/* Private function prototypes -----------------------------------------------*/
5363
/* Common function */
@@ -62,6 +72,13 @@ uint8_t *USBD_HID_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *lengt
6272
uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
6373
uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
6474
#endif /* USBD_USE_HID_COMPOSITE */
75+
#ifdef USBD_USE_CDC
76+
uint8_t *USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
77+
uint8_t *USBD_CDC_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
78+
uint8_t *USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
79+
uint8_t *USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
80+
#endif /* USBD_USE_CDC */
81+
6582
#ifdef USB_SUPPORT_USER_STRING_DESC
6683
uint8_t *USBD_Class_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
6784
#endif /* USB_SUPPORT_USER_STRING_DESC */
@@ -79,7 +96,7 @@ USBD_DescriptorsTypeDef HID_Desc = {
7996
};
8097

8198
/* USB Standard Device Descriptor */
82-
__ALIGN_BEGIN uint8_t USBD_HID_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
99+
__ALIGN_BEGIN uint8_t USBD_HID_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
83100
0x12, /* bLength */
84101
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
85102
0x00, /* bcdUSB */
@@ -101,6 +118,41 @@ __ALIGN_BEGIN uint8_t USBD_HID_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
101118
}; /* USB_DeviceDescriptor */
102119
#endif /* USBD_USE_HID_COMPOSITE */
103120

121+
#ifdef USBD_USE_CDC
122+
USBD_DescriptorsTypeDef CDC_Desc =
123+
{
124+
USBD_CDC_DeviceDescriptor,
125+
USBD_LangIDStrDescriptor,
126+
USBD_ManufacturerStrDescriptor,
127+
USBD_CDC_ProductStrDescriptor,
128+
USBD_SerialStrDescriptor,
129+
USBD_CDC_ConfigStrDescriptor,
130+
USBD_CDC_InterfaceStrDescriptor,
131+
};
132+
133+
/* USB Standard Device Descriptor */
134+
__ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
135+
0x12, /* bLength */
136+
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
137+
0x00, /* bcdUSB */
138+
0x02,
139+
0x00, /* bDeviceClass */
140+
0x00, /* bDeviceSubClass */
141+
0x00, /* bDeviceProtocol */
142+
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
143+
LOBYTE(USBD_VID), /* idVendor */
144+
HIBYTE(USBD_VID), /* idVendor */
145+
LOBYTE(USBD_CDC_PID), /* idVendor */
146+
HIBYTE(USBD_CDC_PID), /* idVendor */
147+
0x00, /* bcdDevice rel. 2.00 */
148+
0x02,
149+
USBD_IDX_MFC_STR, /* Index of manufacturer string */
150+
USBD_IDX_PRODUCT_STR, /* Index of product string */
151+
USBD_IDX_SERIAL_STR, /* Index of serial number string */
152+
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
153+
}; /* USB_DeviceDescriptor */
154+
#endif /* USBD_USE_CDC */
155+
104156
/* USB Standard Device Descriptor */
105157
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
106158
USB_LEN_LANGID_STR_DESC,
@@ -135,7 +187,14 @@ uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
135187
return (uint8_t*)USBD_HID_DeviceDesc;
136188
}
137189
#endif
138-
190+
#ifdef USBD_USE_CDC
191+
uint8_t *USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
192+
{
193+
UNUSED(speed);
194+
*length = sizeof(USBD_CDC_DeviceDesc);
195+
return (uint8_t*)USBD_CDC_DeviceDesc;
196+
}
197+
#endif
139198
/**
140199
* @brief Returns the LangID string descriptor.
141200
* @param speed: Current device speed
@@ -169,6 +228,20 @@ uint8_t *USBD_HID_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
169228
return USBD_StrDesc;
170229
}
171230
#endif /* USBD_USE_HID_COMPOSITE */
231+
#ifdef USBD_USE_CDC
232+
uint8_t *USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
233+
{
234+
if(speed == USBD_SPEED_HIGH)
235+
{
236+
USBD_GetString((uint8_t *)USBD_CDC_PRODUCT_HS_STRING, USBD_StrDesc, length);
237+
}
238+
else
239+
{
240+
USBD_GetString((uint8_t *)USBD_CDC_PRODUCT_FS_STRING, USBD_StrDesc, length);
241+
}
242+
return USBD_StrDesc;
243+
}
244+
#endif /* USBD_USE_CDC */
172245

173246
/**
174247
* @brief Returns the manufacturer string descriptor.
@@ -220,6 +293,20 @@ uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
220293
return USBD_StrDesc;
221294
}
222295
#endif /* USBD_USE_HID_COMPOSITE */
296+
#ifdef USBD_USE_CDC
297+
uint8_t *USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
298+
{
299+
if(speed == USBD_SPEED_HIGH)
300+
{
301+
USBD_GetString((uint8_t *)USBD_CDC_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
302+
}
303+
else
304+
{
305+
USBD_GetString((uint8_t *)USBD_CDC_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
306+
}
307+
return USBD_StrDesc;
308+
}
309+
#endif /* USBD_USE_CDC */
223310

224311
/**
225312
* @brief Returns the interface string descriptor.
@@ -241,6 +328,20 @@ uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
241328
return USBD_StrDesc;
242329
}
243330
#endif /* USBD_USE_HID_COMPOSITE */
331+
#ifdef USBD_USE_CDC
332+
uint8_t *USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
333+
{
334+
if(speed == USBD_SPEED_HIGH)
335+
{
336+
USBD_GetString((uint8_t *)USBD_CDC_INTERFACE_HS_STRING, USBD_StrDesc, length);
337+
}
338+
else
339+
{
340+
USBD_GetString((uint8_t *)USBD_CDC_INTERFACE_FS_STRING, USBD_StrDesc, length);
341+
}
342+
return USBD_StrDesc;
343+
}
344+
#endif /* USBD_USE_CDC */
244345

245346
/**
246347
* @brief Create the serial number string descriptor

cores/arduino/stm32/usb/usbd_desc.h

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#ifdef USBD_USE_HID_COMPOSITE
3838
extern USBD_DescriptorsTypeDef HID_Desc;
3939
#endif
40+
#ifdef USBD_USE_CDC
41+
extern USBD_DescriptorsTypeDef CDC_Desc;
42+
#endif
4043
#endif /* USBCON */
4144
#endif /* __USBD_DESC_H*/
4245

0 commit comments

Comments
 (0)