Author Topic: WinUsb_QueryPipe returning odd reslts  (Read 10834 times)

Mike K

  • Member
  • ***
  • Posts: 4
WinUsb_QueryPipe returning odd reslts
« on: July 09, 2014, 06:37:41 pm »
Hi, all. I'm new to the forum scenario, so please don't jump all over me if I type something stupid. Thanks.
I've set up a user defined board as per Atmel's SAM3u-EK in that the USB and LEDs all function as per book. I've downloaded and programmed the chip with Atmel's example code for the vendor application, and all appears well on that front. The device seems to enumerate properly, and appears in (WinXP SP3) Device Manager. I managed to find (needle in a haystack!), load, and run the sample P.C. program to test the chip and all appeared fine. On examination, the source code is incomplete...

size_ep = min(ISO_NB_TRANS, udi_vendor_ep_iso_size);     //<undefined function min>- not in any file in the package, can't find any reference on the web.

...and has a chunk of code commented out because (quote)

// Impossible to compare, libusb must include a bug
   // because a padding at 0x00 is added sometime.
   /*
                      //some code.... */<EOF>

At that point, I gave up with libusb and decided to go with my original plan of using winusb. I wrote a program based on an earlier project using a PIC32MX250 and the microchip generic device example(- which appears to work fine <big grin!>).
   A word of thanks to Jan Axelson for USB Complete 4, and thus, the code below- a big help.
Using the code below (sorry, it's a bit archaic. libusb wouldn't let go of my system- every winusb device appeared to need libusb0.sys- in spite of successfully installing on it's own for so long.... So, an operating system reinstall and an IDE downgrade, for now.. to eliminate as many variables as possible. Using Borland's C++ Builder 4 at the moment.)

However, to the point. I'm looking for the endpoint ID and thus, direction:
Code:
........

bResult = WinUsb_QueryInterfaceSettings(MyWinUSBInterfaceHandle, 1, &InterfaceDescriptor);
    if (bResult)    //alt setting=0 returns 2x bulk on microchip laser, nothing on atmel
    {               //alt settings=1 all 7 on atmel, nothing on microchip laser
        for (int index = 0; index < InterfaceDescriptor.bNumEndpoints; index++)
        {
            bResult = WinUsb_QueryPipe(MyWinUSBInterfaceHandle, 1, index, &Pipe);
            if(bResult)                 //altinterface=1 for atmel gives all 7... as "out" endpoints
            {                           //0 for microchip shows 2 bulk.. both as "out" endpoints
                switch (Pipe.PipeType)
                {
                  case UsbdPipeTypeControl:
                       string= "Pipe Type: Control";
                      Memo1->Lines->Add(string);
                      string=' ';   //clear Ansistring.. or it concatenates everything
                      break;
                  case UsbdPipeTypeIsochronous:
                      string="Pipe Type: Isochronous";
                      Memo1->Lines->Add(string);
                      string=' ';
                      break;
                  case UsbdPipeTypeBulk:
                       string="Pipe Type: Bulk";
                      Memo1->Lines->Add(string);
                      string=' ';
                      break;
                  case UsbdPipeTypeInterrupt:
                      string="Pipe Type: Interrupt";
                      Memo1->Lines->Add(string);
                      string=' ';
                }
                string.sprintf("Pipe Index: %d",index);
                Memo1->Lines->Add(string);
                string=' ';
                string.sprintf("Pipe ID: %04X",Pipe.PipeId);
                Memo1->Lines->Add(string);
                string=' ';
                string.sprintf("Pipe Interval:%04X", Pipe.Interval);      //added this bit after inspecting the Pipe structure
                Memo1->Lines->Add(string);
                string=' ';
                Memo1->Lines->Add(string);
            }
            else
            {
                FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,
                    ErrorStatus, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                    (LPTSTR) &lpMsgBuf,0,NULL);
                    Application->MessageBox(lpMsgBuf, "Get Endpoint Descriptor Failed", MB_OK);
           }
    }

//... close and tidy up

this produced the following:
Results from Microchip PIC32MX250:
 Device speed: 1 (Low speed)
 
 Endpoint index: 0
 Pipe type: Bulk. Pipe ID: 0000
 Pipe Interval:0001
 
 Endpoint index: 1
 Pipe type: Bulk. Pipe ID: 0000
 Pipe Interval:0081

Results from Atmel ATSAM3U4C:
Device speed: 3 (High speed)
 
 Endpoint index: 0
 Pipe type: Interrupt. Pipe ID: 0000
 Pipe Interval:0083
 
 Endpoint index: 1
 Pipe type: Interrupt. Pipe ID: 0000
 Pipe Interval:0004
 
 Endpoint index: 2
 Pipe type: Bulk. Pipe ID: 0000
 Pipe Interval:0081
 
 Endpoint index: 3
 Pipe type: Bulk. Pipe ID: 0000
 Pipe Interval:0002
 
 Endpoint index: 4
 Pipe type: Isochronous. Pipe ID: 0000
 Pipe Interval:0085
 
 Endpoint index: 5
 Pipe type: Isochronous. Pipe ID: 0000
 Pipe Interval:0006

It wasn't until I inspected the Pipe structure that I realised the endpoint ID and direction are appearing in the Pipe.Interval member of the Pipe structure, instead of the Pipe.PipeId. Surely both Atmel AND Microchip haven't both got the 'same something' wrong with their descriptors? Am I looking in the right direction?
Any clues, please.
Thanks, in advance,
Mike K.

Mike K

  • Member
  • ***
  • Posts: 4
Re: WinUsb_QueryPipe returning odd reslts
« Reply #1 on: July 10, 2014, 10:00:17 am »
This is kind of embarrassing.... A reinstall of BCB6 and a rerun of exactly the same code returns all the expected results in the expected places. Problem not quite solved ('cos I've not identified the root cause- may well have been a registry issue...), but certainly sorted. Note to self: When you think you've explored all avenues, there's always at least one more! (A variation of Sherlock Holmes' "When you've eliminated everything else, whatever is left, however improbable, must be the case." Thanks, Sir Arthur.)
Also, to those who looked, thanks.
Mike K.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: WinUsb_QueryPipe returning odd reslts
« Reply #2 on: July 10, 2014, 10:00:53 am »
Can't explain that one! Thanks for reporting back.