Skip to content

Commit

Permalink
Refs #1655, #1797. Added support for automatic WinUSB driver install …
Browse files Browse the repository at this point in the history
…and used unique ID for the USB serial number, where available.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@1078 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
  • Loading branch information
feaser committed Jun 27, 2023
1 parent c280af5 commit afd5cb1
Show file tree
Hide file tree
Showing 513 changed files with 112,327 additions and 124,399 deletions.

Large diffs are not rendered by default.

3,234 changes: 1,643 additions & 1,591 deletions Target/Demo/ARMCM33_STM32L5_Nucleo_L552ZE_CubeIDE/Boot/Debug/openblt_stm32l552.srec

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ __ALIGN_BEGIN static uint8_t USBD_Bulk_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER
{
USB_LEN_DEV_QUALIFIER_DESC,
USB_DESC_TYPE_DEVICE_QUALIFIER,
0x00,
0x02,
0x10,
0x01,
0x00,
0x00,
0x00,
Expand Down Expand Up @@ -192,6 +192,62 @@ __ALIGN_BEGIN uint8_t USBD_Bulk_CfgFSDesc[USB_BULK_CONFIG_DESC_SIZ] __ALIGN_END
} ;


#if (USBD_WINUSB_ENABLED == 1)
/* USB Bulk device Microsoft OS 2.0 Descriptor Set. */
#define USB_LEN_MSOS20_DESC (0x9E)

__ALIGN_BEGIN uint8_t USBD_Bulk_MSOS20Desc[USB_LEN_MSOS20_DESC] __ALIGN_END =
{
0x0A, 0x00, /* Descriptor size (10 bytes) */
0x00, 0x00, /* MS OS 2.0 descriptor set header */
0x00, 0x00, 0x03, 0x06, /* Windows version (8.1) (0x06030000) */
0x9E, 0x00, /* Size, MS OS 2.0 descriptor set (158 bytes) */

/* Microsoft OS 2.0 compatible ID descriptor */
0x14, 0x00, /* Descriptor size (20 bytes) */
0x03, 0x00, /* MS OS 2.0 compatible ID descriptor */
0x57, 0x49, 0x4E, 0x55, 0x53, 0x42, 0x00, 0x00, /* WINUSB string */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Sub-compatible ID */

/* Registry property descriptor */
0x80, 0x00, /* Descriptor size (130 bytes) */
0x04, 0x00, /* Registry Property descriptor */
0x01, 0x00, /* Strings are null-terminated Unicode */
0x28, 0x00, /* Size of Property Name (40 bytes) */

/* Property Name ("DeviceInterfaceGUID") */
0x44, 0x00, 0x65, 0x00, 0x76, 0x00, 0x69, 0x00, 0x63, 0x00, 0x65, 0x00,
0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x72, 0x00, 0x66, 0x00,
0x61, 0x00, 0x63, 0x00, 0x65, 0x00, 0x47, 0x00, 0x55, 0x00, 0x49, 0x00,
0x44, 0x00, 0x00, 0x00,

0x4E, 0x00, /* Size of Property Data (78 bytes) */

/* Vendor-defined Property Data: "{807999C3-E4E0-40EA-8188-48E852B54F2B}\0" */
0x7B, 0x00, 0x38, 0x00, /* {8 */
0x30, 0x00, 0x37, 0x00, /* 07 */
0x39, 0x00, 0x39, 0x00, /* 99 */
0x39, 0x00, 0x43, 0x00, /* 9C */
0x33, 0x00, 0x2D, 0x00, /* 3- */
0x45, 0x00, 0x34, 0x00, /* E4 */
0x45, 0x00, 0x30, 0x00, /* E0 */
0x2D, 0x00, 0x34, 0x00, /* -4 */
0x30, 0x00, 0x45, 0x00, /* 0E */
0x41, 0x00, 0x2D, 0x00, /* A- */
0x38, 0x00, 0x31, 0x00, /* 81 */
0x38, 0x00, 0x38, 0x00, /* 88 */
0x2D, 0x00, 0x34, 0x00, /* -4 */
0x38, 0x00, 0x45, 0x00, /* 8E */
0x38, 0x00, 0x35, 0x00, /* 85 */
0x32, 0x00, 0x42, 0x00, /* 2B */
0x35, 0x00, 0x34, 0x00, /* 54 */
0x46, 0x00, 0x32, 0x00, /* F2 */
0x42, 0x00, 0x7D, 0x00, /* B} */
0x00, 0x00 /* \0 */
};
#endif /* (USBD_WINUSB_ENABLED == 1) */


/**
* @}
*/
Expand Down Expand Up @@ -269,6 +325,25 @@ static uint8_t USBD_Bulk_Setup (USBD_HandleTypeDef *pdev,

switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
#if (USBD_WINUSB_ENABLED == 1)
case USB_REQ_TYPE_VENDOR:
switch (req->bRequest)
{
case USB_BULK_MS_VENDORCODE: /* bMS_VendorCode */
if (req->wIndex == 7) /*This is defined by the MS spec (Table 6)*/
{
pbuf = USBD_Bulk_MSOS20Desc;
len = USB_LEN_MSOS20_DESC;
USBD_CtlSendData(pdev, pbuf, len);
break;
}

default:
break;
}
break;
#endif /* (USBD_WINUSB_ENABLED == 1) */

case USB_REQ_TYPE_STANDARD:
switch (req->bRequest)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#define USB_BULK_CONFIG_DESC_SIZ 32
#define USB_BULK_DESC_SIZ (32-9)

#define USB_BULK_MS_VENDORCODE 0x01 /* bMS_VendorCode */

#define BULK_DESCRIPTOR_TYPE 0x21


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
******************************************************************************
* @file : App/usbd_desc.c
* @version : v3.0_Cube
* @version : v2.0_Cube
* @brief : This file implements the USB device descriptors.
******************************************************************************
* @attention
Expand All @@ -23,6 +23,7 @@
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_conf.h"
#include "usbd_bulk.h"

/* USER CODE BEGIN INCLUDE */

Expand Down Expand Up @@ -68,9 +69,12 @@
#define USBD_MANUFACTURER_STRING "OpenBLT User"
#define USBD_PID_FS 0x60ac
#define USBD_PRODUCT_STRING_FS "WinUSB Bulk Device"
#define USBD_SERIALNUMBER_STRING_FS "00000000050C"
#define USBD_CONFIGURATION_STRING_FS "Default"
#define USBD_INTERFACE_STRING_FS "WinUSB Bulk Interface"

#define USB_SIZ_BOS_DESC 0x21

/* USER CODE BEGIN PRIVATE_DEFINES */

/* USER CODE END PRIVATE_DEFINES */
Expand Down Expand Up @@ -109,7 +113,7 @@ static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len);
*/

/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
* @brief Private functions declaration.
* @brief Private functions declaration for FS.
* @{
*/

Expand All @@ -120,6 +124,9 @@ uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
#if (USBD_WINUSB_ENABLED == 1)
uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
#endif

/**
* @}
Expand All @@ -139,6 +146,9 @@ USBD_DescriptorsTypeDef FS_Desc =
, USBD_FS_SerialStrDescriptor
, USBD_FS_ConfigStrDescriptor
, USBD_FS_InterfaceStrDescriptor
#if (USBD_WINUSB_ENABLED == 1)
, USBD_FS_USR_BOSDescriptor
#endif /* (USBD_LPM_ENABLED == 1) */
};

#if defined ( __ICCARM__ ) /* IAR Compiler */
Expand All @@ -149,7 +159,12 @@ __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
{
0x12, /*bLength */
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
#if (USBD_WINUSB_ENABLED == 1)
0x01, /*bcdUSB changed to USB version 2.01 to enable BOS */
/*descriptor for reading the MS OS 2.0 descriptors. */
#else
0x00, /*bcdUSB */
#endif
0x02,
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
Expand All @@ -159,15 +174,46 @@ __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
HIBYTE(USBD_VID), /*idVendor*/
LOBYTE(USBD_PID_FS), /*idProduct*/
HIBYTE(USBD_PID_FS), /*idProduct*/
0x00, /*bcdDevice rel. 2.00*/
0x02,
0x00, /*bcdDevice rel. 1.00*/
0x01,
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
USBD_IDX_PRODUCT_STR, /*Index of product string*/
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
};

/* USB_DeviceDescriptor */
/** BOS descriptor. */
#if (USBD_WINUSB_ENABLED == 1)
#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma data_alignment=4
#endif /* defined ( __ICCARM__ ) */
__ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
{
0x05, /* Descriptor size (5 bytes) */
USB_DESC_TYPE_BOS, /* Descriptor type (BOS) */
0x21, 0x00, /* Length of this + subordinate descriptors (33 bytes) */
0x01, /* Number of subordinate descriptors */

/* Microsoft OS 2.0 Platform Capability Descriptor */
0x1C, /* Descriptor size (28 bytes) */
USB_DEVICE_CAPABITY_TYPE, /* Descriptor type (Device Capability) */
0x05, /* Capability type (Platform) */
0x00, /* Reserved */

/* MS OS 2.0 Platform Capability ID (D8DD60DF-4589-4CC7-9CD2-659D9E648A9F) */
0xDF, 0x60, 0xDD, 0xD8,
0x89, 0x45,
0xC7, 0x4C,
0x9C, 0xD2,
0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,

0x00, 0x00, 0x03, 0x06, /* Windows version (8.1) (0x06030000) */
0x9E, 0x00, /* Size, MS OS 2.0 descriptor set (158 bytes) */
USB_BULK_MS_VENDORCODE, /* Vendor-assigned bMS_VendorCode */
0x00 /* Doesn’t support alternate enumeration */
};
#endif /* (USBD_WINUSB_ENABLED == 1) */

/**
* @}
Expand All @@ -182,7 +228,7 @@ __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
#pragma data_alignment=4
#endif /* defined ( __ICCARM__ ) */

/** USB lang indentifier descriptor. */
/** USB lang identifier descriptor. */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
{
USB_LEN_LANGID_STR_DESC,
Expand Down Expand Up @@ -287,7 +333,7 @@ uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
* ID */
Get_SerialNum();
/* USER CODE BEGIN USBD_FS_SerialStrDescriptor */

/* USER CODE END USBD_FS_SerialStrDescriptor */
return (uint8_t *) USBD_StringSerial;
}
Expand Down Expand Up @@ -330,9 +376,24 @@ uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
return USBD_StrDesc;
}

#if (USBD_WINUSB_ENABLED == 1)
/**
* @brief Return the BOS descriptor
* @param speed : Current device speed
* @param length : Pointer to data length variable
* @retval Pointer to descriptor buffer
*/
uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
UNUSED(speed);
*length = sizeof(USBD_FS_BOSDesc);
return (uint8_t*)USBD_FS_BOSDesc;
}
#endif /* (USBD_WINUSB_ENABLED == 1) */

/**
* @brief Create the serial number string descriptor
* @param None
* @brief Create the serial number string descriptor
* @param None
* @retval None
*/
static void Get_SerialNum(void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
******************************************************************************
* @file : usbd_desc.c
* @version : v3.0_Cube
* @version : v2.0_Cube
* @brief : Header for usbd_conf.c file.
******************************************************************************
* @attention
Expand All @@ -18,10 +18,9 @@
******************************************************************************
*/
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USBD_DESC__C__
#define __USBD_DESC__C__
#ifndef __USBD_DESC__H__
#define __USBD_DESC__H__

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -51,7 +50,7 @@
#define DEVICE_ID2 (UID_BASE + 0x4)
#define DEVICE_ID3 (UID_BASE + 0x8)

#define USB_SIZ_STRING_SERIAL 0x1A
#define USB_SIZ_STRING_SERIAL 0x1A

/* USER CODE BEGIN EXPORTED_CONSTANTS */

Expand Down Expand Up @@ -141,6 +140,6 @@ extern USBD_DescriptorsTypeDef FS_Desc;
}
#endif

#endif /* __USBD_DESC__C__ */
#endif /* __USBD_DESC__H__ */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
/* USER CODE END INCLUDE */

/** @addtogroup USBD_OTG_DRIVER
* @brief Driver for Usb device.
* @{
*/

Expand All @@ -53,9 +52,6 @@
* @{
*/

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/**
* @}
*/
Expand All @@ -74,9 +70,13 @@
/*---------- -----------*/
#define USBD_DEBUG_LEVEL 0U
/*---------- -----------*/
#define USBD_LPM_ENABLED 1U
/*---------- -----------*/
#define USBD_SELF_POWERED 1U
/*---------- -----------*/
/* Enable/disable the loading of the WinUSB GUID through MS OS 2.0 descriptors. This
* makes it possible to automatically install WinUSB devices without having to provide
* a device specific INF file.
*/
#define USBD_WINUSB_ENABLED 1U

/****************************************/
/* #define for FS and HS identification */
Expand All @@ -94,21 +94,30 @@
* @{
*/

#if (USBD_WINUSB_ENABLED == 1)
/* Reading out the MS OS 2.0 descriptors, requires support for BOS descriptors. This
* is currently enabled in the ST USB stack by enabled the USBD_LPM_ENABLED feature.
*/
#define USBD_LPM_ENABLED 1U
#endif

/* Memory management macros */

/** Alias for memory allocation. */
#define USBD_malloc (void *)USBD_static_malloc
#define USBD_malloc /* Not used */

/** Alias for memory release. */
#define USBD_free USBD_static_free
#define USBD_free /* Not used */

/** Alias for memory set. */
#define USBD_memset memset
#define USBD_memset /* Not used */

/** Alias for memory copy. */
#define USBD_memcpy memcpy
#define USBD_memcpy /* Not used */

/** Alias for delay. */
#define USBD_Delay HAL_Delay

/* DEBUG macros */

#if (USBD_DEBUG_LEVEL > 0)
Expand Down Expand Up @@ -154,8 +163,6 @@
*/

/* Exported functions -------------------------------------------------------*/
void *USBD_static_malloc(uint32_t size);
void USBD_static_free(void *p);

/**
* @}
Expand Down
Loading

0 comments on commit afd5cb1

Please sign in to comment.