Damian Gabino / picoGW_mcu
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usbd_desc.cpp Source File

usbd_desc.cpp

00001 /**
00002   ******************************************************************************
00003   * @file           : usbd_desc.c
00004   * @version        : v1.0_Cube
00005   * @brief          : This file implements the USB Device descriptors
00006   ******************************************************************************
00007   *
00008   * COPYRIGHT(c) 2016 STMicroelectronics
00009   *
00010   * Redistribution and use in source and binary forms, with or without modification,
00011   * are permitted provided that the following conditions are met:
00012   * 1. Redistributions of source code must retain the above copyright notice,
00013   * this list of conditions and the following disclaimer.
00014   * 2. Redistributions in binary form must reproduce the above copyright notice,
00015   * this list of conditions and the following disclaimer in the documentation
00016   * and/or other materials provided with the distribution.
00017   * 3. Neither the name of STMicroelectronics nor the names of its contributors
00018   * may be used to endorse or promote products derived from this software
00019   * without specific prior written permission.
00020   *
00021   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00025   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00027   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00030   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031   *
00032   ******************************************************************************
00033 */
00034 
00035 /* Includes ------------------------------------------------------------------*/
00036 #include "usbd_core.h"
00037 #include "usbd_desc.h"
00038 #include "usbd_conf.h"
00039 
00040 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
00041   * @{
00042   */
00043 
00044 /** @defgroup USBD_DESC 
00045   * @brief USBD descriptors module
00046   * @{
00047   */ 
00048 
00049 /** @defgroup USBD_DESC_Private_TypesDefinitions
00050   * @{
00051   */ 
00052 /**
00053   * @}
00054   */ 
00055 
00056 /** @defgroup USBD_DESC_Private_Defines
00057   * @{
00058   */ 
00059 #define USBD_VID                      0x0483
00060 #define USBD_PID_FS                   0x5740
00061 #define USBD_LANGID_STRING            0x409
00062 #define USBD_MANUFACTURER_STRING      "STMicroelectronics"
00063 #define USBD_PRODUCT_STRING_FS        "SEMTECH PicoGW Virtual ComPort"
00064 #define USBD_SERIALNUMBER_STRING_FS   "3EA5F0C2B81C"
00065 #define USBD_CONFIGURATION_STRING_FS  "CDC Config"
00066 #define USBD_INTERFACE_STRING_FS      "CDC Interface"
00067 
00068 #define USB_SIZ_BOS_DESC            0x0C
00069 
00070 /* USER CODE BEGIN 0 */
00071 
00072 /* USER CODE END 0*/
00073 /**
00074   * @}
00075   */ 
00076 
00077 /** @defgroup USBD_DESC_Private_Macros
00078   * @{
00079   */ 
00080 /**
00081   * @}
00082   */ 
00083 
00084 /** @defgroup USBD_DESC_Private_Variables
00085   * @{
00086   */ 
00087 uint8_t *     USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
00088 uint8_t *     USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
00089 uint8_t *     USBD_FS_ManufacturerStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length);
00090 uint8_t *     USBD_FS_ProductStrDescriptor ( USBD_SpeedTypeDef speed , uint16_t *length);
00091 uint8_t *     USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
00092 uint8_t *     USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
00093 uint8_t *     USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length);
00094 
00095 #ifdef USB_SUPPORT_USER_STRING_DESC
00096 uint8_t *     USBD_FS_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx , uint16_t *length);  
00097 #endif /* USB_SUPPORT_USER_STRING_DESC */  
00098 
00099 #if (USBD_LPM_ENABLED == 1)
00100 uint8_t *USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed , uint16_t *length);
00101 #endif
00102 
00103 USBD_DescriptorsTypeDef FS_Desc =
00104 {
00105   USBD_FS_DeviceDescriptor,
00106   USBD_FS_LangIDStrDescriptor, 
00107   USBD_FS_ManufacturerStrDescriptor,
00108   USBD_FS_ProductStrDescriptor,
00109   USBD_FS_SerialStrDescriptor,
00110   USBD_FS_ConfigStrDescriptor,
00111   USBD_FS_InterfaceStrDescriptor,
00112 #if (USBD_LPM_ENABLED == 1)  
00113   USBD_FS_USR_BOSDescriptor,
00114 #endif  
00115 };
00116 
00117 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
00118   #pragma data_alignment=4   
00119 #endif
00120 /* USB Standard Device Descriptor */
00121 __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
00122    {
00123     0x12,                       /*bLength */
00124     USB_DESC_TYPE_DEVICE,       /*bDescriptorType*/
00125 #if (USBD_LPM_ENABLED == 1)
00126     0x01,                       /*bcdUSB */ /* changed to USB version 2.01 
00127           //                                     in order to support LPM L1 suspend
00128            //                                    resume test of USBCV3.0*/
00129 #else  
00130     0x00,                       /* bcdUSB */
00131 #endif
00132     0x02,
00133     0x02,                        /*bDeviceClass*/
00134     0x02,                       /*bDeviceSubClass*/
00135     0x00,                       /*bDeviceProtocol*/
00136     USB_MAX_EP0_SIZE,          /*bMaxPacketSize*/
00137     LOBYTE(USBD_VID),           /*idVendor*/
00138     HIBYTE(USBD_VID),           /*idVendor*/
00139     LOBYTE(USBD_PID_FS),           /*idVendor*/
00140     HIBYTE(USBD_PID_FS),           /*idVendor*/
00141     0x00,                       /*bcdDevice rel. 2.00*/
00142     0x02,
00143     USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/
00144     USBD_IDX_PRODUCT_STR,       /*Index of product string*/
00145     USBD_IDX_SERIAL_STR,        /*Index of serial number string*/
00146     USBD_MAX_NUM_CONFIGURATION  /*bNumConfigurations*/
00147   } ; 
00148 /* USB_DeviceDescriptor */
00149 
00150 
00151 /*
00152 
00153 {
00154 0x12,            // Descriptor size in bytes
00155  0x01,            // DEVICE descriptor type
00156  0x00,
00157  0x02,          // USB version, BCD (2.0)
00158  0x02,             // Class: CDC
00159  0x00,            // Subclass: none
00160  0x00,            // Protocol: none
00161  0x08,            // Max. packet size, Endpoint 0
00162  0x25,
00163  0x09,          // USB Vendor ID
00164  0x60,
00165  0x90,          // USB Product ID
00166  0x00,
00167  0x01,          // Device release, BCD (1.0)
00168  0x00,            // Manufacturer string index
00169  0x00,            // Product string index
00170  0x01,            // Serial number string index
00171  0x01             // Number of configurations
00172 };*/
00173 /* BOS descriptor */
00174 #if (USBD_LPM_ENABLED == 1)
00175 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
00176   #pragma data_alignment=4   
00177 #endif
00178 __ALIGN_BEGIN  uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
00179 {
00180   0x5,
00181   USB_DESC_TYPE_BOS,
00182   0xC,
00183   0x0,
00184   0x1,  /* 1 device capability */
00185         /* device capability*/
00186   0x7,
00187   USB_DEVICE_CAPABITY_TYPE,
00188   0x2,
00189   0x2, /*LPM capability bit set */
00190   0x0,
00191   0x0,
00192   0x0
00193 };
00194 #endif
00195 
00196 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
00197   #pragma data_alignment=4   
00198 #endif
00199 
00200 /* USB Standard Device Descriptor */
00201 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
00202 {
00203      USB_LEN_LANGID_STR_DESC,         
00204      USB_DESC_TYPE_STRING,       
00205      LOBYTE(USBD_LANGID_STRING),
00206      HIBYTE(USBD_LANGID_STRING), 
00207 };
00208 
00209 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
00210   #pragma data_alignment=4   
00211 #endif
00212 __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
00213 /**
00214   * @}
00215   */ 
00216 
00217 /** @defgroup USBD_DESC_Private_FunctionPrototypes
00218   * @{
00219   */ 
00220 /**
00221   * @}
00222   */ 
00223 
00224 /** @defgroup USBD_DESC_Private_Functions
00225   * @{
00226   */ 
00227 
00228 /**
00229 * @brief  USBD_FS_DeviceDescriptor 
00230 *         return the device descriptor
00231 * @param  speed : current device speed
00232 * @param  length : pointer to data length variable
00233 * @retval pointer to descriptor buffer
00234 */
00235 uint8_t *  USBD_FS_DeviceDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
00236 {
00237   *length = sizeof(USBD_FS_DeviceDesc);
00238   return USBD_FS_DeviceDesc;
00239 }
00240 
00241 /**
00242 * @brief  USBD_FS_LangIDStrDescriptor 
00243 *         return the LangID string descriptor
00244 * @param  speed : current device speed
00245 * @param  length : pointer to data length variable
00246 * @retval pointer to descriptor buffer
00247 */
00248 uint8_t *  USBD_FS_LangIDStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
00249 {
00250   *length =  sizeof(USBD_LangIDDesc);  
00251   return USBD_LangIDDesc;
00252 }
00253 
00254 /**
00255 * @brief  USBD_FS_ProductStrDescriptor 
00256 *         return the product string descriptor
00257 * @param  speed : current device speed
00258 * @param  length : pointer to data length variable
00259 * @retval pointer to descriptor buffer
00260 */
00261 uint8_t *  USBD_FS_ProductStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
00262 {
00263   if(speed == 0)
00264   {   
00265     USBD_GetString ((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
00266   }
00267   else
00268   {
00269     USBD_GetString ((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);    
00270   }
00271   return USBD_StrDesc;
00272 }
00273 
00274 /**
00275 * @brief  USBD_FS_ManufacturerStrDescriptor 
00276 *         return the manufacturer string descriptor
00277 * @param  speed : current device speed
00278 * @param  length : pointer to data length variable
00279 * @retval pointer to descriptor buffer
00280 */
00281 uint8_t *  USBD_FS_ManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
00282 {
00283   USBD_GetString ((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
00284   return USBD_StrDesc;
00285 }
00286 
00287 /**
00288 * @brief  USBD_FS_SerialStrDescriptor 
00289 *         return the serial number string descriptor
00290 * @param  speed : current device speed
00291 * @param  length : pointer to data length variable
00292 * @retval pointer to descriptor buffer
00293 */
00294 uint8_t *  USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
00295 {
00296   if(speed  == USBD_SPEED_HIGH)
00297   {    
00298     USBD_GetString ((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
00299   }
00300   else
00301   {
00302     USBD_GetString ((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);    
00303   }
00304   return USBD_StrDesc;
00305 }
00306 
00307 /**
00308 * @brief  USBD_FS_ConfigStrDescriptor 
00309 *         return the configuration string descriptor
00310 * @param  speed : current device speed
00311 * @param  length : pointer to data length variable
00312 * @retval pointer to descriptor buffer
00313 */
00314 uint8_t *  USBD_FS_ConfigStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
00315 {
00316   if(speed  == USBD_SPEED_HIGH)
00317   {  
00318     USBD_GetString ((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
00319   }
00320   else
00321   {
00322     USBD_GetString ((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length); 
00323   }
00324   return USBD_StrDesc;  
00325 }
00326 
00327 /**
00328 * @brief  USBD_HS_InterfaceStrDescriptor 
00329 *         return the interface string descriptor
00330 * @param  speed : current device speed
00331 * @param  length : pointer to data length variable
00332 * @retval pointer to descriptor buffer
00333 */
00334 uint8_t *  USBD_FS_InterfaceStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
00335 {
00336   if(speed == 0)
00337   {
00338     USBD_GetString ((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
00339   }
00340   else
00341   {
00342     USBD_GetString ((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
00343   }
00344   return USBD_StrDesc;  
00345 }
00346 #if (USBD_LPM_ENABLED == 1)
00347 /**
00348   * @brief  USBD_FS_USR_BOSDescriptor 
00349   *         return the BOS descriptor
00350   * @param  speed : current device speed
00351   * @param  length : pointer to data length variable
00352   * @retval pointer to descriptor buffer
00353   */
00354 uint8_t *USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed , uint16_t *length)
00355 {
00356   *length = sizeof(USBD_FS_BOSDesc);
00357   return (uint8_t*)USBD_FS_BOSDesc;
00358 }
00359 #endif
00360 /**
00361   * @}
00362   */ 
00363 
00364 /**
00365   * @}
00366   */ 
00367 
00368 /**
00369   * @}
00370   */ 
00371 
00372 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/