usbd_desc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : usbd_desc.c
  5. * @version : v1.0_Cube
  6. * @brief : This file implements the USB device descriptors.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under Ultimate Liberty license
  14. * SLA0044, the "License"; You may not use this file except in compliance with
  15. * the License. You may obtain a copy of the License at:
  16. * www.st.com/SLA0044
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "usbd_core.h"
  23. #include "usbd_desc.h"
  24. #include "usbd_conf.h"
  25. /* USER CODE BEGIN INCLUDE */
  26. /* USER CODE END INCLUDE */
  27. /* Private typedef -----------------------------------------------------------*/
  28. /* Private define ------------------------------------------------------------*/
  29. /* Private macro -------------------------------------------------------------*/
  30. /* USER CODE BEGIN PV */
  31. /* Private variables ---------------------------------------------------------*/
  32. /* USER CODE END PV */
  33. /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
  34. * @{
  35. */
  36. /** @addtogroup USBD_DESC
  37. * @{
  38. */
  39. /** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions
  40. * @brief Private types.
  41. * @{
  42. */
  43. /* USER CODE BEGIN PRIVATE_TYPES */
  44. /* USER CODE END PRIVATE_TYPES */
  45. /**
  46. * @}
  47. */
  48. /** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
  49. * @brief Private defines.
  50. * @{
  51. */
  52. #define USBD_VID 1155
  53. #define USBD_LANGID_STRING 1033
  54. #define USBD_MANUFACTURER_STRING "STMicroelectronics"
  55. #define USBD_PID_HS 22314
  56. #define USBD_PRODUCT_STRING_HS "STM32 Mass Storage"
  57. #define USBD_CONFIGURATION_STRING_HS "MSC Config"
  58. #define USBD_INTERFACE_STRING_HS "MSC Interface"
  59. #define USBD_PID_FS 22314
  60. #define USBD_PRODUCT_STRING_FS "STM32 Mass Storage"
  61. #define USBD_CONFIGURATION_STRING_FS "MSC Config"
  62. #define USBD_INTERFACE_STRING_FS "MSC Interface"
  63. #define USB_SIZ_BOS_DESC 0x0C
  64. /* USER CODE BEGIN PRIVATE_DEFINES */
  65. /* USER CODE END PRIVATE_DEFINES */
  66. /**
  67. * @}
  68. */
  69. /* USER CODE BEGIN 0 */
  70. /* USER CODE END 0 */
  71. /** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
  72. * @brief Private macros.
  73. * @{
  74. */
  75. /* USER CODE BEGIN PRIVATE_MACRO */
  76. /* USER CODE END PRIVATE_MACRO */
  77. /**
  78. * @}
  79. */
  80. /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
  81. * @brief Private functions declaration.
  82. * @{
  83. */
  84. static void Get_SerialNum(void);
  85. static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len);
  86. /**
  87. * @}
  88. */
  89. /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
  90. * @brief Private functions declaration for FS.
  91. * @{
  92. */
  93. uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  94. uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  95. uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  96. uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  97. uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  98. uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  99. uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  100. #if (USBD_LPM_ENABLED == 1)
  101. uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  102. #endif /* (USBD_LPM_ENABLED == 1) */
  103. /**
  104. * @}
  105. */
  106. /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
  107. * @brief Private variables.
  108. * @{
  109. */
  110. USBD_DescriptorsTypeDef FS_Desc =
  111. {
  112. USBD_FS_DeviceDescriptor
  113. , USBD_FS_LangIDStrDescriptor
  114. , USBD_FS_ManufacturerStrDescriptor
  115. , USBD_FS_ProductStrDescriptor
  116. , USBD_FS_SerialStrDescriptor
  117. , USBD_FS_ConfigStrDescriptor
  118. , USBD_FS_InterfaceStrDescriptor
  119. #if (USBD_LPM_ENABLED == 1)
  120. , USBD_FS_USR_BOSDescriptor
  121. #endif /* (USBD_LPM_ENABLED == 1) */
  122. };
  123. #if defined ( __ICCARM__ ) /* IAR Compiler */
  124. #pragma data_alignment=4
  125. #endif /* defined ( __ICCARM__ ) */
  126. /** USB standard device descriptor. */
  127. __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
  128. {
  129. 0x12, /*bLength */
  130. USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
  131. #if (USBD_LPM_ENABLED == 1)
  132. 0x01, /*bcdUSB */ /* changed to USB version 2.01
  133. in order to support LPM L1 suspend
  134. resume test of USBCV3.0*/
  135. #else
  136. 0x00, /*bcdUSB */
  137. #endif /* (USBD_LPM_ENABLED == 1) */
  138. 0x02,
  139. 0x00, /*bDeviceClass*/
  140. 0x00, /*bDeviceSubClass*/
  141. 0x00, /*bDeviceProtocol*/
  142. USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
  143. LOBYTE(USBD_VID), /*idVendor*/
  144. HIBYTE(USBD_VID), /*idVendor*/
  145. LOBYTE(USBD_PID_FS), /*idProduct*/
  146. HIBYTE(USBD_PID_FS), /*idProduct*/
  147. 0x00, /*bcdDevice rel. 2.00*/
  148. 0x02,
  149. USBD_IDX_MFC_STR, /*Index of manufacturer string*/
  150. USBD_IDX_PRODUCT_STR, /*Index of product string*/
  151. USBD_IDX_SERIAL_STR, /*Index of serial number string*/
  152. USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
  153. };
  154. /* USB_DeviceDescriptor */
  155. /** BOS descriptor. */
  156. #if (USBD_LPM_ENABLED == 1)
  157. #if defined ( __ICCARM__ ) /* IAR Compiler */
  158. #pragma data_alignment=4
  159. #endif /* defined ( __ICCARM__ ) */
  160. __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
  161. {
  162. 0x5,
  163. USB_DESC_TYPE_BOS,
  164. 0xC,
  165. 0x0,
  166. 0x1, /* 1 device capability*/
  167. /* device capability*/
  168. 0x7,
  169. USB_DEVICE_CAPABITY_TYPE,
  170. 0x2,
  171. 0x2, /* LPM capability bit set*/
  172. 0x0,
  173. 0x0,
  174. 0x0
  175. };
  176. #endif /* (USBD_LPM_ENABLED == 1) */
  177. /**
  178. * @}
  179. */
  180. /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
  181. * @brief Private functions declaration for HS.
  182. * @{
  183. */
  184. uint8_t * USBD_HS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  185. uint8_t * USBD_HS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  186. uint8_t * USBD_HS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  187. uint8_t * USBD_HS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  188. uint8_t * USBD_HS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  189. uint8_t * USBD_HS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  190. uint8_t * USBD_HS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  191. #if (USBD_LPM_ENABLED == 1)
  192. uint8_t * USBD_HS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
  193. #endif /* (USBD_LPM_ENABLED == 1) */
  194. /**
  195. * @}
  196. */
  197. /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
  198. * @brief Private variables.
  199. * @{
  200. */
  201. USBD_DescriptorsTypeDef HS_Desc =
  202. {
  203. USBD_HS_DeviceDescriptor
  204. , USBD_HS_LangIDStrDescriptor
  205. , USBD_HS_ManufacturerStrDescriptor
  206. , USBD_HS_ProductStrDescriptor
  207. , USBD_HS_SerialStrDescriptor
  208. , USBD_HS_ConfigStrDescriptor
  209. , USBD_HS_InterfaceStrDescriptor
  210. #if (USBD_LPM_ENABLED == 1)
  211. , USBD_HS_USR_BOSDescriptor
  212. #endif /* (USBD_LPM_ENABLED == 1) */
  213. };
  214. #if defined ( __ICCARM__ ) /* IAR Compiler */
  215. #pragma data_alignment=4
  216. #endif /* defined ( __ICCARM__ ) */
  217. /** USB standard device descriptor. */
  218. __ALIGN_BEGIN uint8_t USBD_HS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
  219. {
  220. 0x12, /*bLength */
  221. USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
  222. #if (USBD_LPM_ENABLED == 1)
  223. 0x01, /*bcdUSB */ /* changed to USB version 2.01
  224. in order to support LPM L1 suspend
  225. resume test of USBCV3.0*/
  226. #else
  227. 0x00, /*bcdUSB */
  228. #endif /* (USBD_LPM_ENABLED == 1) */
  229. 0x02,
  230. 0x00, /*bDeviceClass*/
  231. 0x00, /*bDeviceSubClass*/
  232. 0x00, /*bDeviceProtocol*/
  233. USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
  234. LOBYTE(USBD_VID), /*idVendor*/
  235. HIBYTE(USBD_VID), /*idVendor*/
  236. LOBYTE(USBD_PID_HS), /*idProduct*/
  237. HIBYTE(USBD_PID_HS), /*idProduct*/
  238. 0x00, /*bcdDevice rel. 2.00*/
  239. 0x02,
  240. USBD_IDX_MFC_STR, /*Index of manufacturer string*/
  241. USBD_IDX_PRODUCT_STR, /*Index of product string*/
  242. USBD_IDX_SERIAL_STR, /*Index of serial number string*/
  243. USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
  244. };
  245. /** BOS descriptor. */
  246. #if (USBD_LPM_ENABLED == 1)
  247. #if defined ( __ICCARM__ ) /* IAR Compiler */
  248. #pragma data_alignment=4
  249. #endif /* defined ( __ICCARM__ ) */
  250. __ALIGN_BEGIN uint8_t USBD_HS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
  251. {
  252. 0x5,
  253. USB_DESC_TYPE_BOS,
  254. 0xC,
  255. 0x0,
  256. 0x1, /* 1 device capability */
  257. /* device capability */
  258. 0x7,
  259. USB_DEVICE_CAPABITY_TYPE,
  260. 0x2,
  261. 0x2, /*LPM capability bit set */
  262. 0x0,
  263. 0x0,
  264. 0x0
  265. };
  266. #endif /* (USBD_LPM_ENABLED == 1) */
  267. /**
  268. * @}
  269. */
  270. /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
  271. * @brief Private variables.
  272. * @{
  273. */
  274. #if defined ( __ICCARM__ ) /* IAR Compiler */
  275. #pragma data_alignment=4
  276. #endif /* defined ( __ICCARM__ ) */
  277. /** USB lang indentifier descriptor. */
  278. __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
  279. {
  280. USB_LEN_LANGID_STR_DESC,
  281. USB_DESC_TYPE_STRING,
  282. LOBYTE(USBD_LANGID_STRING),
  283. HIBYTE(USBD_LANGID_STRING)
  284. };
  285. #if defined ( __ICCARM__ ) /* IAR Compiler */
  286. #pragma data_alignment=4
  287. #endif /* defined ( __ICCARM__ ) */
  288. /* Internal string descriptor. */
  289. __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
  290. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  291. #pragma data_alignment=4
  292. #endif
  293. __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = {
  294. USB_SIZ_STRING_SERIAL,
  295. USB_DESC_TYPE_STRING,
  296. };
  297. /**
  298. * @}
  299. */
  300. /** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions
  301. * @brief Private functions.
  302. * @{
  303. */
  304. /**
  305. * @brief Return the device descriptor
  306. * @param speed : Current device speed
  307. * @param length : Pointer to data length variable
  308. * @retval Pointer to descriptor buffer
  309. */
  310. uint8_t * USBD_HS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  311. {
  312. UNUSED(speed);
  313. *length = sizeof(USBD_HS_DeviceDesc);
  314. return USBD_HS_DeviceDesc;
  315. }
  316. /**
  317. * @brief Return the LangID string descriptor
  318. * @param speed : Current device speed
  319. * @param length : Pointer to data length variable
  320. * @retval Pointer to descriptor buffer
  321. */
  322. uint8_t * USBD_HS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  323. {
  324. UNUSED(speed);
  325. *length = sizeof(USBD_LangIDDesc);
  326. return USBD_LangIDDesc;
  327. }
  328. /**
  329. * @brief Return the product string descriptor
  330. * @param speed : current device speed
  331. * @param length : pointer to data length variable
  332. * @retval pointer to descriptor buffer
  333. */
  334. uint8_t * USBD_HS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  335. {
  336. if(speed == 0)
  337. {
  338. USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_HS, USBD_StrDesc, length);
  339. }
  340. else
  341. {
  342. USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_HS, USBD_StrDesc, length);
  343. }
  344. return USBD_StrDesc;
  345. }
  346. /**
  347. * @brief Return the manufacturer string descriptor
  348. * @param speed : Current device speed
  349. * @param length : Pointer to data length variable
  350. * @retval Pointer to descriptor buffer
  351. */
  352. uint8_t * USBD_HS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  353. {
  354. UNUSED(speed);
  355. USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
  356. return USBD_StrDesc;
  357. }
  358. /**
  359. * @brief Return the serial number string descriptor
  360. * @param speed : Current device speed
  361. * @param length : Pointer to data length variable
  362. * @retval Pointer to descriptor buffer
  363. */
  364. uint8_t * USBD_HS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  365. {
  366. UNUSED(speed);
  367. *length = USB_SIZ_STRING_SERIAL;
  368. /* Update the serial number string descriptor with the data from the unique
  369. * ID */
  370. Get_SerialNum();
  371. /* USER CODE BEGIN USBD_HS_SerialStrDescriptor */
  372. /* USER CODE END USBD_HS_SerialStrDescriptor */
  373. return (uint8_t *) USBD_StringSerial;
  374. }
  375. /**
  376. * @brief Return the configuration string descriptor
  377. * @param speed : Current device speed
  378. * @param length : Pointer to data length variable
  379. * @retval Pointer to descriptor buffer
  380. */
  381. uint8_t * USBD_HS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  382. {
  383. if(speed == USBD_SPEED_HIGH)
  384. {
  385. USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_HS, USBD_StrDesc, length);
  386. }
  387. else
  388. {
  389. USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_HS, USBD_StrDesc, length);
  390. }
  391. return USBD_StrDesc;
  392. }
  393. /**
  394. * @brief Return the interface string descriptor
  395. * @param speed : Current device speed
  396. * @param length : Pointer to data length variable
  397. * @retval Pointer to descriptor buffer
  398. */
  399. uint8_t * USBD_HS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  400. {
  401. if(speed == 0)
  402. {
  403. USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_HS, USBD_StrDesc, length);
  404. }
  405. else
  406. {
  407. USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_HS, USBD_StrDesc, length);
  408. }
  409. return USBD_StrDesc;
  410. }
  411. #if (USBD_LPM_ENABLED == 1)
  412. /**
  413. * @brief Return the BOS descriptor
  414. * @param speed : Current device speed
  415. * @param length : Pointer to data length variable
  416. * @retval Pointer to descriptor buffer
  417. */
  418. uint8_t * USBD_HS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  419. {
  420. UNUSED(speed);
  421. *length = sizeof(USBD_HS_BOSDesc);
  422. return (uint8_t*)USBD_HS_BOSDesc;
  423. }
  424. #endif /* (USBD_LPM_ENABLED == 1) */
  425. /**
  426. * @brief Return the device descriptor
  427. * @param speed : Current device speed
  428. * @param length : Pointer to data length variable
  429. * @retval Pointer to descriptor buffer
  430. */
  431. uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  432. {
  433. UNUSED(speed);
  434. *length = sizeof(USBD_FS_DeviceDesc);
  435. return USBD_FS_DeviceDesc;
  436. }
  437. /**
  438. * @brief Return the LangID string descriptor
  439. * @param speed : Current device speed
  440. * @param length : Pointer to data length variable
  441. * @retval Pointer to descriptor buffer
  442. */
  443. uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  444. {
  445. UNUSED(speed);
  446. *length = sizeof(USBD_LangIDDesc);
  447. return USBD_LangIDDesc;
  448. }
  449. /**
  450. * @brief Return the product string descriptor
  451. * @param speed : Current device speed
  452. * @param length : Pointer to data length variable
  453. * @retval Pointer to descriptor buffer
  454. */
  455. uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  456. {
  457. if(speed == 0)
  458. {
  459. USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
  460. }
  461. else
  462. {
  463. USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
  464. }
  465. return USBD_StrDesc;
  466. }
  467. /**
  468. * @brief Return the manufacturer string descriptor
  469. * @param speed : Current device speed
  470. * @param length : Pointer to data length variable
  471. * @retval Pointer to descriptor buffer
  472. */
  473. uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  474. {
  475. UNUSED(speed);
  476. USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
  477. return USBD_StrDesc;
  478. }
  479. /**
  480. * @brief Return the serial number string descriptor
  481. * @param speed : Current device speed
  482. * @param length : Pointer to data length variable
  483. * @retval Pointer to descriptor buffer
  484. */
  485. uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  486. {
  487. UNUSED(speed);
  488. *length = USB_SIZ_STRING_SERIAL;
  489. /* Update the serial number string descriptor with the data from the unique
  490. * ID */
  491. Get_SerialNum();
  492. /* USER CODE BEGIN USBD_FS_SerialStrDescriptor */
  493. /* USER CODE END USBD_FS_SerialStrDescriptor */
  494. return (uint8_t *) USBD_StringSerial;
  495. }
  496. /**
  497. * @brief Return the configuration string descriptor
  498. * @param speed : Current device speed
  499. * @param length : Pointer to data length variable
  500. * @retval Pointer to descriptor buffer
  501. */
  502. uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  503. {
  504. if(speed == USBD_SPEED_HIGH)
  505. {
  506. USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
  507. }
  508. else
  509. {
  510. USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
  511. }
  512. return USBD_StrDesc;
  513. }
  514. /**
  515. * @brief Return the interface string descriptor
  516. * @param speed : Current device speed
  517. * @param length : Pointer to data length variable
  518. * @retval Pointer to descriptor buffer
  519. */
  520. uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  521. {
  522. if(speed == 0)
  523. {
  524. USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
  525. }
  526. else
  527. {
  528. USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
  529. }
  530. return USBD_StrDesc;
  531. }
  532. #if (USBD_LPM_ENABLED == 1)
  533. /**
  534. * @brief Return the BOS descriptor
  535. * @param speed : Current device speed
  536. * @param length : Pointer to data length variable
  537. * @retval Pointer to descriptor buffer
  538. */
  539. uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
  540. {
  541. UNUSED(speed);
  542. *length = sizeof(USBD_FS_BOSDesc);
  543. return (uint8_t*)USBD_FS_BOSDesc;
  544. }
  545. #endif /* (USBD_LPM_ENABLED == 1) */
  546. /**
  547. * @brief Create the serial number string descriptor
  548. * @param None
  549. * @retval None
  550. */
  551. static void Get_SerialNum(void)
  552. {
  553. uint32_t deviceserial0, deviceserial1, deviceserial2;
  554. deviceserial0 = *(uint32_t *) DEVICE_ID1;
  555. deviceserial1 = *(uint32_t *) DEVICE_ID2;
  556. deviceserial2 = *(uint32_t *) DEVICE_ID3;
  557. deviceserial0 += deviceserial2;
  558. if (deviceserial0 != 0)
  559. {
  560. IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8);
  561. IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4);
  562. }
  563. }
  564. /**
  565. * @brief Convert Hex 32Bits value into char
  566. * @param value: value to convert
  567. * @param pbuf: pointer to the buffer
  568. * @param len: buffer length
  569. * @retval None
  570. */
  571. static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len)
  572. {
  573. uint8_t idx = 0;
  574. for (idx = 0; idx < len; idx++)
  575. {
  576. if (((value >> 28)) < 0xA)
  577. {
  578. pbuf[2 * idx] = (value >> 28) + '0';
  579. }
  580. else
  581. {
  582. pbuf[2 * idx] = (value >> 28) + 'A' - 10;
  583. }
  584. value = value << 4;
  585. pbuf[2 * idx + 1] = 0;
  586. }
  587. }
  588. /**
  589. * @}
  590. */
  591. /**
  592. * @}
  593. */
  594. /**
  595. * @}
  596. */
  597. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/