PIC32 USB CDC写入速度慢,并引发错误标志

时间:2016-06-24 16:43:39

标签: driver pic32

我目前正在尝试为pic32MZ2048EFH100编写代码,该代码通过USB CDC驱动程序协调地接收和响应来自PC上自定义程序的消息。

目前,pic能够发送和接收消息。但是,每当它向PC发送消息时,它总是错误地提升缓冲区80%满标志(EV_RX80FULL)。除此之外,PIC32相对较慢地发送消息。我正在从可正常工作的TERN板上移植固件。有时PC很快发送两条消息,TERN将发送一个确认,接收下一个,然后确认一个。另一方面,PIC将接收两个,然后发出两个确认,这将导致PC端程序出现问题。

两块板之间最大的区别在于驱动器是不同的,这是我们认为问题的起源。 PIC使用Microchip的驱动程序,.inf如下

;---------------------------------------------------------------------------------
;Note: When the driver package is signed, any modifications to this .inf file will
;break the signature, and the driver package will need to be re-signed.
;---------------------------------------------------------------------------------
; Modified Windows USB CDC Abstract Control Model Serial Driver Setup File
; Copyright (C) 2012 Microchip Technology Inc.

[Version] 
Signature="$Windows NT$" 
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 
Provider=%MFGNAME% 
CatalogFile=%MFGFILENAME%.cat
DriverVer=10/06/2014,5.1.2600.9

[Manufacturer] 
%MFGNAME%=DeviceList,NTamd64


;------------------------------------------------------------------------------
;  Vendor and Product ID Definitions
;------------------------------------------------------------------------------
; When developing your USB device, the VID and PID used in the PC side
; application program and the firmware on the microcontroller must match.
; The VID and PID can be changed in the USB device descriptor and on the below 
; lines in this file.  If you modify this .inf file to customize it for your
; device, please remove all existing Microchip (VID 0x04D8) entries from
; the device lists.
;------------------------------------------------------------------------------
[DeviceList]
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_000A
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0205
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0206
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_00DF&MI_00
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0057&MI_01
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_006E&MI_01
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0208&MI_00
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0208&MI_02
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_00DD&MI_00
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0207&MI_00

[DeviceList.NTamd64] 
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_000A
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0205
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0206
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_00DF&MI_00
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0057&MI_01
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_006E&MI_01
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0208&MI_00
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0208&MI_02
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_00DD&MI_00
%DESCRIPTION%=DriverInstall,USB\VID_04D8&PID_0207&MI_00


;------------------------------------------------------------------------------
;  Windows 32bit OSes Section
;------------------------------------------------------------------------------
[DriverInstall.nt] 
include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection 
AddReg=DriverInstall.nt.AddReg 

[DriverInstall.nt.AddReg] 
HKR,,DevLoader,,*ntkern 
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys 
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 

[DriverInstall.NT.Services]
include=mdmcpq.inf 
AddService=usbser, 0x00000002, LowerFilter_Service_Inst 


;------------------------------------------------------------------------------
;  Windows 64bit OSes Section
;------------------------------------------------------------------------------
[DriverInstall.NTamd64]
include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection
AddReg=DriverInstall.NTamd64.AddReg 

[DriverInstall.NTamd64.AddReg] 
HKR,,DevLoader,,*ntkern 
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys 
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 

[DriverInstall.NTamd64.Services] 
include=mdmcpq.inf 
AddService=usbser, 0x00000002, LowerFilter_Service_Inst 


;------------------------------------------------------------------------------
;  Common Sections
;------------------------------------------------------------------------------
[DestinationDirs] 
DefaultDestDir=12 

[SourceDisksNames]

[SourceDisksFiles]

[FakeModemCopyFileSection]

[LowerFilter_Service_Inst]
DisplayName= %SERVICE%
ServiceType= 1
StartType  = 3
ErrorControl = 0
ServiceBinary = %12%\usbser.sys


;------------------------------------------------------------------------------
;  String Definitions
;------------------------------------------------------------------------------
; These strings can be modified to customize your device
;------------------------------------------------------------------------------
[Strings]
MFGFILENAME="mchpcdc"
DRIVERFILENAME ="usbser"
MFGNAME="Microchip Technology, Inc."   ;This name shows up in the device manager properties for the device
DESCRIPTION="USB Serial Port"          ;This is the "friendly name" that shows up in the device manager
SERVICE="USB to Serial Driver"

以下是PIC上的USB配置:

/**************************************************
 * USB Device Function Driver Init Data
 **************************************************/
    const USB_DEVICE_CDC_INIT cdcInit0 =
    {
        .queueSizeRead = 1,
        .queueSizeWrite = 1,
        .queueSizeSerialStateNotification = 1
    };
/**************************************************
 * USB Device Layer Function Driver Registration 
 * Table
 **************************************************/
const USB_DEVICE_FUNCTION_REGISTRATION_TABLE funcRegistrationTable[1] =
{
    /* Function 1 */
    { 
        .configurationValue = 1,    /* Configuration value */ 
        .interfaceNumber = 0,       /* First interfaceNumber of this function */ 
        .speed = USB_SPEED_HIGH|USB_SPEED_FULL,    /* Function Speed */ 
        .numberOfInterfaces = 2,    /* Number of interfaces */
        .funcDriverIndex = 0,  /* Index of CDC Function Driver */
        .driver = (void*)USB_DEVICE_CDC_FUNCTION_DRIVER,    /* USB CDC function data exposed to device layer */
        .funcDriverInit = (void*)&cdcInit0    /* Function driver init data */
    },
};

/*******************************************
 * USB Device Layer Descriptors
 *******************************************/
/*******************************************
 *  USB Device Descriptor 
 *******************************************/
const USB_DEVICE_DESCRIPTOR deviceDescriptor =
{
    0x12,                           // Size of this descriptor in bytes
    USB_DESCRIPTOR_DEVICE,          // DEVICE descriptor type
    0x0200,                         // USB Spec Release Number in BCD format
    USB_CDC_CLASS_CODE,         // Class Code
    USB_CDC_SUBCLASS_CODE,      // Subclass code
    0x00,                       // Protocol code
    USB_DEVICE_EP0_BUFFER_SIZE,     // Max packet size for EP0, see system_config.h
    0x04D8,                         // Vendor ID
    0x000A,                         // Product ID
    0x0100,                         // Device release number in BCD format
    0x01,                           // Manufacturer string index
    0x02,                           // Product string index
    0x00,                           // Device serial number string index
    0x01                            // Number of possible configurations
};

/*******************************************
 *  USB Device Qualifier Descriptor for this
 *  demo.
 *******************************************/
const USB_DEVICE_QUALIFIER deviceQualifierDescriptor1 =
{
    0x0A,                               // Size of this descriptor in bytes
    USB_DESCRIPTOR_DEVICE_QUALIFIER,    // Device Qualifier Type
    0x0200,                             // USB Specification Release number
    USB_CDC_CLASS_CODE,         // Class Code
    USB_CDC_SUBCLASS_CODE,      // Subclass code
    0x00,                       // Protocol code
    USB_DEVICE_EP0_BUFFER_SIZE,         // Maximum packet size for endpoint 0
    0x01,                               // Number of possible configurations
    0x00                                // Reserved for future use.
};

/*******************************************
 *  USB High Speed Configuration Descriptor
 *******************************************/

const uint8_t highSpeedConfigurationDescriptor[]=
{
    /* Configuration Descriptor */

    0x09,                                               // Size of this descriptor in bytes
    USB_DESCRIPTOR_CONFIGURATION,                       // Descriptor Type
    67,0,                //(67 Bytes)Size of the Config descriptor.e
    2,                                               // Number of interfaces in this cfg
    0x01,                                               // Index value of this configuration
    0x00,                                               // Configuration string index
    USB_ATTRIBUTE_DEFAULT | USB_ATTRIBUTE_SELF_POWERED, // Attributes
    50,                                                 // Max power consumption (2X mA)

    /* Descriptor for Function 1 - CDC     */ 

    /* Interface Descriptor */

    0x09,                                           // Size of this descriptor in bytes
    USB_DESCRIPTOR_INTERFACE,                       // Descriptor Type
    0,                                           // Interface Number
    0x00,                                           // Alternate Setting Number
    0x01,                                           // Number of endpoints in this interface
    USB_CDC_COMMUNICATIONS_INTERFACE_CLASS_CODE,    // Class code
    USB_CDC_SUBCLASS_ABSTRACT_CONTROL_MODEL,        // Subclass code
    USB_CDC_PROTOCOL_AT_V250,                       // Protocol code
    0x00,                                           // Interface string index

    /* CDC Class-Specific Descriptors */

    sizeof(USB_CDC_HEADER_FUNCTIONAL_DESCRIPTOR),               // Size of the descriptor
    USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
    USB_CDC_FUNCTIONAL_HEADER,                                  // Type of functional descriptor
    0x20,0x01,                                                  // CDC spec version

    sizeof(USB_CDC_ACM_FUNCTIONAL_DESCRIPTOR),                  // Size of the descriptor
    USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
    USB_CDC_FUNCTIONAL_ABSTRACT_CONTROL_MANAGEMENT,             // Type of functional descriptor
    USB_CDC_ACM_SUPPORT_LINE_CODING_LINE_STATE_AND_NOTIFICATION,// bmCapabilities of ACM

    sizeof(USB_CDC_UNION_FUNCTIONAL_DESCRIPTOR_HEADER) + 1,     // Size of the descriptor
    USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
    USB_CDC_FUNCTIONAL_UNION,                                   // Type of functional descriptor
    0,                                                       // com interface number
    1,

    sizeof(USB_CDC_CALL_MANAGEMENT_DESCRIPTOR),                 // Size of the descriptor
    USB_CDC_DESC_CS_INTERFACE,                                  // CS_INTERFACE
    USB_CDC_FUNCTIONAL_CALL_MANAGEMENT,                         // Type of functional descriptor
    0x00,                                                       // bmCapabilities of CallManagement
    1,                                                       // Data interface number

    /* Interrupt Endpoint (IN)Descriptor */

    0x07,                           // Size of this descriptor
    USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
    1| USB_EP_DIRECTION_IN,      // EndpointAddress ( EP1 IN INTERRUPT)
    USB_TRANSFER_TYPE_INTERRUPT,    // Attributes type of EP (INTERRUPT)
    0x10,0x00,                      // Max packet size of this EP
    0x02,                           // Interval (in ms)

    /* Interface Descriptor */

    0x09,                               // Size of this descriptor in bytes
    USB_DESCRIPTOR_INTERFACE,           // INTERFACE descriptor type
    1,      // Interface Number
    0x00,                               // Alternate Setting Number
    0x02,                               // Number of endpoints in this interface
    USB_CDC_DATA_INTERFACE_CLASS_CODE,  // Class code
    0x00,                               // Subclass code
    USB_CDC_PROTOCOL_NO_CLASS_SPECIFIC, // Protocol code
    0x00,                               // Interface string index

    /* Bulk Endpoint (OUT)Descriptor */

    0x07,                       // Size of this descriptor
    USB_DESCRIPTOR_ENDPOINT,    // Endpoint Descriptor
    2|USB_EP_DIRECTION_OUT,     // EndpointAddress ( EP2 OUT)
    USB_TRANSFER_TYPE_BULK,     // Attributes type of EP (BULK)
    0x00, 0x02,                 // Max packet size of this EP
    0x00,                       // Interval (in ms)

     /* Bulk Endpoint (IN)Descriptor */

    0x07,                       // Size of this descriptor
    USB_DESCRIPTOR_ENDPOINT,    // Endpoint Descriptor
    2|USB_EP_DIRECTION_IN,      // EndpointAddress ( EP2 IN )
    0x02,                       // Attributes type of EP (BULK)
    0x00, 0x02,                 // Max packet size of this EP
    0x00,                       // Interval (in ms)

};



/******************************************************
 * USB Driver Initialization
 ******************************************************/
const DRV_USBHS_INIT drvUSBInit =
{
    /* Interrupt Source for USB module */
    .interruptSource = INT_SOURCE_USB_1,

    /* Interrupt Source for USB module */
    .interruptSourceUSBDma = INT_SOURCE_USB_1_DMA,

    /* System module initialization */
    .moduleInit = {SYS_MODULE_POWER_RUN_FULL},

    .operationMode = DRV_USBHS_OPMODE_DEVICE,

    .operationSpeed = USB_SPEED_HIGH,

    /* Stop in idle */
    .stopInIdle = false,

    /* Suspend in sleep */
    .suspendInSleep = false,

    /* Identifies peripheral (PLIB-level) ID */
    .usbID = 0,
};

0 个答案:

没有答案