2 ******************************************************************************
4 * @author MCD Application Team
6 * @date 09-November-2015
7 * @brief This file provides the USBD descriptors and string formating method.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
17 * http://www.st.com/software_license_agreement_liberty_v2
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 ******************************************************************************
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbd_core.h"
30 #include "usbd_desc.h"
32 #include "usbd_conf.h"
36 #define DEVICE_ID1 (0x1FFFF7E8)
37 #define DEVICE_ID2 (0x1FFFF7EA)
38 #define DEVICE_ID3 (0x1FFFF7EC)
39 #define USB_SIZ_STRING_SERIAL 0x1A
41 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
46 /** @defgroup USBD_DESC
47 * @brief USBD descriptors module
51 /** @defgroup USBD_DESC_Private_TypesDefinitions
59 /** @defgroup USBD_DESC_Private_Defines
63 #define USBD_VID 0x0483
64 #define USBD_PID 0x5720
66 #define USBD_LANGID_STRING 0x409
67 #define USBD_MANUFACTURER_STRING "STMicroelectronics"
68 #define USBD_PRODUCT_HS_STRING "Mass Storage in HS Mode"
69 #define USBD_PRODUCT_FS_STRING "Mass Storage in FS Mode"
70 #define USBD_CONFIGURATION_HS_STRING "MSC Config"
71 #define USBD_INTERFACE_HS_STRING "MSC Interface"
72 #define USBD_CONFIGURATION_FS_STRING "MSC Config"
73 #define USBD_INTERFACE_FS_STRING "MSC Interface"
79 /** @defgroup USBD_DESC_Private_Macros
87 /** @defgroup USBD_DESC_Private_Variables
91 USBD_DEVICE MSC_desc
=
93 USBD_MSC_DeviceDescriptor
,
94 USBD_MSC_LangIDStrDescriptor
,
95 USBD_MSC_ManufacturerStrDescriptor
,
96 USBD_MSC_ProductStrDescriptor
,
97 USBD_MSC_SerialStrDescriptor
,
98 USBD_MSC_ConfigStrDescriptor
,
99 USBD_MSC_InterfaceStrDescriptor
,
102 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
103 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
104 #pragma data_alignment=4
106 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
107 /* USB Standard Device Descriptor */
108 __ALIGN_BEGIN
uint8_t USBD_DeviceDesc_MSC
[USB_SIZ_DEVICE_DESC
] __ALIGN_END
=
111 USB_DEVICE_DESCRIPTOR_TYPE
, /*bDescriptorType*/
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*/
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 */
130 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
131 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
132 #pragma data_alignment=4
134 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
135 /* USB Standard Device Descriptor */
136 __ALIGN_BEGIN
uint8_t USBD_DeviceQualifierDesc_MSC
[USB_LEN_DEV_QUALIFIER_DESC
] __ALIGN_END
=
138 USB_LEN_DEV_QUALIFIER_DESC
,
139 USB_DESC_TYPE_DEVICE_QUALIFIER
,
150 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
151 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
152 #pragma data_alignment=4
154 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
155 /* USB Standard Device Descriptor */
156 __ALIGN_BEGIN
uint8_t USBD_LangIDDesc_MSC
[USB_SIZ_STRING_LANGID
] __ALIGN_END
=
158 USB_SIZ_STRING_LANGID
,
159 USB_DESC_TYPE_STRING
,
160 LOBYTE(USBD_LANGID_STRING
),
161 HIBYTE(USBD_LANGID_STRING
),
164 uint8_t USBD_StringSerial_MSC
[USB_SIZ_STRING_SERIAL
] =
166 USB_SIZ_STRING_SERIAL
,
167 USB_DESC_TYPE_STRING
,
170 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
171 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
172 #pragma data_alignment=4
174 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
175 __ALIGN_BEGIN
uint8_t USBD_StrDesc_MSC
[USB_MAX_STR_DESC_SIZ
] __ALIGN_END
;
182 /** @defgroup USBD_DESC_Private_FunctionPrototypes
185 static void IntToUnicode (uint32_t value
, uint8_t *pbuf
, uint8_t len
);
186 static void Get_SerialNum(void);
192 /** @defgroup USBD_DESC_Private_Functions
197 * @brief USBD_USR_DeviceDescriptor
198 * return the device descriptor
199 * @param speed : current device speed
200 * @param length : pointer to data length variable
201 * @retval pointer to descriptor buffer
203 uint8_t * USBD_MSC_DeviceDescriptor( uint8_t speed
, uint16_t *length
)
206 *length
= sizeof(USBD_DeviceDesc_MSC
);
207 return (uint8_t*)USBD_DeviceDesc_MSC
;
211 * @brief USBD_USR_LangIDStrDescriptor
212 * return the LangID string descriptor
213 * @param speed : current device speed
214 * @param length : pointer to data length variable
215 * @retval pointer to descriptor buffer
217 uint8_t * USBD_MSC_LangIDStrDescriptor( uint8_t speed
, uint16_t *length
)
220 *length
= sizeof(USBD_LangIDDesc_MSC
);
221 return (uint8_t*)USBD_LangIDDesc_MSC
;
226 * @brief USBD_USR_ProductStrDescriptor
227 * return the product string descriptor
228 * @param speed : current device speed
229 * @param length : pointer to data length variable
230 * @retval pointer to descriptor buffer
232 uint8_t * USBD_MSC_ProductStrDescriptor( uint8_t speed
, uint16_t *length
)
236 USBD_GetString((uint8_t *)(uint8_t *)USBD_PRODUCT_HS_STRING
, USBD_StrDesc_MSC
, length
);
240 USBD_GetString((uint8_t *)(uint8_t *)USBD_PRODUCT_FS_STRING
, USBD_StrDesc_MSC
, length
);
242 return USBD_StrDesc_MSC
;
246 * @brief USBD_USR_ManufacturerStrDescriptor
247 * return the manufacturer string descriptor
248 * @param speed : current device speed
249 * @param length : pointer to data length variable
250 * @retval pointer to descriptor buffer
252 uint8_t * USBD_MSC_ManufacturerStrDescriptor( uint8_t speed
, uint16_t *length
)
255 USBD_GetString((uint8_t *)(uint8_t *)USBD_MANUFACTURER_STRING
, USBD_StrDesc_MSC
, length
);
256 return USBD_StrDesc_MSC
;
260 * @brief USBD_USR_SerialStrDescriptor
261 * return the serial number string descriptor
262 * @param speed : current device speed
263 * @param length : pointer to data length variable
264 * @retval pointer to descriptor buffer
266 uint8_t * USBD_MSC_SerialStrDescriptor( uint8_t speed
, uint16_t *length
)
269 *length
= USB_SIZ_STRING_SERIAL
;
271 /* Update the serial number string descriptor with the data from the unique ID*/
274 return (uint8_t*)USBD_StringSerial_MSC
;
278 * @brief USBD_USR_ConfigStrDescriptor
279 * return the configuration string descriptor
280 * @param speed : current device speed
281 * @param length : pointer to data length variable
282 * @retval pointer to descriptor buffer
284 uint8_t * USBD_MSC_ConfigStrDescriptor( uint8_t speed
, uint16_t *length
)
286 if(speed
== USB_OTG_SPEED_HIGH
)
288 USBD_GetString((uint8_t *)(uint8_t *)USBD_CONFIGURATION_HS_STRING
, USBD_StrDesc_MSC
, length
);
292 USBD_GetString((uint8_t *)(uint8_t *)USBD_CONFIGURATION_FS_STRING
, USBD_StrDesc_MSC
, length
);
294 return USBD_StrDesc_MSC
;
299 * @brief USBD_USR_InterfaceStrDescriptor
300 * return the interface string descriptor
301 * @param speed : current device speed
302 * @param length : pointer to data length variable
303 * @retval pointer to descriptor buffer
305 uint8_t * USBD_MSC_InterfaceStrDescriptor( uint8_t speed
, uint16_t *length
)
309 USBD_GetString((uint8_t *)(uint8_t *)USBD_INTERFACE_HS_STRING
, USBD_StrDesc_MSC
, length
);
313 USBD_GetString((uint8_t *)(uint8_t *)USBD_INTERFACE_FS_STRING
, USBD_StrDesc_MSC
, length
);
315 return USBD_StrDesc_MSC
;
319 * @brief Create the serial number string descriptor
323 static void Get_SerialNum(void)
325 uint32_t deviceserial0
, deviceserial1
, deviceserial2
;
327 deviceserial0
= *(uint32_t*)DEVICE_ID1
;
328 deviceserial1
= *(uint32_t*)DEVICE_ID2
;
329 deviceserial2
= *(uint32_t*)DEVICE_ID3
;
331 deviceserial0
+= deviceserial2
;
333 if (deviceserial0
!= 0)
335 IntToUnicode (deviceserial0
, &USBD_StringSerial_MSC
[2] ,8);
336 IntToUnicode (deviceserial1
, &USBD_StringSerial_MSC
[18] ,4);
341 * @brief Convert Hex 32Bits value into char
342 * @param value: value to convert
343 * @param pbuf: pointer to the buffer
344 * @param len: buffer length
347 static void IntToUnicode (uint32_t value
, uint8_t *pbuf
, uint8_t len
)
351 for( idx
= 0 ; idx
< len
; idx
++)
353 if( ((value
>> 28)) < 0xA )
355 pbuf
[ 2* idx
] = (value
>> 28) + '0';
359 pbuf
[2* idx
] = (value
>> 28) + 'A' - 10;
364 pbuf
[ 2* idx
+ 1] = 0;
383 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/