MCUXpresso Config Tools provide a USB configuration component that allows configuring USB settings in a graphical environment and generates a configuration and sample C code according to the configuration.
This tutorial shows how to create the configuration and sample code for the mouse and keyboard HID USB class for the RT1050 EVKB board and build it using the MCUXpresso IDE.
Note: The i.MX RT1050 EVKB board is used; however, the instructions are applicable in a similar way on other NXP EVK boards.
Prerequisites
Steps
1. Launch MCUXpresso IDE and click Create a new C/C++ project…:
2. Select the EVKBIMXRT1050 board in the MIMXRT1050 processor folder, click Next:
3. Specify the project name (for example, Test_USB). In the Middleware section, select USB > USB Device. Then click Finish:
5. In the Peripherals view of the Peripherals tool, click the USB1 peripheral checkbox, ignore the error for now:
6. When the Add configuration component instance dialog appears, select the USB configuration component, click OK:
6. The USB configuration component instance is added. As it requires the component for MPU initialization, click the + icon to add it.
Confirm the selection of the MPU utility component in the dialog that appeared.
Keep the MPU component in the default setting and close its editor tab.
The keyboard interfaces are now added to the Supported interfaces list and pre-configured.
8. To add the mouse interface, click the + in the Supported interfaces section.
Select the newly added item and change the Class item to HID.
10. The Problems view shows an error as the clock function is inactive by default.
To enable it, right-click on the error and select “Enable USBPHY1 PLL clock”:Note: Optionally, it's possible to click the Show the problem… and adjust it in the Clocks tool.
11. Click the Update Code button in the main toolbar, a pop-up appears:
Build the application using the Build Command in the Quickstart Panel.
Note: The EVKB-IMXRT1050 board provides multiple USB connectors. For flashing the application, it is it’s necessary to use the debug connection. Also ensure that the board power is configured properly. There are several other configuration jumpers on the board. So in case the application cannot be flashed or debugged, follow the user guide of the board.
14. To launch the application in the debugger, click the Debug text located in the bottom-left corner of the IDE.
Once the connection is successful, launch the application by clicking the Run button.
If the application connects successfully, connect an additional USB cable from the application USB connector to your PC.
The generated source code files contain a sample code that moves a mouse cursor in a loop and sends Home and End keys. After the cable is connected and the application runs, the movement of the mouse cursor and the text cursor moves left to right are visible.