Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
Adding User Code for USB Interrupts in PSoC Creator - KBA230825
Question: How do I add user code in the PSoC Creator™ USB component in PSoC® 3, PSoC 4200-L, and PSoC 5LP?
Answer: The PSoC Creator USB component has interrupts associated with each of the Endpoints, SOF, Bus Reset, Arbiter, and Link Power Management. A user may need to add custom code or perform a task when these interrupts are triggered. This can be done using the following two methods:
Using the space to add custom code
In this method, you can directly add the custom code in the respective Interrupt handlers between the space provided as shown in Figure 1.
Figure 1: Space to Enter the Custom Code in the Interrupt Handler
The USBFS_episr.c file contains Interrupt handlers for all the interrupts supported by the USBFS component. Figure 1 shows the interrupt handler for Endpoint 1. Regenerating the code does not remove code inserted between the /* `#START EP1_USER_CODE` Place your code here */ and /* `#END` */.
Using interrupt callback function
In this method, use the Entry and Exit callback functions present at the beginning and end of each Interrupt handler.
Define a macro to signal the presence of a callback (in cyapicallbacks.h). This will “uncomment” the function call from the component’s source code.
Write the function declaration (in cyapicallbacks.h). This will make this function visible to all the project files.
Write the function implementation in any user file.
The following examples show how to use the entry callback function in case of an SOF Interrupt.
Define macro USBFS_SOF_ISR_ENTRY_CALLBACK in cyapicallbacks.h. Make sure that the cyapicallback.h is included in the USBFS_episr.c. This will enable the USBFS_SOF_ISR_EntryCallback().
Figure 2: Macro to Uncomment the Callback Function
Declare the function USBFS_SOF_ISR_EntryCallback() in the cyapicallback.h file
Figure 3: Define the Macro and Function in cyapicallback.h