1 2 Previous Next 29 Replies Latest reply on Apr 1, 2013 6:36 PM by shashank.rebbapragada

    how to write fireware to implement UVC( USB video class) using 68013a?

    xianlong.hu

      Hi :

         

             I want to implemented a UVC( USB video class) board using 68013a, so I can use the USBvideo.sys driver by Windows XP; 

         

            According to UVC hardware spec, several changes needed to be done with the device and configure descriptors,

         

      My  change is done with a reference of the  below code:

         

               /* Standard High Speed Configuration Descriptor */
       const uint8_t CyFxUSBHSConfigDscr[] =
      {
          /* Configuration descriptor */
          0x09,                           /* Descriptor size */
          CY_U3P_USB_CONFIG_DESCR,        /* Configuration descriptor type */
          0xBD,0x00,                      /* Length of this descriptor and all sub descriptors */
          0x02,                           /* Number of interfaces */
          0x01,                           /* Configuration number */
          0x00,                           /* COnfiguration string index */
          0x80,                           /* Config characteristics - bus powered */
          0xFA,                           /* Max power consumption of device (in 2mA unit) : 500mA */

         

          /* Interface association descriptor */
          0x08,                           /* Descriptor size */
          CY_FX_INTF_ASSN_DSCR_TYPE,      /* Interface association descr type */
          0x00,                           /* I/f number of first video control i/f */
          0x02,                           /* Number of video streaming i/f */
          0x0E,                           /* CC_VIDEO : Video i/f class code */
          0x03,                           /* SC_VIDEO_INTERFACE_COLLECTION : subclass code */
          0x00,                           /* Protocol : not used */
          0x00,                           /* String desc index for interface */

         

          /* Standard video control interface descriptor */
          0x09,                           /* Descriptor size */
          CY_U3P_USB_INTRFC_DESCR,        /* Interface descriptor type */
          0x00,                           /* Interface number */
          0x00,                           /* Alternate setting number */
          0x01,                           /* Number of end points */
          0x0E,                           /* CC_VIDEO : Interface class */
          0x01,                           /* CC_VIDEOCONTROL : Interface sub class */
          0x00,                           /* Interface protocol code */
          0x00,                           /* Interface descriptor string index */

         

          /* Class specific VC interface header descriptor */
          0x0D,                           /* Descriptor size */
          0x24,                           /* Class Specific I/f header descriptor type */
          0x01,                           /* Descriptor sub type : VC_HEADER */
          0x00,0x01,                      /* Revision of class spec : 1.0 */
          0x50,0x00,                      /* Total size of class specific descriptors (till output terminal) */
          0x00,0x6C,0xDC,0x02,            /* Clock frequency : 48MHz */
          0x01,                           /* Number of streaming interfaces */
          0x01,                           /* Video streaming I/f 1 belongs to VC i/f */

         

          /* Input (camera) terminal descriptor */
          0x12,                           /* Descriptor size */
          0x24,                           /* Class specific interface desc type */
          0x02,                           /* Input Terminal Descriptor type */
          0x01,                           /* ID of this terminal */
          0x01,0x02,                      /* Camera terminal type */
          0x00,                           /* No association terminal */
          0x00,                           /* String desc index : not used */
          0x00,0x00,                      /* No optical zoom supported */
          0x00,0x00,                      /* No optical zoom supported */
          0x00,0x00,                      /* No optical zoom supported */
          0x03,                           /* Size of controls field for this terminal : 3 bytes */
          0x00,0x00,0x00,                 /* No controls supported */

         

          /* Processing unit descriptor */
          0x0C,                           /* Descriptor size */
          0x24,                           /* Class specific interface desc type */
          0x05,                           /* Processing unit descriptor type */
          0x02,                           /* ID of this terminal */
          0x01,                           /* Source ID : 1 : conencted to input terminal */
          0x00,0x40,                      /* Digital multiplier */
          0x03,                           /* Size of controls field for this terminal : 3 bytes */
          0x00,0x00,0x00,                 /* No controls supported */
          0x00,                           /* String desc index : not used */

         

          /* Extension unit descriptor */
          0x1C,                           /* Descriptor size */
          0x24,                           /* Class specific interface desc type */
          0x06,                           /* Extension unit descriptor type */
          0x03,                           /* ID of this terminal */
          0xFF,0xFF,0xFF,0xFF,            /* 16 byte GUID */
          0xFF,0xFF,0xFF,0xFF,
          0xFF,0xFF,0xFF,0xFF,
          0xFF,0xFF,0xFF,0xFF,
          0x00,                           /* Number of controls in this terminal */
          0x01,                           /* Number of input pins in this terminal */
          0x02,                           /* Source ID : 2 : connected to proc unit */
          0x03,                           /* Size of controls field for this terminal : 3 bytes */
          0x00,0x00,0x00,                 /* No controls supported */
          0x00,                           /* String desc index : not used */

         

          /* Output terminal descriptor */
          0x09,                           /* Descriptor size */
          0x24,                           /* Class specific interface desc type */
          0x03,                           /* Output terminal descriptor type */
          0x04,                           /* ID of this terminal */
          0x01,0x01,                      /* USB Streaming terminal type */
          0x00,                           /* No association terminal */
          0x03,                           /* Source ID : 3 : connected to extn unit */
          0x00,                           /* String desc index : not used */

         

          /* Video control status interrupt endpoint descriptor */
          0x07,                           /* Descriptor size */
          CY_U3P_USB_ENDPNT_DESCR,        /* Endpoint descriptor type */
          CY_FX_EP_CONTROL_STATUS,        /* Endpoint address and description */
          CY_U3P_USB_EP_INTR,             /* Interrupt end point type */
          0x40,0x00,                      /* Max packet size = 64 bytes */
          0x08,                           /* Servicing interval : 8ms */

         

          /* Class specific interrupt endpoint descriptor */
          0x05,                           /* Descriptor size */
          0x25,                           /* Class specific endpoint descriptor type */
          CY_U3P_USB_EP_INTR,             /* End point sub type */
          0x40,0x00,                      /* Max packet size = 64 bytes */

         

          /* Standard video streaming interface descriptor (alternate setting 0) */
          0x09,                           /* Descriptor size */
          CY_U3P_USB_INTRFC_DESCR,        /* Interface descriptor type */
          0x01,                           /* Interface number */
          0x00,                           /* Alternate setting number */
          0x01,                           /* Number of end points : zero bandwidth */
          0x0E,                           /* Interface class : CC_VIDEO */
          0x02,                           /* Interface sub class : CC_VIDEOSTREAMING */
          0x00,                           /* Interface protocol code : undefined */
          0x00,                           /* Interface descriptor string index */

         

          /* Endpoint descriptor for streaming video data */
          0x07,                           /* Descriptor size */
          CY_U3P_USB_ENDPNT_DESCR,        /* Endpoint descriptor type */
          CY_FX_EP_BULK_VIDEO,            /* Endpoint address and description */
          CY_U3P_USB_EP_BULK,             /* Bulk Endpoint */
          0x00, 0x02,                     /* 512 Bytes Maximum Packet Size. */
          0x00,                           /* Servicing interval for data transfers */

         

          /* Class-specific video streaming input header descriptor */
          0x0E,                           /* Descriptor size */
          0x24,                           /* Class-specific VS i/f type */
          0x01,                           /* Descriptotor subtype : input header */
          0x01,                           /* 1 format desciptor follows */
          0x19,0x00,                      /* Total size of class specific VS descr */
          CY_FX_EP_BULK_VIDEO,            /* EP address for BULK video data */
          0x00,                           /* No dynamic format change supported */
          0x04,                           /* Output terminal ID : 4 */
          0x01,                           /* Still image capture method 1 supported */
          0x01,                           /* Hardware trigger supported for still image */
          0x00,                           /* Hardware to initiate still image capture */
          0x01,                           /* Size of controls field : 1 byte */
          0x00,                           /* D2 : Compression quality supported */

         

          /* Class specific VS format descriptor */
          0x0B,                           /* Descriptor size */
          0x24,                           /* Class-specific VS i/f type */
          0x06,                           /* Descriptotor subtype : VS_FORMAT_MJPEG */
          0x01,                           /* Format desciptor index */
          0x01,                           /* 1 Frame desciptor follows */
          0x01,                           /* Uses fixed size samples */
          0x01,                           /* Default frame index is 1 */
          0x00,                           /* Non interlaced stream not reqd. */
          0x00,                           /* Non interlaced stream not reqd. */
          0x00,                           /* Non interlaced stream */
          0x00,                           /* CopyProtect: duplication unrestricted */

         

          /* Class specific VS frame descriptor */
          0x1E,                           /* Descriptor size */
          0x24,                           /* Class-specific VS I/f Type */
          0x07,                           /* Descriptotor subtype : VS_FRAME_MJPEG */
          0x01,                           /* Frame desciptor index */
          0x00,                           /* Still image capture method not supported */
          0xB0,0x00,                      /* Width of the frame : 176 */
          0x90,0x00,                      /* Height of the frame : 144 */
          0x00,0xC0,0x5D,0x00,            /* Min bit rate bits/s */
          0x00,0xC0,0x5D,0x00,            /* Min bit rate bits/s */
          0x00,0x58,0x02,0x00,            /* Maximum video or still frame size in bytes */
          0x2A,0x2C,0x0A,0x00,            /* Default frame interval */
          0x01,                           /* Frame interval type : No of discrete intervals */
          0x2A,0x2C,0x0A,0x00            /* Frame interval 3 */
      };
       

         

      The results shows that the driver is not correctly setup at WIndows, it shows" USB composite device" in the device manager with yellow "!";

         

       

         

      my question is :

         

      how to correctly change the configure descriptors and other codes in the fireware so that Windows can recognize the device as UVC ;  Thanks 

        • 1. Re: how to write fireware to implement UVC( USB video class) using 68013a?
          rama.sai.krishna.vakkantula

           Try with the Descriptors present in the attached text file.

          • 2. Re: how to write fireware to implement UVC( USB video class) using 68013a?
            xianlong.hu

            Thanks, the descriptor works and Windows XP can find the device as an UVC now.

               

            there is others problems:

               

            (1) if  the size of compiled fireware exceeds 13K , when download to 68013 using  cyconsole,  the fireware does not work,  so  I have to comment out code in order to keep the compiled code below 13K, but I don't why this happened?

               

            (2) When using the UVC device by directshow Graphedit or AMCAP.exe, it shows a dialog say" this graph cannot preview";

               

            I  implemented Get_CUR  request by return 26 bytes  referred to the following:

               

            const uint8_t glProbeCtrl[CY_FX_UVC_MAX_PROBE_SETTING] = {
                0x00,0x00,                       /* bmHint : No fixed parameters */
                0x01,                            /* Use 1st Video format index */
                0x01,                            /* Use 1st Video frame index */
                0x2A,0x2C,0x0A,0x00,             /* Desired frame interval in 100ns */
                0x00,0x00,                       /* Key frame rate in key frame/video frame units */
                0x00,0x00,                       /* PFrame rate in PFrame / key frame units */
                0x00,0x00,                       /* Compression quality control */
                0x00,0x00,                       /* Window size for average bit rate */
                0x00,0x00,                       /* Internal video streaming i/f latency in ms */
                0x00,0x90,0x01,0x00,             /* Max video frame size in bytes (100KB) */
                0x00,0x10,0x00,0x00              /* No. of bytes device can rx in single payload */
            };

               

            and Set_CUR request with only return true;

               

            So is there any problem with these implementation of  Get_CUR  and Set_CUR? and Is there other UVC requests that should be implemented ?

               

            Thanks.

            • 3. Re: how to write fireware to implement UVC( USB video class) using 68013a?
              xianlong.hu

              Hi :

                 

                   I use the busbound to capture the usb request, it shows in the below picture.when Get_Cur request , the fireware returns back 26byte information, but when in SET_CUR request, it is an USTS error, my fireware is as below( changed the SC_CLEAR_FEATURE in fw.c) :

                 

                    case SC_CLEAR_FEATURE:                  // *** Clear Feature 0x01
                       if(DR_ClearFeature())
                          switch(SETUPDAT[0])
                          {
                             case 0x21:      ///////SET_CUR request
                                   UVC_SetCur();
                                   break;
                               
                          }

                 


              ////read the 26 byte data into glCommitCtrl

                 

              BOOL UVC_SetCur(void)
              {
                 WORD i;
                 //EP0CS |= bmHSNAK;// Acknowledge handshake phase of device request
                 for (i=0;i<26;i++)
                   glCommitCtrl[i]=EP0BUF[i];
                
                 return(TRUE);
              }

                 

               

                 

              so is the fireware not right or other problems? thanks

              • 4. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                gayathri.vasudevan

                 Hi,

                   

                 

                   

                With respect to the issue related with firmware exceeding 13k size: Please check out the settings made in the Keil compiler (in Project -> Options for Target1 -> BL51 Locate tab/ Target tab).    

                   

                 

                   

                Regards,

                   

                Gayathri

                • 5. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                  gayathri.vasudevan

                   Hi,

                     

                   

                     

                  USTS error (0xC0010000) stands for USB_STATUS_Cancelled error. The USB stack reports this error whenever it completed a transfer because of an AbortPipe request from the client driver. Abort pipe request is given following some error in the transfer. We need to know what is the error that occured. Is it possible for  you to capture the traffic using analyzer like CATC/ Ellysis, which will provide more detailing?

                     

                  For the question: what other UVC requests need to be implemented. UVC spec clearly mentions what are the mandatory requests needed depending on the specific controls. Please refer UVC spec.

                     

                   

                     

                  Regards,

                     

                  Gayathri

                  • 6. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                    xianlong.hu

                    Thanks for your quick response!

                       

                    (1) The SET_CUR request code is 0x01, the same as SC_CLEAR_feature, So I changed the SC_CLEAR_feature code. So is there anything that should be done after moving the data ,such as change the endpiont status , set stall bit ,and etc in order to make the SET_CUR request work?  

                       

                        Does the analyser need some hardware? currently we do not have that things.

                       

                    (2) As to the 13k code size, so Is that what i need to do is change the code size in the settings? 

                    • 7. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                      gayathri.vasudevan

                       Hi,

                         

                       

                         

                      I don't see anything else that needs to be done specially for SET_CUR request. It is to be serivced like any other request, with IN data transfer phase. I believe you are doing the EP0CS |= bmHSNAK; statement common to all the requests. Can you please check and see whether all the 8 bytes of setup data that you have received in EP0BUF is intact? What I read in some of the specs is that the Xact error (which ay cause Abort pipe) might be due to CRC/ PId error etc. I am exactly not sure how we can find out the roor cause, if you do not have better analyzers. 

                         

                      Can you just try replacing the USB cable with a certfied one, since I have heard of such issues due to improper cables as well. Just wanted to be sure.

                         

                      In FX2LP, code size can go upto 16k. since yours is only 13k, I think the Keil settings should fix the issue related to firmware size.

                         

                      I think, you are modifying the vend_ax firmware file to incorporate the SET_CUR and other UVC related requests. If so, can you please try any other vendor command with IN data transfer phase, if that is working? If so, can you please compare the difference between the way that and SET_CUR are implemented?

                         

                      Regards,

                         

                      Gayathri

                      • 8. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                        xianlong.hu

                        Hi:

                           

                        (1) As to the SET_CUR USTS C0000011 error, I put

                           

                                EP0BCH = 0;
                                EP0BCL = 0;
                                while(EP0CS & bmEPBUSY);

                           

                                before moving data , and it is OK;  but I can't explain why?

                           

                               

                           

                         

                           

                        (2) Another question, I put  EP6 as an IN bulk endpoint ,  and after SET_CUR and GET_CUR , an XACT error happened as your said before

                           

                        Device  Length    Phase  Data                                                Description       Cmd.Phase.Ofs(rep)
                        ------  --------  -----  --------------------------------------------------  ----------------  ------------------
                          25           0  IN                                                                                                          9.1.0(6233) 
                          25.6            USTS   c0000011                                                  xact error            6242.1.0       
                          25.6            RESET                                                                                                  6243.1.0       
                          25           0  IN                                                                                                           6244.1.0(45K)  
                          25.6            USTS   c0000011                                                   xact error           51685.1.0       
                          25.6            RESET                                                                                                  51686.1.0   

                           

                        no data is send to PC, it seems that it try many times before the error happened, the EP6 setting is as following:

                           

                            EP6CFG = 0xE0;                //valid,IN,bullk,double   

                           

                            SYNCDELAY; 

                           

                           EP6AUTOINLENH = 02;  // EP6 auto in length: 512 //512:02  64:00
                           SYNCDELAY;
                           EP6AUTOINLENL = 00;        //512:00   64:64
                           SYNCDELAY;

                           

                           EP6FIFOCFG = 0x09;

                           

                           SYNCDELAY;

                           

                         

                           

                         

                           

                        If I put EP6 as ISO IN with the following setting:

                           

                            EP6CFG = 0xD0;                //valid,IN,ISO,double   

                           

                          25           0  ISOC                                                                                                9.1.0(2403) 
                          25.1            USTS   c0000011                                            xact error            2412.1.0       
                          25           0  ISOC                                                                                               2413.1.0(749)

                           

                           would you please give me some advice on this problem? thanks

                        • 10. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                          xianlong.hu

                          Thanks, it is for the ISO transfer , and I tried bulk transfer mode , the XACT error is still there.

                             

                          Is there something that maybe not right is the configuration of EP6 in the fireware?   Hope to get your advice. Thanks.

                          • 11. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                            colin.buckley

                            May I ask if you successfully managed to get UVC implemented?

                               

                             

                               

                            Also interested in developing a UVC camera but was mindful of another Cypress comment that I found a while ago:-

                               

                             

                               

                            "Cypress recommends using a custom driver to implement video products using the EZ-USB FX2LP family ofdevices. Certain
                            requirements of the Video device class specification make it difficult to support the class specification using the FX2LP product. In particular, manual insertion of the payload header into the video data stream is difficult to achieve. Related Categories: USB High-Speed Peripherals"

                               

                             

                               

                            Be interested to know if it is possible.

                            • 12. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                              gayathri.vasudevan

                              Hi Logicland,

                                 

                               

                                 

                              If you use FX2LP to insert the payload headers, it will introduce huge amount of delay, since 8051 comes in the data path. It won't be possible. But you can achieve the same if you think of FPGA on the data path, which will insert the payload headers and pass the data to FX2LP. If you donot want to think of FPGA, you may think of some custom filter driver sitting on top of UVC driver, which will insert the payload headers.

                                 

                               

                                 

                              Regards,

                                 

                              Gayathri

                              • 13. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                                xianlong.hu

                                Hi:

                                   

                                Yes, I had an FPGA in the data chain. but I had been stopped by the Xact error now.

                                   

                                AS to payload header,  I think it is possible to add it by FPGA, but I do not try .

                                • 14. Re: how to write fireware to implement UVC( USB video class) using 68013a?
                                  anand.srinivasan.asokan

                                  XACT_ERROR means there is a transaction error. FX2LP handles the data toggle PID by default so I don't see a reason for transaction error getting triggered. Have you had a chance to hook up a CATC analyzer to see what is happening on the bus?

                                     

                                  Regards,

                                     

                                  Anand

                                  1 2 Previous Next