3 Replies Latest reply on Apr 27, 2020 7:22 AM by EktaN_26

    Example on how to use the USB control EndPoint EP0


      Hi there,

      I need to be able to get control messages from the EP0.

      I'm using a PSoC 5LP, and I can successfully read and Write USB messages on EP1 and EP2.

      For compatibility reason I need to use the Endpoint 0 to configure the PSOC.



      I have tried the following code, but is not working:


      #define EP0 0


      uint8_t  NewUSBMessage()


        uint8_t retVal;


          retVal =0;

          if (USB_bGetEPState(EP0)!= USB_OUT_BUFFER_EMPTY)




              retVal = 1;





          return retVal;




      Can somebody help me please? send me some example link, etc.




        • 1. Re: Example on how to use the USB control EndPoint EP0



          I'm not a USB configuration expert but here goes:


          I'm assuming NewUSBMessage() is an ISR you want called when EP0 is activated.


          You may need to make the following changes if you already haven't:

          Rename the function NewUSBMessage() to <comp_name>_EP_0_ISR_ExitCallback()

          Add the following lines into file cyapicallbacks.h:

          #define <comp_name>_EP_0_ISR_EXIT_CALLBACK
          void <comp_name>_EP_0_ISR_ExitCallback();

          Note: <comp_name> needs to be substituted with the name of your USBFS component.


          I've used USBFS and EP0 and these are the changes I had to add to get EP0 to be processes with my own code.



          • 2. Re: Example on how to use the USB control EndPoint EP0

            Thank you Len!

            it worked!

            I'm writing the solution in case other people need it.


            In order to read the messages from EP0 I have added


                  #define USB_EP_0_ISR_EXIT_CALLBACK 

                 void USB_EP_0_ISR_ExitCallback();

            in cyapicallback.h


            and I wrote this function:


            void USB_EP_0_ISR_ExitCallback(){

                int length = USB_currentTD.count;   

                     if (length == 8)

                         for (int i = 0; i< length; i++)


                                Message[i] = USB_currentTD.pData[i];





            which seems working.




            Now I'm having the opposite problem  I can't sens (anymore) data to the IN EP1).

            the PSoC 


            // wait until our IN Endpoint is empty

                        while(USB_GetEPState(UNDPOINTIN) != USB_IN_BUFFER_EMPTY);


            Do you know what else could be wrong now?


            Thank you!

            • 3. Re: Example on how to use the USB control EndPoint EP0

              Hello Francesco,


              For the functions like USBFS_ReadOutEP(), the valid value of endpoint number ranges from 1 to 8. You cannot give 0 for the endpoint number parameter in it.


              As already mentioned by Len you can use the USBFS_EP_0_ISR_ExitCallback() and USBFS_EP_0_ISR_EntryCallback() ISR's located in the USBFS_dvrc.c . These ISR's are triggered to handle control transfers directed to endpoint.


              To use these ISRs you need to define  USBFS_EP_0_ISR_ENTRY_CALLBACK (or USBFS_EP_0_ISR_EXIT_CALLBACK) in the cyapicallbacks.h as shown in the image below:


              Then define the USBFS_EP_0_ISR_EntryCallback() function in the main.c to perform the desired function.