1 /**
2 ******************************************************************************
3 * @file : usbd_desc.c
4 * @version : v2.0_Cube
5 * @brief : This file implements the USB device descriptors.
6 ******************************************************************************
7 * This notice applies to any and all portions of this file
8 * that are not between comment pairs USER CODE BEGIN and
9 * USER CODE END. Other portions of this file, whether
10 * inserted by the user or by software development tools
11 * are owned by their respective copyright owners.
12 *
13 * Copyright (c) 2018 STMicroelectronics International N.V.
14 * All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted, provided that the following conditions are met:
18 *
19 * 1. Redistribution of source code must retain the above copyright notice,
20 * this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright notice,
22 * this list of conditions and the following disclaimer in the documentation
23 * and/or other materials provided with the distribution.
24 * 3. Neither the name of STMicroelectronics nor the names of other
25 * contributors to this software may be used to endorse or promote products
26 * derived from this software without specific written permission.
27 * 4. This software, including modifications and/or derivative works of this
28 * software, must execute solely and exclusively on microcontroller or
29 * microprocessor devices manufactured by or for STMicroelectronics.
30 * 5. Redistribution and use of this software other than as permitted under
31 * this license is void and will automatically terminate your rights under
32 * this license.
33 *
34 * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
35 * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
37 * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
38 * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
39 * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
42 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
45 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 *
47 ******************************************************************************
48 */
49
50 /* Includes ------------------------------------------------------------------*/
51 #include "usbd_core.h"
52 #include "usbd_desc.h"
53 #include "usbd_conf.h"
54
55 /* USER CODE BEGIN INCLUDE */
56
57 /* USER CODE END INCLUDE */
58
59 /* Private typedef -----------------------------------------------------------*/
60 /* Private define ------------------------------------------------------------*/
61 /* Private macro -------------------------------------------------------------*/
62
63 /* USER CODE BEGIN PV */
64 /* Private variables ---------------------------------------------------------*/
65
66 /* USER CODE END PV */
67
68 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
69 * @{
70 */
71
72 /** @addtogroup USBD_DESC
73 * @{
74 */
75
76 /** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions
77 * @brief Private types.
78 * @{
79 */
80
81 /* USER CODE BEGIN PRIVATE_TYPES */
82
83 /* USER CODE END PRIVATE_TYPES */
84
85 /**
86 * @}
87 */
88
89 /** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
90 * @brief Private defines.
91 * @{
92 */
93
94 #define USBD_VID 1155
95 #define USBD_LANGID_STRING 1033
96 #define USBD_MANUFACTURER_STRING "STMicroelectronics"
97 #define USBD_PID_FS 22336
98 #define USBD_PRODUCT_STRING_FS "STM32 Virtual ComPort"
99 #define USBD_SERIALNUMBER_STRING_FS "00000000001A"
100 #define USBD_CONFIGURATION_STRING_FS "CDC Config"
101 #define USBD_INTERFACE_STRING_FS "CDC Interface"
102
103 #define USB_SIZ_BOS_DESC 0x0C
104
105 /* USER CODE BEGIN PRIVATE_DEFINES */
106
107 /* USER CODE END PRIVATE_DEFINES */
108
109 /**
110 * @}
111 */
112
113 /* USER CODE BEGIN 0 */
114
115 /* USER CODE END 0 */
116
117 /** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
118 * @brief Private macros.
119 * @{
120 */
121
122 /* USER CODE BEGIN PRIVATE_MACRO */
123
124 /* USER CODE END PRIVATE_MACRO */
125
126 /**
127 * @}
128 */
129
130 /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
131 * @brief Private functions declaration.
132 * @{
133 */
134
135 uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
136 uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
137 uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
138 uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
139 uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
140 uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
141 uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
142
143 #ifdef USB_SUPPORT_USER_STRING_DESC
144 uint8_t * USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
145 #endif /* USB_SUPPORT_USER_STRING_DESC */
146
147 #if (USBD_LPM_ENABLED == 1)
148 uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
149 #endif /* (USBD_LPM_ENABLED == 1) */
150
151 /**
152 * @}
153 */
154
155 /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
156 * @brief Private variables.
157 * @{
158 */
159
160 USBD_DescriptorsTypeDef FS_Desc =
161 {
162 USBD_FS_DeviceDescriptor
163 , USBD_FS_LangIDStrDescriptor
164 , USBD_FS_ManufacturerStrDescriptor
165 , USBD_FS_ProductStrDescriptor
166 , USBD_FS_SerialStrDescriptor
167 , USBD_FS_ConfigStrDescriptor
168 , USBD_FS_InterfaceStrDescriptor
169 #if (USBD_LPM_ENABLED == 1)
170 , USBD_FS_USR_BOSDescriptor
171 #endif /* (USBD_LPM_ENABLED == 1) */
172 };
173
174 #if defined ( __ICCARM__ ) /* IAR Compiler */
175 #pragma data_alignment=4
176 #endif /* defined ( __ICCARM__ ) */
177 /** USB standard device descriptor. */
178 __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
179 {
180 0x12, /*bLength */
181 USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
182 #if (USBD_LPM_ENABLED == 1)
183 0x01, /*bcdUSB */ /* changed to USB version 2.01
184 in order to support LPM L1 suspend
185 resume test of USBCV3.0*/
186 #else
187 0x00, /*bcdUSB */
188 #endif /* (USBD_LPM_ENABLED == 1) */
189 0x02,
190 0x02, /*bDeviceClass*/
191 0x02, /*bDeviceSubClass*/
192 0x00, /*bDeviceProtocol*/
193 USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
194 LOBYTE(USBD_VID), /*idVendor*/
195 HIBYTE(USBD_VID), /*idVendor*/
196 LOBYTE(USBD_PID_FS), /*idProduct*/
197 HIBYTE(USBD_PID_FS), /*idProduct*/
198 0x00, /*bcdDevice rel. 2.00*/
199 0x02,
200 USBD_IDX_MFC_STR, /*Index of manufacturer string*/
201 USBD_IDX_PRODUCT_STR, /*Index of product string*/
202 USBD_IDX_SERIAL_STR, /*Index of serial number string*/
203 USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
204 };
205
206 /* USB_DeviceDescriptor */
207 /** BOS descriptor. */
208 #if (USBD_LPM_ENABLED == 1)
209 #if defined ( __ICCARM__ ) /* IAR Compiler */
210 #pragma data_alignment=4
211 #endif /* defined ( __ICCARM__ ) */
212 __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
213 {
214 0x5,
215 USB_DESC_TYPE_BOS,
216 0xC,
217 0x0,
218 0x1, /* 1 device capability*/
219 /* device capability*/
220 0x7,
221 USB_DEVICE_CAPABITY_TYPE,
222 0x2,
223 0x2, /* LPM capability bit set*/
224 0x0,
225 0x0,
226 0x0
227 };
228 #endif /* (USBD_LPM_ENABLED == 1) */
229
230 /**
231 * @}
232 */
233
234 /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
235 * @brief Private variables.
236 * @{
237 */
238
239 #if defined ( __ICCARM__ ) /* IAR Compiler */
240 #pragma data_alignment=4
241 #endif /* defined ( __ICCARM__ ) */
242
243 /** USB lang indentifier descriptor. */
244 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
245 {
246 USB_LEN_LANGID_STR_DESC,
247 USB_DESC_TYPE_STRING,
248 LOBYTE(USBD_LANGID_STRING),
249 HIBYTE(USBD_LANGID_STRING)
250 };
251
252 #if defined ( __ICCARM__ ) /* IAR Compiler */
253 #pragma data_alignment=4
254 #endif /* defined ( __ICCARM__ ) */
255 /* Internal string descriptor. */
256 __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
257
258 /**
259 * @}
260 */
261
262 /** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions
263 * @brief Private functions.
264 * @{
265 */
266
267 /**
268 * @brief Return the device descriptor
269 * @param speed : Current device speed
270 * @param length : Pointer to data length variable
271 * @retval Pointer to descriptor buffer
272 */
USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed,uint16_t * length)273 uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
274 {
275 *length = sizeof(USBD_FS_DeviceDesc);
276 return USBD_FS_DeviceDesc;
277 }
278
279 /**
280 * @brief Return the LangID string descriptor
281 * @param speed : Current device speed
282 * @param length : Pointer to data length variable
283 * @retval Pointer to descriptor buffer
284 */
USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed,uint16_t * length)285 uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
286 {
287 *length = sizeof(USBD_LangIDDesc);
288 return USBD_LangIDDesc;
289 }
290
291 /**
292 * @brief Return the product string descriptor
293 * @param speed : Current device speed
294 * @param length : Pointer to data length variable
295 * @retval Pointer to descriptor buffer
296 */
USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed,uint16_t * length)297 uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
298 {
299 if(speed == 0)
300 {
301 USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
302 }
303 else
304 {
305 USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
306 }
307 return USBD_StrDesc;
308 }
309
310 /**
311 * @brief Return the manufacturer string descriptor
312 * @param speed : Current device speed
313 * @param length : Pointer to data length variable
314 * @retval Pointer to descriptor buffer
315 */
USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed,uint16_t * length)316 uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
317 {
318 USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
319 return USBD_StrDesc;
320 }
321
322 /**
323 * @brief Return the serial number string descriptor
324 * @param speed : Current device speed
325 * @param length : Pointer to data length variable
326 * @retval Pointer to descriptor buffer
327 */
USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed,uint16_t * length)328 uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
329 {
330 if(speed == USBD_SPEED_HIGH)
331 {
332 USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
333 }
334 else
335 {
336 USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
337 }
338 return USBD_StrDesc;
339 }
340
341 /**
342 * @brief Return the configuration string descriptor
343 * @param speed : Current device speed
344 * @param length : Pointer to data length variable
345 * @retval Pointer to descriptor buffer
346 */
USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed,uint16_t * length)347 uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
348 {
349 if(speed == USBD_SPEED_HIGH)
350 {
351 USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
352 }
353 else
354 {
355 USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
356 }
357 return USBD_StrDesc;
358 }
359
360 /**
361 * @brief Return the interface string descriptor
362 * @param speed : Current device speed
363 * @param length : Pointer to data length variable
364 * @retval Pointer to descriptor buffer
365 */
USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed,uint16_t * length)366 uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
367 {
368 if(speed == 0)
369 {
370 USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
371 }
372 else
373 {
374 USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
375 }
376 return USBD_StrDesc;
377 }
378
379 #if (USBD_LPM_ENABLED == 1)
380 /**
381 * @brief Return the BOS descriptor
382 * @param speed : Current device speed
383 * @param length : Pointer to data length variable
384 * @retval Pointer to descriptor buffer
385 */
USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed,uint16_t * length)386 uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
387 {
388 *length = sizeof(USBD_FS_BOSDesc);
389 return (uint8_t*)USBD_FS_BOSDesc;
390 }
391 #endif /* (USBD_LPM_ENABLED == 1) */
392
393 /**
394 * @}
395 */
396
397 /**
398 * @}
399 */
400
401 /**
402 * @}
403 */
404
405 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
406