cancel
Showing results for 
Search instead for 
Did you mean: 

USB Low-Full-High Speed Peripherals

Anonymous
Not applicable

Apologies if this has been answered elsewhere but I have been unable to find anything.  I am new to the CyAPI and am trying to write a C++ application to communicate with a CY7C68013A.  However, whenever I attempt a read/write to the control endpoint, I see an error 997.  The functional part of my code is here:

   
    

CCyControlEndPoint *ept = USBDevice->ControlEndPt;

    

ept->Target = TGT_DEVICE;
ept->ReqType = REQ_VENDOR;
ept->Direction = DIR_TO_DEVICE;
ept->ReqCode = 0xA0;
ept->Index = 0x0000;
unsigned char buf[64];
ZeroMemory(buf, 64);
    
ept->Value = 0xE600;
LONG buflen = 1;
buf[0] = 1;
ept->XferData(buf, buflen);

    

ept->Direction = DIR_FROM_DEVICE;
ept->Value = 0xE60A;
buflen = 1;

    

ept->XferData(buf, buflen);

    

cout <<  "Data: " << hex << (int)buf[0] << dec <<  "\nError code: " << ept->LastError << '\n';

   
   

According to the documentation I've seen, this register should output a value of "1"; however, I get "5e".  In fact, for any register I try to access, I get "5e 6f" repeating.  Is there something I am missing about setting up the control endpoint or how I'm using it?

   

Thanks,

   

Scott

0 Likes
3 Replies
Anonymous
Not applicable

Hi,

   

Did you make sure that the device responds properly to the vendor command? Is it handled in your firmware? The 997 error iscaused if the device does not send anything.

   

Regards,

   

-Madhu Sudhan

0 Likes
Anonymous
Not applicable

Using CyUSB.dll   ver 1.2.2.0      12/4/2013

   

Visual Studio C#  2015

   

FX3 processor application- just "pinging" the control endpoint...

   

 

   

The following action is done after successfully finding my enumerated device in USBDeviceList ( ) & performing the SetDevice ( ) API:

   

...

   

                 
            if (gDspDevice != null)
                    {
                    //---------------------------------------------------------------------
                    // CYPRESS DEVICE FOUND...    ASSIGN OBJECT TO CONTROL ENDPOINT
                    //---------------------------------------------------------------------
                    gControlEndpoint = gDspDevice.ControlEndPt;

   

                    gControlEndpoint.TimeOut = 1000000;

   


                    //$$$$$$$$$$$$$$$$$$$$$   testing $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
                    gControlEndpoint.Target = CyConst.TGT_DEVICE;
                    gControlEndpoint.ReqType = CyConst.REQ_VENDOR;           // Special Vendor command
                    gControlEndpoint.ReqCode = 0xA0;                   // VENDOR SPECIFIC
                    gControlEndpoint.Index = 0;                               // Masthead virtual device being accessed
                    gControlEndpoint.Value = 0xe700;                     // Int16 argument (passed as uint16)

   

                    gControlEndpoint.Read(ref ep0Data, ref ep0Len);

   

                    if (gControlEndpoint.LastError == 997)
                           while (true) ;               // always hit this assert

   

                    //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

   

Note the explicit Ep0 request I am making here is identical to the "check" transaction that is implicitly made by the Cypress driver anytime the USBDecviceList ( ) function is invoked.   I can invoke the USBDeviceList( ) API all day long and my firmware responds without any issues (BTW...  I'm returning 1 byte = 0x00 for the Vendor request  bRequest= 0xA0).  

   

Yet the explicit use of the    .Read ( ) API/method on the control endpoint returns with error 997 within 8 msec every time.    My FX3 firmware is seeing the related SETUP packet correctly, but its attempt to return the data with  FX3 API  by CyU3PUsbSendEP0Data ( ) times out... looks like the CyUSB.dll is not properly attempting the read phase... just returning "fail" with 997 error code posted.

   

Why is this?   Have worked with these tools before on other projects, and not encountered this problem.  Seems very improbable it's anything in my FX3 firmware... as it is handling the implicit and identical "check" transaction over and over with no problems at all.  

   

The   .Read ( ) method in .net is the trouble maker.  

   

After the 997 fail, these properties vary relative to what I see after the successful DeviceList ( ) API Ep0 transactions:

   

Success:     gControlEndpoint.Direction = 0x00        .LastError = 0x00000000     .bln = false

   

Fail:   gControlEndpoint.Direction = 0x80        .LastError = 0x00003e5     .bln = true

0 Likes
Anonymous
Not applicable

Follow UP:...  Problem solved.

   

Rules to follow with CyUSB.dll  and the FX3 USB framework:

   

1.  In FX3, don't attempt to handle the SETUP that has  bReqType = Vendor,  bRequest = 0xA0,  wIndex=0,  wValue = 0xE600.    

   

       Your Ep0 Callback just needs to pretend it didn't happen and return a CyFalse.    The FX3's framework ("driver") handles this.

   

2.  In your .NET app, do not explicitly issue a .ReadControl ( ) with this vendor command. (bReqType=Vendor, bRequest = 0xA0,  wIndex = 1).      Let only the  USBDeviceList ( ) API call do this (it will do so for each Cypress USB VID it sees)
 

   

3.  You will still find that  .ReadControl( ) calls set the USB Control object's .LastError to  997.   (0x000003E5).  

   

     They just do that, but the returned data is correct length and is good.

0 Likes