STSW-STLKT01: Projects/SensorTile/Applications/DataLog/Src/usbd_desc.c Source File

STSW-STLKT01

usbd_desc.c
Go to the documentation of this file.
1 
48 /* Includes ------------------------------------------------------------------*/
49 #include "usbd_core.h"
50 #include "usbd_desc.h"
51 #include "usbd_conf.h"
52 
53 /* Private typedef -----------------------------------------------------------*/
54 /* Private define ------------------------------------------------------------*/
55 #define USBD_VID 0x0483
56 #define USBD_PID 0x5740
57 #define USBD_LANGID_STRING 0x409
58 #define USBD_MANUFACTURER_STRING "STMicroelectronics"
59 #define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode"
60 #define USBD_CONFIGURATION_FS_STRING "VCP Config"
61 #define USBD_INTERFACE_FS_STRING "VCP Interface"
62 
63 /* Private macro -------------------------------------------------------------*/
64 /* Private function prototypes -----------------------------------------------*/
65 uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
66 uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
67 uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
68 uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
69 uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
70 uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
71 uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
72 #ifdef USB_SUPPORT_USER_STRING_DESC
73 uint8_t *USBD_VCP_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
74 #endif /* USB_SUPPORT_USER_STRING_DESC */
75 
76 /* Private variables ---------------------------------------------------------*/
77 USBD_DescriptorsTypeDef VCP_Desc = {
85 };
86 
87 /* USB Standard Device Descriptor */
88 #if defined ( __ICCARM__ )
89  #pragma data_alignment=4
90 #endif
91 __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
92  0x12, /* bLength */
93  USB_DESC_TYPE_DEVICE, /* bDescriptorType */
94  0x00, /* bcdUSB */
95  0x02,
96  0x00, /* bDeviceClass */
97  0x00, /* bDeviceSubClass */
98  0x00, /* bDeviceProtocol */
99  USB_MAX_EP0_SIZE, /* bMaxPacketSize */
100  LOBYTE(USBD_VID), /* idVendor */
101  HIBYTE(USBD_VID), /* idVendor */
102  LOBYTE(USBD_PID), /* idVendor */
103  HIBYTE(USBD_PID), /* idVendor */
104  0x00, /* bcdDevice rel. 2.00 */
105  0x02,
106  USBD_IDX_MFC_STR, /* Index of manufacturer string */
107  USBD_IDX_PRODUCT_STR, /* Index of product string */
108  USBD_IDX_SERIAL_STR, /* Index of serial number string */
109  USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
110 }; /* USB_DeviceDescriptor */
111 
112 /* USB Standard Device Descriptor */
113 #if defined ( __ICCARM__ )
114  #pragma data_alignment=4
115 #endif
116 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
117  USB_LEN_LANGID_STR_DESC,
118  USB_DESC_TYPE_STRING,
119  LOBYTE(USBD_LANGID_STRING),
120  HIBYTE(USBD_LANGID_STRING),
121 };
122 
123 uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
124 {
125  USB_SIZ_STRING_SERIAL,
126  USB_DESC_TYPE_STRING,
127 };
128 
129 #if defined ( __ICCARM__ )
130  #pragma data_alignment=4
131 #endif
132 __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
133 
134 /* Private functions ---------------------------------------------------------*/
135 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
136 static void Get_SerialNum(void);
137 
144 uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
145 {
146  *length = sizeof(USBD_DeviceDesc);
147  return (uint8_t*)USBD_DeviceDesc;
148 }
149 
156 uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
157 {
158  *length = sizeof(USBD_LangIDDesc);
159  return (uint8_t*)USBD_LangIDDesc;
160 }
161 
168 uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
169 {
170  USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
171  return USBD_StrDesc;
172 }
173 
180 uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
181 {
182  USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
183  return USBD_StrDesc;
184 }
185 
192 uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
193 {
194  *length = USB_SIZ_STRING_SERIAL;
195 
196  /* Update the serial number string descriptor with the data from the unique ID*/
197  Get_SerialNum();
198 
199  return (uint8_t*)USBD_StringSerial;
200 }
201 
208 uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
209 {
210  USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
211  return USBD_StrDesc;
212 }
213 
220 uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
221 {
222  USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
223  return USBD_StrDesc;
224 }
225 
231 static void Get_SerialNum(void)
232 {
233  uint32_t deviceserial0, deviceserial1, deviceserial2;
234 
235  deviceserial0 = *(uint32_t*)DEVICE_ID1;
236  deviceserial1 = *(uint32_t*)DEVICE_ID2;
237  deviceserial2 = *(uint32_t*)DEVICE_ID3;
238 
239  deviceserial0 += deviceserial2;
240 
241  if (deviceserial0 != 0)
242  {
243  IntToUnicode (deviceserial0, &USBD_StringSerial[2] ,8);
244  IntToUnicode (deviceserial1, &USBD_StringSerial[18] ,4);
245  }
246 }
247 
255 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
256 {
257  uint8_t idx = 0;
258 
259  for( idx = 0 ; idx < len ; idx ++)
260  {
261  if( ((value >> 28)) < 0xA )
262  {
263  pbuf[ 2* idx] = (value >> 28) + '0';
264  }
265  else
266  {
267  pbuf[2* idx] = (value >> 28) + 'A' - 10;
268  }
269 
270  value = value << 4;
271 
272  pbuf[ 2* idx + 1] = 0;
273  }
274 }
275 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
276 
uint8_t * USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the product string descriptor.
Definition: usbd_desc.c:168
uint8_t * USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the device descriptor.
Definition: usbd_desc.c:144
uint8_t * USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the LangID string descriptor.
Definition: usbd_desc.c:156
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
Convert Hex 32Bits value into char.
Definition: usbd_desc.c:255
uint8_t * USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the manufacturer string descriptor.
Definition: usbd_desc.c:180
uint8_t * USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the configuration string descriptor.
Definition: usbd_desc.c:208
uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL]
Definition: usbd_desc.c:123
__ALIGN_BEGIN uint8_t USBD_DeviceDesc [USB_LEN_DEV_DESC] __ALIGN_END
Definition: usbd_desc.c:91
uint8_t * USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the serial number string descriptor.
Definition: usbd_desc.c:192
uint8_t * USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the interface string descriptor.
Definition: usbd_desc.c:220
static void Get_SerialNum(void)
Create the serial number string descriptor.
Definition: usbd_desc.c:231
Generated by   doxygen 1.8.13