C语言 使用自定义INF的微控制器的USB驱动程序安装问题

sigwle7e  于 2023-05-16  发布在  其他
关注(0)|答案(2)|浏览(198)

我正在使用恩智浦LPC 1788微控制器,并尝试在主机上创建一个驱动程序,以便通过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文件的相关部分被指定为here。日志中多次出现以下类型的行:

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,
};
sbtkgmzw

sbtkgmzw1#

我用自己的配置尝试了丹尼尔K建议的INF模板here

;This .inf file is a modified version of the example INF provided
;in the Microsoft document:
;"How to Use WinUSB to Communicate with a USB Device"

[Version]
Signature = "$Windows NT$"
Class = USBDevices
ClassGuid= {88BAE032-5A81-49f0-BC3D-A4FF138216D6}
Provider = %MFGNAME%
DriverVer=04/17/2014,1.0.0.0
CatalogFile=winusb.cat    ;CAT file needed for a signed driver pacakage
;------------------------------------------------------------------------------
; ========== Manufacturer/Models sections ===========
;------------------------------------------------------------------------------
[Manufacturer]
%MFGNAME% = MyDevice_WinUSB,NTx86,NTamd64

;------------------------------------------------------------------------------
;  Vendor and Product ID Definitions
;------------------------------------------------------------------------------
; When developing your custom USB device, the VID and PID used in the PC side
; application program and the firmware on the microcontroller must match.
; Modify the below lines to use your VID and PID.  Use the format as shown below.
; Note: One INF file can be used for multiple devices with different VID and PIDs.
; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line.
; There is a maximum number of devices that can be supported per line however.
; If you append a large number of VID/PIDs to the end of the line, and get a:
; "The data area passed to a system call is too small." error when trying to install
; the INF, try removing some of the VIDs/PIDs.
;------------------------------------------------------------------------------
[MyDevice_WinUSB.NTx86]
%DESCRIPTION% =USB_Install, USB\VID_0483&PID_5720

[MyDevice_WinUSB.NTamd64]
%DESCRIPTION% =USB_Install, USB\VID_0483&PID_5720

;=========================================================================================
;ClassInstall32 and ClassInstall_AddReg sections used to make new device manager category.
;=========================================================================================
[ClassInstall32]
AddReg=ClassInstall_AddReg

[ClassInstall_AddReg]
HKR,,,,%DEVICEMANAGERCATEGORY%
HKR,,Icon,,"-20"

; =================== 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.Wdf]
KmdfService=WINUSB, WinUsb_Install

[WinUSB_Install]
KmdfLibraryVersion=1.11

[USB_Install.HW]
AddReg=Dev_AddReg

[Dev_AddReg]
HKR,,DeviceInterfaceGUIDs,0x10000,"{fcb251a5-6a1f-4e5b-9df8-e8de91d04cfe}"
;When editing the GUID (the big hex number with dashes inside the squiggly 
;braces), make sure to write the intended PC application to use the same GUID.
;Otherwise the application won't be able to find the USB device properly.

[USB_Install.CoInstallers]
AddReg=CoInstallers_AddReg
CopyFiles=CoInstallers_CopyFiles

[CoInstallers_AddReg]
HKR,,CoInstallers32,0x00010000,"WdfCoInstaller01011.dll,WdfCoInstaller",

[CoInstallers_CopyFiles]
;WinUSBCoInstaller2.dll
WdfCoInstaller01011.dll

[DestinationDirs]
CoInstallers_CopyFiles=11

; ================= Source Media Section =====================

[SourceDisksNames]
1 = %DISK_NAME%

[SourceDisksFiles]
WdfCoInstaller01011.dll=1

; =================== Strings ===================

[Strings]
MFGNAME="ATP Industries Group" ; ManufacturerName
DESCRIPTION="TestCube" ; DeviceName
WinUSB_SvcDesc="WinUSB Device"
DISK_NAME="TestCubeDriver Installation Disk" ; DiskName
DEVICEMANAGERCATEGORY="Universal Serial Bus devices" ; ClassName

我的设备驱动程序已成功安装,设备管理器报告设备工作正常。我尝试运行我的应用程序,它能够找到我的设备,并检索有关它的详细信息.现在一切都正常了,我终于可以开始在应用程序方面工作了。
编辑:虽然现在一切正常,但我不知道原来的模板出了什么问题-谁能给我解释一下为什么第二个模板有效而第一个不行?

4ioopgfo

4ioopgfo2#

你运行的是32位Windows对吧原始文件不适合您的一个原因是它没有32位驱动程序的部分,它只有NTamd64部分。
从原始文件:

[Standard.NTamd64]
%DeviceName% =USB_Install, USB\VID_0483&PID_5720

在新文件中,MyDevice_WinUSB类似于Standard

[MyDevice_WinUSB.NTx86]
%DESCRIPTION% =USB_Install, USB\VID_0483&PID_5720

[MyDevice_WinUSB.NTamd64]
%DESCRIPTION% =USB_Install, USB\VID_0483&PID_5720

新文件具有旧文件所没有的额外部分。

相关问题