我正在使用 NXP LPC1788 微控制器,我正在尝试在主机上创建一个驱动程序以通过 USB 与其通信。我相信我已经设法让设备正确处理标准 USB 请求(PC 能够正确读取字符串描述符)。
不过,我在编写示例 USB 驱动程序并为设备安装它时遇到了麻烦。我正在使用 Microsoft Visual Studio 2013。我的步骤是:
创建一个 WinUSB 应用程序,它会生成一个“驱动程序”和“驱动程序包”项目。
修改生成的 INF 文件以使用我设备的 VID 和 PID。
构建项目 - 都成功构建。输出文件夹包含一个 INF 文件、一个目录文件和 WdfCoinstaller01011.dll。
通过 USB 插入微控制器,转到设备管理器→更新驱动程序软件...,浏览到包含 INF 文件的文件夹并选择它。
这会导致出现以下屏幕:
- 我选择“仍然安装此驱动程序软件”。片刻之后,它显示了这个屏幕:
我的 INF 文件如下所示:
;
; TestCubeDriver.inf
;
; Installs WinUsb
;
[Version]
Signature = "$Windows NT$"
Class = USBDevice
ClassGUID = {88BAE032-5A81-49f0-BC3D-A4FF138216D6}
Provider = %ManufacturerName%
CatalogFile=TestCubeDriver.cat
DriverVer=04/16/2014,15.55.4.44
; ========== Manufacturer/Models sections ===========
[Manufacturer]
%ManufacturerName% = Standard,NTamd64
[Standard.NTamd64]
%DeviceName% =USB_Install, USB\VID_0483&PID_5720
; ========== Class definition ===========
[ClassInstall32]
AddReg = ClassInstall_AddReg
[ClassInstall_AddReg]
HKR,,,,%ClassName%
HKR,,NoInstallClass,,1
HKR,,IconPath,%REG_MULTI_SZ%,"%systemroot%\system32\setupapi.dll,-20"
HKR,,LowerLogoVersion,,5.2
; =================== Installation ===================
[USB_Install]
Include=winusb.inf
Needs=WINUSB.NT
[USB_Install.Services]
Include=winusb.inf
AddService=WinUsb,0x00000002,WinUsb_ServiceInstall
[WinUsb_ServiceInstall]
DisplayName = %WinUsb_SvcDesc%
ServiceType = 1
StartType = 3
ErrorControl = 1
ServiceBinary = %12%\WinUSB.sys
[USB_Install.HW]
AddReg=Dev_AddReg
[Dev_AddReg]
; By default, USBDevice class uses iProduct descriptor to name the device in
; Device Manager on Windows 8 and higher.
; Uncomment for this device to use %DeviceName% on Windows 8 and higher:
;HKR,,FriendlyName,,%DeviceName%
HKR,,DeviceInterfaceGUIDs,0x10000,"{fcb251a5-6a1f-4e5b-9df8-e8de91d04cfe}"
[USB_Install.CoInstallers]
AddReg=CoInstallers_AddReg
CopyFiles=CoInstallers_CopyFiles
[CoInstallers_AddReg]
HKR,,CoInstallers32,0x00010000,"WdfCoInstaller01011.dll,WdfCoInstaller"
[CoInstallers_CopyFiles]
WdfCoInstaller01011.dll
[DestinationDirs]
CoInstallers_CopyFiles=11
; ================= Source Media Section =====================
[SourceDisksNames]
1 = %DiskName%
[SourceDisksFiles]
WdfCoInstaller01011.dll=1
; =================== Strings ===================
[Strings]
ManufacturerName=""
ClassName="Universal Serial Bus devices"
DiskName="TestCubeDriver Installation Disk"
WinUsb_SvcDesc="WinUSB Driver"
DeviceName="TestCubeDriver Device"
REG_MULTI_SZ = 0x00010000
.
我的 setupapi.dev.log 文件的相关部分在此处给出。日志中多次出现以下类型的行:
sig: Key = testcubedriver.inf
sig: FilePath = C:\Windows\System32\DriverStore\Temp\{1bf7c0e3-30cb-6135-d9b8-7d1ac87a6c7c}\testcubedriver.inf
sig: Catalog = C:\Windows\System32\DriverStore\Temp\{1bf7c0e3-30cb-6135-d9b8-7d1ac87a6c7c}\TestCubeDriver.cat
! sig: Verifying file against specific (valid) catalog failed! (0x800b0109)
! sig: Error 0x800b0109: A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.
还出现了以下情况:
ndv: Installing device...
dvi: {DIF_INSTALLDEVICE} 09:58:11.087
dvi: No class installer for 'TestCubeDriver Device'
dvi: CoInstaller 1: Enter 09:58:11.087
inf: Opened PNF: 'C:\Windows\INF\oem68.inf' ([strings])
!!! dvi: CoInstaller 1: failed(0xe0000101)!
!!! dvi: Error 0xe0000101: The required section was not found in the INF.
dvi: {DIF_INSTALLDEVICE - exit(0xe0000101)} 09:58:11.907
!!! ndv: Error(e0000101) installing device!
.
我对我的 USB 设备使用以下描述符:
/*----------------------------------------------------------------------------
* U S B - K e r n e l
*----------------------------------------------------------------------------
* Name: USBDESC.C
* Purpose: USB Descriptors
* Version: V1.10
*----------------------------------------------------------------------------
* This software is supplied "AS IS" without any warranties, express,
* implied or statutory, including but not limited to the implied
* warranties of fitness for purpose, satisfactory quality and
* noninfringement. Keil extends you a royalty-free right to reproduce
* and distribute executable files created using this software for use
* on NXP Semiconductors LPC family microcontroller devices only. Nothing
* else gives you the right to use this software.
*
* Copyright (c) 2005-2009 Keil Software.
*---------------------------------------------------------------------------*/
#include "lpc_types.h"
#include "usb.h"
#include "usbcore.h"
#include "usbhw.h"
/* USB Standard Device Descriptor */
const uint8_t USB_DeviceDescriptor[] = {
USB_DEVICE_DESC_SIZE, /* bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(0x0200), /* 2.00 */ /* bcdUSB */
0xFF, /* bDeviceClass */
0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */
USB_MAX_PACKET_SIZE, /* bMaxPacketSize0 */
WBVAL(0x0483), /* idVendor */
WBVAL(0x5720), /* idProduct */
WBVAL(0x0100), /* 1.00 */ /* bcdDevice */
0x04, /* iManufacturer */
0x30, /* iProduct */
0x42, /* iSerialNumber */
0x01 /* bNumConfigurations */
};
/* USB Configuration Descriptor */
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const uint8_t USB_ConfigDescriptor[] = {
/* Configuration 1 */
USB_CONFIGURATION_DESC_SIZE, /* bDescriptorType */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL( /* wTotalLength */
1*USB_CONFIGURATION_DESC_SIZE +
1*USB_INTERFACE_DESC_SIZE +
2*USB_ENDPOINT_DESC_SIZE
),
0x01, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
USB_CONFIG_SELF_POWERED /*|*/ /* bmAttributes */
/*USB_CONFIG_REMOTE_WAKEUP*/,
USB_CONFIG_POWER_MA(100), /* bMaxPower */
/* Interface 0, Alternate Setting 0, MSC Class */
USB_INTERFACE_DESC_SIZE, /* bLength */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
0x00, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
0x02, /* bNumEndpoints */
0xFF, /* bInterfaceClass */
0x0, /* bInterfaceSubClass */
0x0, /* bInterfaceProtocol */
0x5C, /* iInterface */
/* Interrupt In Endpoint */
USB_ENDPOINT_DESC_SIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_IN(2), /* bEndpointAddress */
USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
WBVAL(0x0040), /* wMaxPacketSize */
0xA, /* bInterval */
/* Interrupt Out Endpoint */
USB_ENDPOINT_DESC_SIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
USB_ENDPOINT_OUT(2), /* bEndpointAddress */
USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
WBVAL(0x0040), /* wMaxPacketSize */
0xA, /* bInterval */
/* Terminator */
0 /* bLength */
};
/* USB String Descriptor (optional) */
const uint8_t USB_StringDescriptor[] = {
/* Index 0x00: LANGID Codes */
0x04, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
WBVAL(0x0409), /* US English */ /* wLANGID */
/* Index 0x04: Manufacturer */
0x2C, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'A',0,
'T',0,
'P',0,
' ',0,
'I',0,
'n',0,
'd',0,
'u',0,
's',0,
't',0,
'r',0,
'i',0,
'e',0,
's',0,
' ',0,
'G',0,
'r',0,
'o',0,
'u',0,
'p',0,
' ',0,
/* Index 0x30: Product */
0x12, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'T',0,
'e',0,
's',0,
't',0,
'C',0,
'u',0,
'b',0,
'e',0,
' ',0,
/* Index 0x42: Serial Number */
0x1A, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'D',0,
'E',0,
'M',0,
'O',0,
'0',0,
'0',0,
'0',0,
'0',0,
'0',0,
'0',0,
'0',0,
'0',0,
/* Index 0x5C: Interface 0, Alternate Setting 0 */
0x0E, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'M',0,
'e',0,
'm',0,
'o',0,
'r',0,
'y',0,
};