2 ******************************************************************************
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.
13 * Copyright (c) 2018 STMicroelectronics International N.V.
14 * All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted, provided that the following conditions are met:
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
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.
47 ******************************************************************************
50 /* Includes ------------------------------------------------------------------*/
51 #include "usbd_core.h"
52 #include "usbd_desc.h"
53 #include "usbd_conf.h"
55 /* USER CODE BEGIN INCLUDE */
57 /* USER CODE END INCLUDE */
59 /* Private typedef -----------------------------------------------------------*/
60 /* Private define ------------------------------------------------------------*/
61 /* Private macro -------------------------------------------------------------*/
63 /* USER CODE BEGIN PV */
64 /* Private variables ---------------------------------------------------------*/
66 /* USER CODE END PV */
68 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
72 /** @addtogroup USBD_DESC
76 /** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions
77 * @brief Private types.
81 /* USER CODE BEGIN PRIVATE_TYPES */
83 /* USER CODE END PRIVATE_TYPES */
89 /** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
90 * @brief Private defines.
95 #define USBD_LANGID_STRING 1033
96 #define USBD_MANUFACTURER_STRING "UCW"
97 #define USBD_PID_FS 57105
98 #define USBD_PRODUCT_STRING_FS "Mysterious Gadget"
99 #define USBD_SERIALNUMBER_STRING_FS "00000000002A"
100 #define USBD_CONFIGURATION_STRING_FS "DFU Config"
101 #define USBD_INTERFACE_STRING_FS "DFU Interface"
103 /* USER CODE BEGIN PRIVATE_DEFINES */
105 /* USER CODE END PRIVATE_DEFINES */
111 /* USER CODE BEGIN 0 */
113 /* USER CODE END 0 */
115 /** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
116 * @brief Private macros.
120 /* USER CODE BEGIN PRIVATE_MACRO */
122 /* USER CODE END PRIVATE_MACRO */
128 /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
129 * @brief Private functions declaration.
133 uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
134 uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
135 uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
136 uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
137 uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
138 uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
139 uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
141 #ifdef USB_SUPPORT_USER_STRING_DESC
142 uint8_t * USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
143 #endif /* USB_SUPPORT_USER_STRING_DESC */
149 /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
150 * @brief Private variables.
154 USBD_DescriptorsTypeDef FS_Desc =
156 USBD_FS_DeviceDescriptor
157 , USBD_FS_LangIDStrDescriptor
158 , USBD_FS_ManufacturerStrDescriptor
159 , USBD_FS_ProductStrDescriptor
160 , USBD_FS_SerialStrDescriptor
161 , USBD_FS_ConfigStrDescriptor
162 , USBD_FS_InterfaceStrDescriptor
165 #if defined ( __ICCARM__ ) /* IAR Compiler */
166 #pragma data_alignment=4
167 #endif /* defined ( __ICCARM__ ) */
168 /** USB standard device descriptor. */
169 __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
172 USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
175 0x00, /*bDeviceClass*/
176 0x00, /*bDeviceSubClass*/
177 0x00, /*bDeviceProtocol*/
178 USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
179 LOBYTE(USBD_VID), /*idVendor*/
180 HIBYTE(USBD_VID), /*idVendor*/
181 LOBYTE(USBD_PID_FS), /*idProduct*/
182 HIBYTE(USBD_PID_FS), /*idProduct*/
183 0x00, /*bcdDevice rel. 2.00*/
185 USBD_IDX_MFC_STR, /*Index of manufacturer string*/
186 USBD_IDX_PRODUCT_STR, /*Index of product string*/
187 USBD_IDX_SERIAL_STR, /*Index of serial number string*/
188 USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
191 /* USB_DeviceDescriptor */
197 /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
198 * @brief Private variables.
202 #if defined ( __ICCARM__ ) /* IAR Compiler */
203 #pragma data_alignment=4
204 #endif /* defined ( __ICCARM__ ) */
206 /** USB lang indentifier descriptor. */
207 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
209 USB_LEN_LANGID_STR_DESC,
210 USB_DESC_TYPE_STRING,
211 LOBYTE(USBD_LANGID_STRING),
212 HIBYTE(USBD_LANGID_STRING)
215 #if defined ( __ICCARM__ ) /* IAR Compiler */
216 #pragma data_alignment=4
217 #endif /* defined ( __ICCARM__ ) */
218 /* Internal string descriptor. */
219 __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
225 /** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions
226 * @brief Private functions.
231 * @brief Return the device descriptor
232 * @param speed : Current device speed
233 * @param length : Pointer to data length variable
234 * @retval Pointer to descriptor buffer
236 uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
238 *length = sizeof(USBD_FS_DeviceDesc);
239 return USBD_FS_DeviceDesc;
243 * @brief Return the LangID string descriptor
244 * @param speed : Current device speed
245 * @param length : Pointer to data length variable
246 * @retval Pointer to descriptor buffer
248 uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
250 *length = sizeof(USBD_LangIDDesc);
251 return USBD_LangIDDesc;
255 * @brief Return the product string descriptor
256 * @param speed : Current device speed
257 * @param length : Pointer to data length variable
258 * @retval Pointer to descriptor buffer
260 uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
264 USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
268 USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
274 * @brief Return the manufacturer string descriptor
275 * @param speed : Current device speed
276 * @param length : Pointer to data length variable
277 * @retval Pointer to descriptor buffer
279 uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
281 USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
286 * @brief Return the serial number string descriptor
287 * @param speed : Current device speed
288 * @param length : Pointer to data length variable
289 * @retval Pointer to descriptor buffer
291 uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
293 if(speed == USBD_SPEED_HIGH)
295 USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
299 USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
305 * @brief Return the configuration string descriptor
306 * @param speed : Current device speed
307 * @param length : Pointer to data length variable
308 * @retval Pointer to descriptor buffer
310 uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
312 if(speed == USBD_SPEED_HIGH)
314 USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
318 USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
324 * @brief Return the interface string descriptor
325 * @param speed : Current device speed
326 * @param length : Pointer to data length variable
327 * @retval Pointer to descriptor buffer
329 uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
333 USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
337 USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
354 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/