2 ******************************************************************************
4 * @author MCD Application Team
6 * @date 19-September-2011
7 * @brief This file provides the USBD descriptors and string formating method.
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
23 #include "usbd_core.h"
24 #include "usbd_desc.h"
26 #include "usbd_conf.h"
29 #include "build/version.h"
34 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
39 /** @defgroup USBD_DESC
40 * @brief USBD descriptors module
44 /** @defgroup USBD_DESC_Private_TypesDefinitions
52 /** @defgroup USBD_DESC_Private_Defines
56 #define USBD_VID 0x0483
58 #ifdef USE_USB_CDC_HID
59 #define USBD_PID_COMPOSITE 0x3256
61 #define USBD_PID 0x5740
63 /** @defgroup USB_String_Descriptors
66 #define USBD_LANGID_STRING 0x409
67 #define USBD_MANUFACTURER_STRING FC_FIRMWARE_NAME
69 #ifdef USBD_PRODUCT_STRING
70 #define USBD_PRODUCT_HS_STRING USBD_PRODUCT_STRING
71 #define USBD_PRODUCT_FS_STRING USBD_PRODUCT_STRING
73 #define USBD_PRODUCT_HS_STRING "STM32 Virtual ComPort in HS mode"
74 #define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode"
75 #endif /* USBD_PRODUCT_STRING */
77 #ifdef USBD_SERIALNUMBER_STRING
78 #define USBD_SERIALNUMBER_HS_STRING USBD_SERIALNUMBER_STRING
79 #define USBD_SERIALNUMBER_FS_STRING USBD_SERIALNUMBER_STRING
81 // start of STM32 flash
82 #define USBD_SERIALNUMBER_HS_STRING "0x8000000"
83 #define USBD_SERIALNUMBER_FS_STRING "0x8000000"
84 #endif /* USBD_SERIALNUMBER_STRING */
86 #define USBD_CONFIGURATION_HS_STRING "VCP Config"
87 #define USBD_INTERFACE_HS_STRING "VCP Interface"
89 #define USBD_CONFIGURATION_FS_STRING "VCP Config"
90 #define USBD_INTERFACE_FS_STRING "VCP Interface"
96 /** @defgroup USBD_DESC_Private_Macros
104 /** @defgroup USBD_DESC_Private_Variables
108 USBD_DEVICE USR_desc
=
110 USBD_USR_DeviceDescriptor
,
111 USBD_USR_LangIDStrDescriptor
,
112 USBD_USR_ManufacturerStrDescriptor
,
113 USBD_USR_ProductStrDescriptor
,
114 USBD_USR_SerialStrDescriptor
,
115 USBD_USR_ConfigStrDescriptor
,
116 USBD_USR_InterfaceStrDescriptor
,
120 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
121 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
122 #pragma data_alignment=4
124 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
125 #ifdef USE_USB_CDC_HID
126 /* USB Standard Device Descriptor */
127 __ALIGN_BEGIN
uint8_t USBD_DeviceDesc_Composite
[USB_SIZ_DEVICE_DESC
] __ALIGN_END
=
130 USB_DEVICE_DESCRIPTOR_TYPE
, /*bDescriptorType*/
131 0x00, 0x02, /*bcdUSB */
132 0xEF, /*bDeviceClass*/
133 0x02, /*bDeviceSubClass*/
134 0x01, /*bDeviceProtocol*/
135 USB_OTG_MAX_EP0_SIZE
, /*bMaxPacketSize*/
136 LOBYTE(USBD_VID
), HIBYTE(USBD_VID
), /*idVendor*/
137 LOBYTE(USBD_PID_COMPOSITE
),
138 HIBYTE(USBD_PID_COMPOSITE
), /*idProduct*/
139 0x00, 0x02, /*bcdDevice rel. 2.00*/
140 USBD_IDX_MFC_STR
, /*Index of manufacturer string*/
141 USBD_IDX_PRODUCT_STR
, /*Index of product string*/
142 USBD_IDX_SERIAL_STR
, /*Index of serial number string*/
143 USBD_CFG_MAX_NUM
/*bNumConfigurations*/
144 } ; /* USB_DeviceDescriptor */
146 /* USB Standard Device Descriptor */
147 __ALIGN_BEGIN
uint8_t USBD_DeviceDesc
[USB_SIZ_DEVICE_DESC
] __ALIGN_END
=
150 USB_DEVICE_DESCRIPTOR_TYPE
, /*bDescriptorType*/
151 0x00, 0x02, /*bcdUSB */
152 0x02, /*bDeviceClass*/
153 0x02, /*bDeviceSubClass*/
154 0x00, /*bDeviceProtocol*/
155 USB_OTG_MAX_EP0_SIZE
, /*bMaxPacketSize*/
156 LOBYTE(USBD_VID
), HIBYTE(USBD_VID
), /*idVendor*/
157 LOBYTE(USBD_PID
), HIBYTE(USBD_PID
), /*idProduct*/
158 0x00, 0x02, /*bcdDevice rel. 2.00*/
159 USBD_IDX_MFC_STR
, /*Index of manufacturer string*/
160 USBD_IDX_PRODUCT_STR
, /*Index of product string*/
161 USBD_IDX_SERIAL_STR
, /*Index of serial number string*/
162 USBD_CFG_MAX_NUM
/*bNumConfigurations*/
163 } ; /* USB_DeviceDescriptor */
165 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
166 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
167 #pragma data_alignment=4
169 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
170 /* USB Standard Device Descriptor */
171 __ALIGN_BEGIN
uint8_t USBD_DeviceQualifierDesc
[USB_LEN_DEV_QUALIFIER_DESC
] __ALIGN_END
=
173 USB_LEN_DEV_QUALIFIER_DESC
,
174 USB_DESC_TYPE_DEVICE_QUALIFIER
,
185 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
186 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
187 #pragma data_alignment=4
189 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
190 /* USB Standard Device Descriptor */
191 __ALIGN_BEGIN
uint8_t USBD_LangIDDesc
[USB_SIZ_STRING_LANGID
] __ALIGN_END
=
193 USB_SIZ_STRING_LANGID
,
194 USB_DESC_TYPE_STRING
,
195 LOBYTE(USBD_LANGID_STRING
),
196 HIBYTE(USBD_LANGID_STRING
),
203 /** @defgroup USBD_DESC_Private_FunctionPrototypes
211 /** @defgroup USBD_DESC_Private_Functions
216 * @brief USBD_USR_DeviceDescriptor
217 * return the device descriptor
218 * @param speed : current device speed
219 * @param length : pointer to data length variable
220 * @retval pointer to descriptor buffer
222 uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed
, uint16_t *length
)
225 #ifdef USE_USB_CDC_HID
226 if (usbDevConfig()->type
== COMPOSITE
) {
227 *length
= sizeof(USBD_DeviceDesc_Composite
);
228 return USBD_DeviceDesc_Composite
;
231 *length
= sizeof(USBD_DeviceDesc
);
232 return USBD_DeviceDesc
;
236 * @brief USBD_USR_LangIDStrDescriptor
237 * return the LangID string descriptor
238 * @param speed : current device speed
239 * @param length : pointer to data length variable
240 * @retval pointer to descriptor buffer
242 uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed
, uint16_t *length
)
245 *length
= sizeof(USBD_LangIDDesc
);
246 return USBD_LangIDDesc
;
251 * @brief USBD_USR_ProductStrDescriptor
252 * return the product string descriptor
253 * @param speed : current device speed
254 * @param length : pointer to data length variable
255 * @retval pointer to descriptor buffer
257 uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed
, uint16_t *length
)
262 USBD_GetString ((uint8_t*)USBD_PRODUCT_HS_STRING
, USBD_StrDesc
, length
);
264 USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING
, USBD_StrDesc
, length
);
270 * @brief USBD_USR_ManufacturerStrDescriptor
271 * return the manufacturer string descriptor
272 * @param speed : current device speed
273 * @param length : pointer to data length variable
274 * @retval pointer to descriptor buffer
276 uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed
, uint16_t *length
)
279 USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING
, USBD_StrDesc
, length
);
284 * @brief USBD_USR_SerialStrDescriptor
285 * return the serial number string descriptor
286 * @param speed : current device speed
287 * @param length : pointer to data length variable
288 * @retval pointer to descriptor buffer
290 uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed
, uint16_t *length
)
292 if (speed
== USB_OTG_SPEED_HIGH
)
293 USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_HS_STRING
, USBD_StrDesc
, length
);
295 USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING
, USBD_StrDesc
, length
);
301 * @brief USBD_USR_ConfigStrDescriptor
302 * return the configuration string descriptor
303 * @param speed : current device speed
304 * @param length : pointer to data length variable
305 * @retval pointer to descriptor buffer
307 uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed
, uint16_t *length
)
309 if (speed
== USB_OTG_SPEED_HIGH
)
310 USBD_GetString ((uint8_t*)USBD_CONFIGURATION_HS_STRING
, USBD_StrDesc
, length
);
312 USBD_GetString ((uint8_t*)USBD_CONFIGURATION_FS_STRING
, USBD_StrDesc
, length
);
319 * @brief USBD_USR_InterfaceStrDescriptor
320 * return the interface string descriptor
321 * @param speed : current device speed
322 * @param length : pointer to data length variable
323 * @retval pointer to descriptor buffer
325 uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed
, uint16_t *length
)
328 USBD_GetString ((uint8_t*)USBD_INTERFACE_HS_STRING
, USBD_StrDesc
, length
);
330 USBD_GetString ((uint8_t*)USBD_INTERFACE_FS_STRING
, USBD_StrDesc
, length
);
349 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/