From 2d44201de7a3691e790a6f9d4a815378950ce6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Tue, 15 Sep 2020 12:31:00 +0200 Subject: [PATCH] automatic driver installation on Windows using WCID, changed PID to avoid collision --- Software/PC_Application/Device/device.cpp | 11 +- Software/PC_Application/Device/device.h | 10 +- .../Generator/signalgenwidget.cpp | 2 +- .../Generator/signalgenwidget.ui | 4 +- Software/VNA_embedded/.cproject | 1228 ++++++----------- .../.settings/language.settings.xml | 67 +- .../Drivers/USB/Core/Inc/usbd_def.h | 2 + .../Drivers/USB/Core/Inc/usbd_desc.h | 2 + .../Drivers/USB/Core/Src/usbd_ctlreq.c | 8 + .../Drivers/USB/Core/Src/usbd_desc.c | 25 +- .../Application/Drivers/USB/usb.c | 26 +- 11 files changed, 512 insertions(+), 873 deletions(-) diff --git a/Software/PC_Application/Device/device.cpp b/Software/PC_Application/Device/device.cpp index cb437f7..0667365 100644 --- a/Software/PC_Application/Device/device.cpp +++ b/Software/PC_Application/Device/device.cpp @@ -263,8 +263,15 @@ void Device::SearchDevices(std::function continue; } - if (desc.idVendor != VID || desc.idProduct != PID) { - /* Not the correct IDs */ + bool correctID = false; + int numIDs = sizeof(IDs)/sizeof(IDs[0]); + for(int i=0;i - Signalgenerator - + SignalgeneratorWidget + 0 diff --git a/Software/VNA_embedded/.cproject b/Software/VNA_embedded/.cproject index 85592b6..24b9043 100644 --- a/Software/VNA_embedded/.cproject +++ b/Software/VNA_embedded/.cproject @@ -1,822 +1,412 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/VNA_embedded/.settings/language.settings.xml b/Software/VNA_embedded/.settings/language.settings.xml index aadbc97..2892ea2 100644 --- a/Software/VNA_embedded/.settings/language.settings.xml +++ b/Software/VNA_embedded/.settings/language.settings.xml @@ -1,48 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/VNA_embedded/Application/Drivers/USB/Core/Inc/usbd_def.h b/Software/VNA_embedded/Application/Drivers/USB/Core/Inc/usbd_def.h index b1e7968..b528812 100644 --- a/Software/VNA_embedded/Application/Drivers/USB/Core/Inc/usbd_def.h +++ b/Software/VNA_embedded/Application/Drivers/USB/Core/Inc/usbd_def.h @@ -221,6 +221,8 @@ typedef struct #if (USBD_LPM_ENABLED == 1U) uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); #endif + // WCID descriptors + uint8_t *(*GetMicrosoftOSStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length); } USBD_DescriptorsTypeDef; /* USB Device handle structure */ diff --git a/Software/VNA_embedded/Application/Drivers/USB/Core/Inc/usbd_desc.h b/Software/VNA_embedded/Application/Drivers/USB/Core/Inc/usbd_desc.h index 9e0bb00..35a000e 100644 --- a/Software/VNA_embedded/Application/Drivers/USB/Core/Inc/usbd_desc.h +++ b/Software/VNA_embedded/Application/Drivers/USB/Core/Inc/usbd_desc.h @@ -52,6 +52,8 @@ #define USB_SIZ_STRING_SERIAL 0x1A +#define USB_WCID_VENDOR_CODE 0x56 + /* USER CODE BEGIN EXPORTED_CONSTANTS */ /* USER CODE END EXPORTED_CONSTANTS */ diff --git a/Software/VNA_embedded/Application/Drivers/USB/Core/Src/usbd_ctlreq.c b/Software/VNA_embedded/Application/Drivers/USB/Core/Src/usbd_ctlreq.c index c3e7ecb..81bc53d 100644 --- a/Software/VNA_embedded/Application/Drivers/USB/Core/Src/usbd_ctlreq.c +++ b/Software/VNA_embedded/Application/Drivers/USB/Core/Src/usbd_ctlreq.c @@ -458,6 +458,14 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len); break; + case 0xEE: + // Windows specific OS string descriptor + if(pdev->pDesc->GetMicrosoftOSStrDescriptor) { + pbuf = pdev->pDesc->GetMicrosoftOSStrDescriptor(pdev->dev_speed, &len); + } else { + USBD_CtlError(pdev , req); + } + break; default: #if (USBD_SUPPORT_USER_STRING == 1U) pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue) , &len); diff --git a/Software/VNA_embedded/Application/Drivers/USB/Core/Src/usbd_desc.c b/Software/VNA_embedded/Application/Drivers/USB/Core/Src/usbd_desc.c index c9f4f72..7535574 100644 --- a/Software/VNA_embedded/Application/Drivers/USB/Core/Src/usbd_desc.c +++ b/Software/VNA_embedded/Application/Drivers/USB/Core/Src/usbd_desc.c @@ -64,7 +64,7 @@ */ #define USBD_VID 0x0483 -#define USBD_PID_FS 0x564E +#define USBD_PID_FS 0x4121 #define USBD_LANGID_STRING 0x0409 #define USBD_MANUFACTURER_STRING "STMicroelectronics" #define USBD_PRODUCT_STRING_FS "VNA" @@ -123,6 +123,7 @@ 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); +uint8_t * USBD_FS_MicrosoftOSStrDescriptor(USBD_SpeedTypeDef speed , uint16_t *length); #ifdef USBD_SUPPORT_USER_STRING_DESC uint8_t * USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); @@ -153,6 +154,7 @@ USBD_DescriptorsTypeDef FS_Desc = #if (USBD_LPM_ENABLED == 1) , USBD_FS_USR_BOSDescriptor #endif /* (USBD_LPM_ENABLED == 1) */ +, USBD_FS_MicrosoftOSStrDescriptor }; #if defined ( __ICCARM__ ) /* IAR Compiler */ @@ -211,6 +213,21 @@ __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = }; #endif /* (USBD_LPM_ENABLED == 1) */ +__ALIGN_BEGIN uint8_t USBD_FS_MicrosoftOSDescr[18] __ALIGN_END = +{ + 0x12, /* length */ + USB_DESC_TYPE_STRING, + 0x4D, 0x00, /* 7 word unicode string "MSFT100" */ + 0x53, 0x00, + 0x46, 0x00, + 0x54, 0x00, + 0x31, 0x00, + 0x30, 0x00, + 0x30, 0x00, + USB_WCID_VENDOR_CODE, /* Vendor code */ + 0x00, /* Padding */ +}; + /** * @} */ @@ -385,6 +402,12 @@ uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) } #endif /* (USBD_LPM_ENABLED == 1) */ +uint8_t * USBD_FS_MicrosoftOSStrDescriptor(USBD_SpeedTypeDef speed , uint16_t *length) { + UNUSED(speed); + *length = sizeof(USBD_FS_MicrosoftOSDescr); + return (uint8_t*)USBD_FS_MicrosoftOSDescr; +} + /** * @brief Create the serial number string descriptor * @param None diff --git a/Software/VNA_embedded/Application/Drivers/USB/usb.c b/Software/VNA_embedded/Application/Drivers/USB/usb.c index 9bceec2..8eb2a7b 100644 --- a/Software/VNA_embedded/Application/Drivers/USB/usb.c +++ b/Software/VNA_embedded/Application/Drivers/USB/usb.c @@ -10,6 +10,7 @@ USBD_HandleTypeDef hUsbDeviceFS; static uint8_t USBD_Class_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx); static uint8_t USBD_Class_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx); +static uint8_t USBD_Class_Setup(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req); static uint8_t USBD_Class_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); static uint8_t USBD_Class_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum); static uint8_t *USBD_Class_GetFSCfgDesc (uint16_t *length); @@ -24,7 +25,7 @@ USBD_ClassTypeDef USBD_ClassDriver = { USBD_Class_Init, USBD_Class_DeInit, - NULL, + USBD_Class_Setup, NULL, NULL, USBD_Class_DataIn, @@ -103,6 +104,22 @@ __ALIGN_BEGIN uint8_t USBD_CfgFSDesc[USB_CONFIG_DESC_SIZ] __ALIGN_END = 0x00 /* bInterval */ }; +// See https://github.com/pbatard/libwdi/wiki/WCID-Devices for descriptor data +// This requests to load the WinUSB driver for this device +__ALIGN_BEGIN const uint8_t USBD_MicrosoftCompatibleID[40] __ALIGN_END = +{ + 0x28, 0x00, 0x00, 0x00, + 0x00, 0x01, + 0x04, 0x00, + 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, + 0x01, + 0x57, 0x49, 0x4E, 0x55, 0x53, 0x42, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + static uint8_t USBD_Class_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { // Open endpoints and start reception @@ -120,6 +137,13 @@ static uint8_t USBD_Class_DeInit(USBD_HandleTypeDef *pdev, USBD_LL_CloseEP(pdev, EP_LOG_IN_ADDRESS); return USBD_OK; } +static uint8_t USBD_Class_Setup(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { + if(req->wIndex == 0x0004 && req->bRequest == USB_WCID_VENDOR_CODE && req->bmRequest == 0xC0) { + // This is a request for the Microsoft Compatible IF Feature Descriptor + USBD_CtlSendData (pdev, (uint8_t *)(void *)USBD_MicrosoftCompatibleID, req->wLength); + } + return USBD_OK; +} static uint8_t USBD_Class_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) { // A bulk transfer is complete when the endpoint does on of the following: // - Has transferred exactly the amount of data expected