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.
Thank you Len!
I'm writing the solution in case other people need it.
In order to read the messages from EP0 I have added
and I wrote this function:
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).
// wait until our IN Endpoint is empty
while(USB_GetEPState(UNDPOINTIN) != USB_IN_BUFFER_EMPTY);
Do you know what else could be wrong now?
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.