?
Solved

WinCE USB Driver Problem Setting Configuration

Posted on 2006-06-20
6
Medium Priority
?
1,915 Views
Last Modified: 2013-12-27
Project: Driver for USB to Serial device in WinCE
IDE: Platform Builder for Win CE 5.0

So far, we are able to get the device to enumerate properly (Getting device, configuration descriptors etc..) However, we are unable to set the configuration. In the Device descriptor, there are 2 Configurations. Config1 with only 1 bulk out pipe. Config2 one with 1 bulk out, 1 bulk in and 1 interrupt. The problem we are having is setting the configuration to Config2.

Descriptors:
// Device Descriptor
-      pDevice      0x005114dc
      dwCount      0x00000020
-      Descriptor      {...}
      bLength      0x12 '?'
      bDescriptorType      0x01 '?'
      bcdUSB      0x0110
      bDeviceClass      0xff 'ÿ'
      bDeviceSubClass      0x00
      bDeviceProtocol      0x00
      bMaxPacketSize0      0x08 '?'
      idVendor      0x0451
      idProduct      0x3410
      bcdDevice      0x0101
      iManufacturer      0x01 '?'
      iProduct      0x02 '?'
      iSerialNumber      0x03 '?'
      bNumConfigurations      0x02 '?'

//Config1      
-      lpActiveConfig      0x002bc1e0
      dwCount      0x0000001c
-      Descriptor      {...}
      bLength      0x09 '?'
      bDescriptorType      0x02 '?'
      wTotalLength      0x0019
      bNumInterfaces      0x01 '?'
      bConfigurationValue      0x01 '?'
      iConfiguration      0x00
      bmAttributes      0x80 '€'
      MaxPower      0x32 '2'
      lpvExtended      0x00000000
      dwNumInterfaces      0x00000001
+      lpInterfaces      0x005113e0

//Config2
-      pConfigDesc      0x002bc1fc
      dwCount      0x0000001c
-      Descriptor      {...}
      bLength      0x09 '?'
      bDescriptorType      0x02 '?'
      wTotalLength      0x0027
      bNumInterfaces      0x01 '?'
      bConfigurationValue      0x02 '?'
      iConfiguration      0x00
      bmAttributes      0xa0 ' '
      MaxPower      0x32 '2'
      lpvExtended      0x00000000
      dwNumInterfaces      0x00000001
+      lpInterfaces      0x00511440


This is what we used to set the Configuration:

// This SET configuration was completed successfully
USB_DEVICE_REQUEST usbDevReq;
usbDevReq.bmRequestType = USB_REQUEST_HOST_TO_DEVICE | USB_REQUEST_STANDARD | USB_REQUEST_FOR_DEVICE;
usbDevReq.bRequest = USB_REQUEST_SET_CONFIGURATION;
usbDevReq.wValue = (pDevice->lpConfigs + *ConfigIndex)->Descriptor.bConfigurationValue;
usbDevReq.wIndex = 0;
usbDevReq.wLength = 0;
USB_TRANSFER usbTrans = UsbFuncs->lpIssueVendorTransfer(hUsbDevice, NULL,
                                                0, USB_OUT_TRANSFER | USB_SHORT_TRANSFER_OK,
                                                                        &usbDevReq, NULL, NULL);

// This GET configuration was able to verify that the Configuration was Set to Config2      (ConfigValue = 2)
int Configvalue = 0;
      usbDevReq.bmRequestType = 0x80;
      usbDevReq.bRequest = USB_REQUEST_GET_CONFIGURATION;
      usbDevReq.wValue = 0;
      usbDevReq.wIndex = 0;
      usbDevReq.wLength = 1;
      usbTrans = UsbFuncs->lpIssueVendorTransfer(hUsbDevice, NULL,
                                                      0, USB_IN_TRANSFER | USB_SHORT_TRANSFER_OK,
                                                      &usbDevReq, &Configvalue, NULL);
                                                      
// However, Using lpGetDeviceInfo, the lpActiveConfig->Descriptor->bConfigurationValue is still 1(Config1)      
pDevice = UsbFuncs->lpGetDeviceInfo( hUsbDevice );

Another indication that the lpActiveConfig has not been set properly is that we are unable to open the bulk in pipe which is only present in Config2.

Is there something we are missing here?
0
Comment
Question by:ceoconsultancy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 6

Expert Comment

by:umahesh
ID: 17029196
Your lpActiveConfig looks fine.

check with this,

pUsbDevice = pUsbFuncs->lpGetDeviceInfo(hDevice);
        if (pUsbDevice != NULL) {
            pUsbInterfaceToUse = pUsbDevice->lpActiveConfig->lpInterfaces;
        }      

The driver should get the device information (pointer to USB_DEVICE) and use the lpActiveConfig parameter to get a pointer to an array of interfaces (lpInterfaces). The first interface is lpInterfaces[0].

Check with USB descriptors here..
http://www.beyondlogic.org/usbnutshell/usb5.htm#DeviceDescriptors

For more details on USB driver development, check
http://www.beyondlogic.org/usb/usbdevdrvs.htm

0
 

Author Comment

by:ceoconsultancy
ID: 17029767
We have managed to solve the problem. We tried letting the driver set the correct config automatically by setting the registry. From there we found that our firmware does not display the correct number of configurations in the device descriptor.

Thanks for your response, umahesh
0
 
LVL 6

Expert Comment

by:umahesh
ID: 17034596
Thats gr8.
please share your success, how you did that, to the community.

0
 

Author Comment

by:ceoconsultancy
ID: 17056050
Our firmware shows 2 configurations, however the value of lpDeviceInfo->lpConfigs[bIndex].Descriptor.iConfiguration for both the configurations was 0. And we want to select the 2nd configuration.
We had 2 choices:
1. To change the firmware such that the iConfiguration would show the correct value
2. Modify the HcdSelectConfiguration() to select the correct configuration in usbddrv.
We chose the 2nd approach which isnt the correct way but due to our limited resources(we do not have the source for the firmware) was the best approach.

We set it in the .reg file so that the 2nd configuration was to be selected with this entry "iConfiguration"=dword:1
and the modification to HcdSelectConfiguration as follows:
extern "C" BOOL HcdSelectConfiguration(LPCUSB_DEVICE lpDeviceInfo, LPBYTE lpbConfigure)
{
    if (lpbConfigure && lpDeviceInfo) {
        BOOL bReturn = FALSE;
        TCHAR RegPath[MAX_PATH];    
        HKEY hClientRegKey;
        DWORD dwData = 0;
        if (!bReturn && ConvertToClientRegistry(RegPath,MAX_PATH,lpDeviceInfo,NULL,TRUE,TRUE,FALSE,NULL)) {
            DWORD dwType = 0;
            DWORD dwLength = sizeof(DWORD);
            if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,RegPath,0,0,&hClientRegKey) == ERROR_SUCCESS ) { // We found Registry
                if (RegQueryValueEx( hClientRegKey,gcszUsbConfigureEntry, NULL,&dwType, (LPBYTE)&dwData, &dwLength) == ERROR_SUCCESS)
                    bReturn = TRUE;
                RegCloseKey( hClientRegKey );
            }
        }
        if (!bReturn && ConvertToClientRegistry(RegPath,MAX_PATH,lpDeviceInfo,NULL,TRUE,FALSE,FALSE,NULL)) {
            DWORD dwType = 0;
            DWORD dwLength = sizeof(DWORD);
            if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,RegPath,0,0,&hClientRegKey) == ERROR_SUCCESS ) { // We found Registry
                if (RegQueryValueEx( hClientRegKey,gcszUsbConfigureEntry, NULL,&dwType, (LPBYTE)&dwData, &dwLength) == ERROR_SUCCESS)
                    bReturn = TRUE;
                RegCloseKey( hClientRegKey );
            }
        }
        if (!bReturn && ConvertToClientRegistry(RegPath,MAX_PATH,lpDeviceInfo,NULL,FALSE,TRUE,FALSE,NULL)) {
            DWORD dwType = 0;
            DWORD dwLength = sizeof(DWORD);
            if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,RegPath,0,0,&hClientRegKey) == ERROR_SUCCESS ) { // We found Registry
                if (RegQueryValueEx( hClientRegKey,gcszUsbConfigureEntry, NULL,&dwType, (LPBYTE)&dwData, &dwLength) == ERROR_SUCCESS)
                    bReturn = TRUE;
                RegCloseKey( hClientRegKey );
            }
        }
        if (bReturn) { // We have Return. We need search for the index.
            for (BYTE bIndex= 0; lpDeviceInfo->lpConfigs != NULL && bIndex < lpDeviceInfo->Descriptor.bNumConfigurations ; bIndex ++) {
   /***Changes here***/           //  if (lpDeviceInfo->lpConfigs[bIndex].Descriptor.iConfiguration == (BYTE)dwData) {
                     *lpbConfigure = (BYTE)dwData;//bIndex;
                     return TRUE;
               // }
               
            }
        }
       
    }
    return FALSE;
}
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 17583059
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Progress means simplifying, not complicating. Bruno Munari Preface How to detect the name of the internal storage or an SD-card on Windows Mobile device from the desktop application? I got this question, when I was working on a PC applicati…
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question