1 /**
2   ******************************************************************************
3   * @file    usbd_desc.c
4   * @author  MCD Application Team
5   * @version V1.0.0
6   * @date    19-September-2011
7   * @brief   This file provides the USBD descriptors and string formating method.
8   ******************************************************************************
9   * @attention
10   *
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.
17   *
18   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19   ******************************************************************************
20   */
21 
22 /* Includes ------------------------------------------------------------------*/
23 #include <assert.h>
24 #include "usbd_core.h"
25 #include "usbd_desc.h"
26 #include "usbd_req.h"
27 #include "usbd_conf.h"
28 #include "usb_regs.h"
29 
30 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
31   * @{
32   */
33 
34 
35 /** @defgroup USBD_DESC
36   * @brief USBD descriptors module
37   * @{
38   */
39 
40 /** @defgroup USBD_DESC_Private_TypesDefinitions
41   * @{
42   */
43 /**
44   * @}
45   */
46 
47 
48 /** @defgroup USBD_DESC_Private_Defines
49   * @{
50   */
51 
52 #define USBD_VID                        0x0483
53 
54 #define USBD_PID                        0x5740
55 
56 /** @defgroup USB_String_Descriptors
57   * @{
58   */
59 #define USBD_LANGID_STRING              0x409
60 #define USBD_MANUFACTURER_STRING        "STMicroelectronics"
61 
62 #define USBD_PRODUCT_HS_STRING          "STM32 Virtual ComPort in HS mode"
63 #define USBD_SERIALNUMBER_HS_STRING     "00000000050B"
64 
65 #define USBD_PRODUCT_FS_STRING          "STM32 Virtual ComPort in FS Mode"
66 #define USBD_SERIALNUMBER_FS_STRING     "00000000050C"
67 
68 #define USBD_CONFIGURATION_HS_STRING    "VCP Config"
69 #define USBD_INTERFACE_HS_STRING        "VCP Interface"
70 
71 #define USBD_CONFIGURATION_FS_STRING    "VCP Config"
72 #define USBD_INTERFACE_FS_STRING        "VCP Interface"
73 /**
74   * @}
75   */
76 
77 
78 /** @defgroup USBD_DESC_Private_Macros
79   * @{
80   */
81 /**
82   * @}
83   */
84 
85 
86 /** @defgroup USBD_DESC_Private_Variables
87   * @{
88   */
89 
90 USBD_DEVICE USR_desc =
91 {
92   USBD_USR_DeviceDescriptor,
93   USBD_USR_LangIDStrDescriptor,
94   USBD_USR_ManufacturerStrDescriptor,
95   USBD_USR_ProductStrDescriptor,
96   USBD_USR_SerialStrDescriptor,
97   USBD_USR_ConfigStrDescriptor,
98   USBD_USR_InterfaceStrDescriptor,
99 
100 };
101 
102 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
103   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
104     #pragma data_alignment=4
105   #endif
106 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
107 /* USB Standard Device Descriptor */
108 __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
109   {
110     0x12,                       /*bLength */
111     USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
112     0x00,                       /*bcdUSB */
113     0x02,
114     0x00,                       /*bDeviceClass*/
115     0x00,                       /*bDeviceSubClass*/
116     0x00,                       /*bDeviceProtocol*/
117     USB_OTG_MAX_EP0_SIZE,      /*bMaxPacketSize*/
118     LOBYTE(USBD_VID),           /*idVendor*/
119     HIBYTE(USBD_VID),           /*idVendor*/
120     LOBYTE(USBD_PID),           /*idVendor*/
121     HIBYTE(USBD_PID),           /*idVendor*/
122     0x00,                       /*bcdDevice rel. 2.00*/
123     0x02,
124     USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/
125     USBD_IDX_PRODUCT_STR,       /*Index of product string*/
126     USBD_IDX_SERIAL_STR,        /*Index of serial number string*/
127     USBD_CFG_MAX_NUM            /*bNumConfigurations*/
128   } ; /* USB_DeviceDescriptor */
129 
130 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
131   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
132     #pragma data_alignment=4
133   #endif
134 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
135 /* USB Standard Device Descriptor */
136 __ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
137 {
138   USB_LEN_DEV_QUALIFIER_DESC,
139   USB_DESC_TYPE_DEVICE_QUALIFIER,
140   0x00,
141   0x02,
142   0x00,
143   0x00,
144   0x00,
145   0x40,
146   0x01,
147   0x00,
148 };
149 
150 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
151   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
152     #pragma data_alignment=4
153   #endif
154 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
155 /* USB Standard Device Descriptor */
156 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
157 {
158      USB_SIZ_STRING_LANGID,
159      USB_DESC_TYPE_STRING,
160      LOBYTE(USBD_LANGID_STRING),
161      HIBYTE(USBD_LANGID_STRING),
162 };
163 /**
164   * @}
165   */
166 
167 
168 /** @defgroup USBD_DESC_Private_FunctionPrototypes
169   * @{
170   */
171 /**
172   * @}
173   */
174 
175 
176 /** @defgroup USBD_DESC_Private_Functions
177   * @{
178   */
179 
180 /**
181 * @brief  USBD_USR_DeviceDescriptor
182 *         return the device descriptor
183 * @param  speed : current device speed
184 * @param  length : pointer to data length variable
185 * @retval pointer to descriptor buffer
186 */
USBD_USR_DeviceDescriptor(uint8_t speed,uint16_t * length)187 uint8_t *  USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
188 {
189   *length = sizeof(USBD_DeviceDesc);
190   return USBD_DeviceDesc;
191 }
192 
193 /**
194 * @brief  USBD_USR_LangIDStrDescriptor
195 *         return the LangID string descriptor
196 * @param  speed : current device speed
197 * @param  length : pointer to data length variable
198 * @retval pointer to descriptor buffer
199 */
USBD_USR_LangIDStrDescriptor(uint8_t speed,uint16_t * length)200 uint8_t *  USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
201 {
202   *length =  sizeof(USBD_LangIDDesc);
203   return USBD_LangIDDesc;
204 }
205 
206 
207 /**
208 * @brief  USBD_USR_ProductStrDescriptor
209 *         return the product string descriptor
210 * @param  speed : current device speed
211 * @param  length : pointer to data length variable
212 * @retval pointer to descriptor buffer
213 */
USBD_USR_ProductStrDescriptor(uint8_t speed,uint16_t * length)214 uint8_t *  USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
215 {
216 
217   if(speed == 0)
218   {
219     USBD_GetString ((uint8_t*)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
220   }
221   else
222   {
223     USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
224   }
225 
226   assert(*length < USB_MAX_STR_DESC_SIZ);
227 
228   return USBD_StrDesc;
229 }
230 
231 /**
232 * @brief  USBD_USR_ManufacturerStrDescriptor
233 *         return the manufacturer string descriptor
234 * @param  speed : current device speed
235 * @param  length : pointer to data length variable
236 * @retval pointer to descriptor buffer
237 */
USBD_USR_ManufacturerStrDescriptor(uint8_t speed,uint16_t * length)238 uint8_t *  USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
239 {
240   USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
241   assert(*length < USB_MAX_STR_DESC_SIZ);
242   return USBD_StrDesc;
243 }
244 
245 /**
246 * @brief  USBD_USR_SerialStrDescriptor
247 *         return the serial number string descriptor
248 * @param  speed : current device speed
249 * @param  length : pointer to data length variable
250 * @retval pointer to descriptor buffer
251 */
USBD_USR_SerialStrDescriptor(uint8_t speed,uint16_t * length)252 uint8_t *  USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
253 {
254   if(speed  == USB_OTG_SPEED_HIGH)
255   {
256     USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
257   }
258   else
259   {
260     USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
261   }
262   assert(*length < USB_MAX_STR_DESC_SIZ);
263   return USBD_StrDesc;
264 }
265 
266 /**
267 * @brief  USBD_USR_ConfigStrDescriptor
268 *         return the configuration string descriptor
269 * @param  speed : current device speed
270 * @param  length : pointer to data length variable
271 * @retval pointer to descriptor buffer
272 */
USBD_USR_ConfigStrDescriptor(uint8_t speed,uint16_t * length)273 uint8_t *  USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
274 {
275   if(speed  == USB_OTG_SPEED_HIGH)
276   {
277     USBD_GetString ((uint8_t*)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
278   }
279   else
280   {
281     USBD_GetString ((uint8_t*)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
282   }
283   assert(*length < USB_MAX_STR_DESC_SIZ);
284   return USBD_StrDesc;
285 }
286 
287 
288 /**
289 * @brief  USBD_USR_InterfaceStrDescriptor
290 *         return the interface string descriptor
291 * @param  speed : current device speed
292 * @param  length : pointer to data length variable
293 * @retval pointer to descriptor buffer
294 */
USBD_USR_InterfaceStrDescriptor(uint8_t speed,uint16_t * length)295 uint8_t *  USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
296 {
297   if(speed == 0)
298   {
299     USBD_GetString ((uint8_t*)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
300   }
301   else
302   {
303     USBD_GetString ((uint8_t*)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
304   }
305   assert(*length < USB_MAX_STR_DESC_SIZ);
306   return USBD_StrDesc;
307 }
308 
309 /**
310   * @}
311   */
312 
313 
314 /**
315   * @}
316   */
317 
318 
319 /**
320   * @}
321   */
322 
323 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
324 
325