Showing results for 
Search instead for 
Did you mean: 

Knowledge Base Articles

Adding User Code for USB Interrupts in PSoC Creator - KBA230825


Adding User Code for USB Interrupts in PSoC Creator - KBA230825

Version: **

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:

  1. 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` */.

  1. 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



Figure 4: Define the Function



Version history
Revision #:
1 of 1
Last update:
‎Jul 19, 2021 10:04 PM
Updated by: