|
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * @file USB_Device/CDC_Standalone/Src/usbd_desc.c |
| 4 | + * @author MCD Application Team |
| 5 | + * @version V1.0.1 |
| 6 | + * @date 26-February-2014 |
| 7 | + * @brief This file provides the USBD descriptors and string formating method. |
| 8 | + ****************************************************************************** |
| 9 | + * @attention |
| 10 | + * |
| 11 | + * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
| 12 | + * |
| 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: |
| 16 | + * |
| 17 | + * http://www.st.com/software_license_agreement_liberty_v2 |
| 18 | + * |
| 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. |
| 24 | + * |
| 25 | + ****************************************************************************** |
| 26 | + */ |
| 27 | + |
| 28 | +/* Includes ------------------------------------------------------------------*/ |
| 29 | +#include "usbd_core.h" |
| 30 | +#include "usbd_desc.h" |
| 31 | +#include "usbd_conf.h" |
| 32 | + |
| 33 | +/* Private typedef -----------------------------------------------------------*/ |
| 34 | +/* Private define ------------------------------------------------------------*/ |
| 35 | +#define USBD_VID 0x0483 |
| 36 | +#define USBD_PID 0x5740 |
| 37 | +#define USBD_LANGID_STRING 0x409 |
| 38 | +#define USBD_MANUFACTURER_STRING "STMicroelectronics" |
| 39 | +#define USBD_PRODUCT_HS_STRING "STM32 Virtual ComPort in HS Mode" |
| 40 | +#define USBD_SERIALNUMBER_HS_STRING "00000000001A" |
| 41 | +#define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode" |
| 42 | +#define USBD_SERIALNUMBER_FS_STRING "00000000001B" |
| 43 | +#define USBD_CONFIGURATION_HS_STRING "VCP Config" |
| 44 | +#define USBD_INTERFACE_HS_STRING "VCP Interface" |
| 45 | +#define USBD_CONFIGURATION_FS_STRING "VCP Config" |
| 46 | +#define USBD_INTERFACE_FS_STRING "VCP Interface" |
| 47 | + |
| 48 | +/* Private macro -------------------------------------------------------------*/ |
| 49 | +/* Private function prototypes -----------------------------------------------*/ |
| 50 | +uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
| 51 | +uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
| 52 | +uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
| 53 | +uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
| 54 | +uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
| 55 | +uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
| 56 | +uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
| 57 | +#ifdef USB_SUPPORT_USER_STRING_DESC |
| 58 | +uint8_t *USBD_VCP_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); |
| 59 | +#endif /* USB_SUPPORT_USER_STRING_DESC */ |
| 60 | + |
| 61 | +/* Private variables ---------------------------------------------------------*/ |
| 62 | +USBD_DescriptorsTypeDef VCP_Desc = { |
| 63 | + USBD_VCP_DeviceDescriptor, |
| 64 | + USBD_VCP_LangIDStrDescriptor, |
| 65 | + USBD_VCP_ManufacturerStrDescriptor, |
| 66 | + USBD_VCP_ProductStrDescriptor, |
| 67 | + USBD_VCP_SerialStrDescriptor, |
| 68 | + USBD_VCP_ConfigStrDescriptor, |
| 69 | + USBD_VCP_InterfaceStrDescriptor, |
| 70 | +}; |
| 71 | + |
| 72 | +/* USB Standard Device Descriptor */ |
| 73 | +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ |
| 74 | + #pragma data_alignment=4 |
| 75 | +#endif |
| 76 | +__ALIGN_BEGIN static uint8_t hUSBDDeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { |
| 77 | + 0x12, /* bLength */ |
| 78 | + USB_DESC_TYPE_DEVICE, /* bDescriptorType */ |
| 79 | + 0x00, /* bcdUSB */ |
| 80 | + 0x02, |
| 81 | + 0x00, /* bDeviceClass */ |
| 82 | + 0x00, /* bDeviceSubClass */ |
| 83 | + 0x00, /* bDeviceProtocol */ |
| 84 | + USB_MAX_EP0_SIZE, /* bMaxPacketSize */ |
| 85 | + LOBYTE(USBD_VID), /* idVendor */ |
| 86 | + HIBYTE(USBD_VID), /* idVendor */ |
| 87 | + LOBYTE(USBD_PID), /* idVendor */ |
| 88 | + HIBYTE(USBD_PID), /* idVendor */ |
| 89 | + 0x00, /* bcdDevice rel. 2.00 */ |
| 90 | + 0x02, |
| 91 | + USBD_IDX_MFC_STR, /* Index of manufacturer string */ |
| 92 | + USBD_IDX_PRODUCT_STR, /* Index of product string */ |
| 93 | + USBD_IDX_SERIAL_STR, /* Index of serial number string */ |
| 94 | + USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */ |
| 95 | +}; /* USB_DeviceDescriptor */ |
| 96 | + |
| 97 | +/* USB Standard Device Descriptor */ |
| 98 | +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ |
| 99 | + #pragma data_alignment=4 |
| 100 | +#endif |
| 101 | +__ALIGN_BEGIN static uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = { |
| 102 | + USB_LEN_LANGID_STR_DESC, |
| 103 | + USB_DESC_TYPE_STRING, |
| 104 | + LOBYTE(USBD_LANGID_STRING), |
| 105 | + HIBYTE(USBD_LANGID_STRING), |
| 106 | +}; |
| 107 | + |
| 108 | +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ |
| 109 | + #pragma data_alignment=4 |
| 110 | +#endif |
| 111 | +__ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; |
| 112 | + |
| 113 | +/* Private functions ---------------------------------------------------------*/ |
| 114 | + |
| 115 | +/** |
| 116 | + * @brief Returns the device descriptor. |
| 117 | + * @param speed: Current device speed |
| 118 | + * @param length: Pointer to data length variable |
| 119 | + * @retval Pointer to descriptor buffer |
| 120 | + */ |
| 121 | +uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
| 122 | +{ |
| 123 | + *length = sizeof(hUSBDDeviceDesc); |
| 124 | + return hUSBDDeviceDesc; |
| 125 | +} |
| 126 | + |
| 127 | +/** |
| 128 | + * @brief Returns the LangID string descriptor. |
| 129 | + * @param speed: Current device speed |
| 130 | + * @param length: Pointer to data length variable |
| 131 | + * @retval Pointer to descriptor buffer |
| 132 | + */ |
| 133 | +uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
| 134 | +{ |
| 135 | + *length = sizeof(USBD_LangIDDesc); |
| 136 | + return USBD_LangIDDesc; |
| 137 | +} |
| 138 | + |
| 139 | +/** |
| 140 | + * @brief Returns the product string descriptor. |
| 141 | + * @param speed: Current device speed |
| 142 | + * @param length: Pointer to data length variable |
| 143 | + * @retval Pointer to descriptor buffer |
| 144 | + */ |
| 145 | +uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
| 146 | +{ |
| 147 | + if(speed == 0) |
| 148 | + { |
| 149 | + USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length); |
| 150 | + } |
| 151 | + else |
| 152 | + { |
| 153 | + USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); |
| 154 | + } |
| 155 | + return USBD_StrDesc; |
| 156 | +} |
| 157 | + |
| 158 | +/** |
| 159 | + * @brief Returns the manufacturer string descriptor. |
| 160 | + * @param speed: Current device speed |
| 161 | + * @param length: Pointer to data length variable |
| 162 | + * @retval Pointer to descriptor buffer |
| 163 | + */ |
| 164 | +uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
| 165 | +{ |
| 166 | + USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); |
| 167 | + return USBD_StrDesc; |
| 168 | +} |
| 169 | + |
| 170 | +/** |
| 171 | + * @brief Returns the serial number string descriptor. |
| 172 | + * @param speed: Current device speed |
| 173 | + * @param length: Pointer to data length variable |
| 174 | + * @retval Pointer to descriptor buffer |
| 175 | + */ |
| 176 | +uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
| 177 | +{ |
| 178 | + if(speed == USBD_SPEED_HIGH) |
| 179 | + { |
| 180 | + USBD_GetString((uint8_t *)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length); |
| 181 | + } |
| 182 | + else |
| 183 | + { |
| 184 | + USBD_GetString((uint8_t *)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length); |
| 185 | + } |
| 186 | + return USBD_StrDesc; |
| 187 | +} |
| 188 | + |
| 189 | +/** |
| 190 | + * @brief Returns the configuration string descriptor. |
| 191 | + * @param speed: Current device speed |
| 192 | + * @param length: Pointer to data length variable |
| 193 | + * @retval Pointer to descriptor buffer |
| 194 | + */ |
| 195 | +uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
| 196 | +{ |
| 197 | + if(speed == USBD_SPEED_HIGH) |
| 198 | + { |
| 199 | + USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length); |
| 200 | + } |
| 201 | + else |
| 202 | + { |
| 203 | + USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); |
| 204 | + } |
| 205 | + return USBD_StrDesc; |
| 206 | +} |
| 207 | + |
| 208 | +/** |
| 209 | + * @brief Returns the interface string descriptor. |
| 210 | + * @param speed: Current device speed |
| 211 | + * @param length: Pointer to data length variable |
| 212 | + * @retval Pointer to descriptor buffer |
| 213 | + */ |
| 214 | +uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
| 215 | +{ |
| 216 | + if(speed == 0) |
| 217 | + { |
| 218 | + USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length); |
| 219 | + } |
| 220 | + else |
| 221 | + { |
| 222 | + USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length); |
| 223 | + } |
| 224 | + return USBD_StrDesc; |
| 225 | +} |
| 226 | + |
| 227 | +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
| 228 | + |
0 commit comments