This project, which uses the Microchip Microchip MPLAB® X or MPLAB Extensions for VS Code, demonstrates the TinyUSB stack with integrated USB device examples running on top of the PIC32CM GC. Within the project, there are different configurations for different USB device class functions respectively. For example, the device_cdc_msc configuration is a USB CDC+MSC composite device example. The device_hid_composite configuration is a USB HID composite device example. The pic32cm_gc_cpro configuration without a USB stack involved is only for adding or removing necessary driver components from MPLAB® X MCC, which can be used by other configurations inside this same project.
TinyUSB is an open-source cross-platform USB Host/Device stack for embedded systems, designed to be memory-safe with no dynamic allocation; and thread-safe with all interrupt events deferred then handled in the non-ISR (Interrupt Service Routine) task function. Refer to the following links for more details:
- MPLAB® X IDE 6.25 or newer
- MPLAB® XC32 4.60 or newer compiler
- MPLAB® Code Configurator (MCC) 5.6.2 plug-in or newer
- TinyUSB Stack 0.18.0
The PIC32CM GC Curiosity Pro Development board has two USB ports. One debugger port for programming the device through the on-board debugger and one target port directly connected to the PIC32CM GC. This example uses the Debugger port for programming. After the device is programmed, the Debugger port can be disconnected and the target port must be connected to the host for TinyUSB demonstration.
This section explains how to set up the example in MPLAB using the MCC. The following figure presents an overview of the complete MCC setup.
Note: The MCC code generation is only manually tested with the MPLAB® X MCC plug-in. The MCC within the MPLAB Extension is not tested, while building and debugging are manually tested and are working well.
-
Download the zip package or clone the project to get the source code
This project has two configurations with a USB function, where each configuration will demonstrate a class example: one is the MSC+CDC USB device demonstration, and the other is the HID composite USB device demonstration.
The following steps will demonstrate how to use MPLAB® X to program and run the board.Note: This project can be opened, programmed, and debugged from the VS Code with MPLAB Extensions. The VS Code project is under the .X folder: pic32cm_gc_cpro_tinyusb.X. For more details on how to use the MPLAB Extensions with VS Code, refer to the MPLAB® Tools for VS Code®.
-
Connect the board to the PC through the J600: DEBUG USB.
-
Open the MPLAB® X project and select the
device_cdc_mscconfiguration in project. -
Build the project and program the board, by clicking the icon.
Programming/Verify completewill appear after correctly programming. -
Connect the board's USB target port, J200, to the host PC.
-
Check the disk from the PC,
TinyUSB MSCandREADME.txtwill be displayed. -
Open the
Device Managerto check the COM port device. -
Open a serial terminal to test the CDC port, any typed characters will be echoed back to the terminal, as shown in the following figure.
-
Connect the board to the PC through the J600: DEBUG USB.
-
Open the MPLAB® X project and select the
device_hid_compositeconfiguration in the project. -
Build the project and program the board, by clicking the icon.
Programming/Verify completewill appear after correctly programming. -
Connect the board's USB target port, J200, to the host PC.
-
Open the
Device Managerto check ifHID Keyboard DeviceandHID-Compliant mouseare present or not. -
Open an editor from the host PC and push the SW0 button on board. The
awill be typed in after every button press, meanwhile the cursor will move right and down by one step respectively.
- The VS Code project can only work for XC32 v5.0 or newer. The older version of XC32 cannot find the correct
elffiles for hex conversions. - The current release (v1.0.0) is well tested with a bus powered device. The self-powered mechanism will be covered in a future release.











