This project uses the Microchip MPLAB® X IDE or MPLAB Extensions for Microsoft® Visual Studio Code® (VS Code®) and demonstrates the TinyUSB stack with integrated USB device examples running on top of the AVR DU. Within the project, there are different configurations for various USB device class functions. For example, the device_cdc_msc configuration is a USB CDC + MSC composite device. The device_hid_composite configuration is a USB Human Interface Device (HID) composite device. The default configuration without a USB stack involved is used only for adding or removing necessary driver components from MPLAB® X MPLAB® Code Configurator (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. It is thread-safe with all interrupt events deferred then handled in the non-ISR (Interrupt Service Routine) task function. For details, please refer to the following links:
- MPLAB® X IDE v6.25 or newer
- MPLAB® XC8 v3.10 or newer
- AVR GCC v15.1.0 or newer
- MPLAB® Code Configurator (MCC) v5.6.2 plug-in or newer
- TinyUSB Stack v0.19.0
The AVR DU Curiosity Pro Development board has two USB ports: one debugger port for programming the device via the on-board debugger, and one target port directly connected to the AVR DU. This example uses the Debugger port for programming. After the device is programmed, the Debugger port can be disconnected. The target port must be connected to the host for the TinyUSB demonstration.
The Curiosity Nano has an Adjustable Target Regulator that regulates voltage to 3.3V by default. Since the USB peripheral in the AVR64DU32 needs to run at 3.3V, it either needs a 3.3V supply connected on the VUSB pin or a 5.0V supply on VDD with the internal USB Voltage Regulator active. With the Curiosity Nano's default settings, the VBUS pinheader on the board must be connected with the included jumper to supply 3.3V directly to VUSB. This project uses the default settings, requiring the jumper to be connected as shown in the following figure.
This section shows 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 has been manually tested only with the MPLAB® X MCC plug-in. The MCC within the MPLAB extension has not been tested. However, building and debugging processes have been manually tested and function properly.
-
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 demonstrates a class example: one is the MSC + CDC USB device demonstration, 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 J203: DEBUG USB.
-
Open the MPLAB® X project. Select the
device_cdc_mscconfiguration 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 (J112) to the host PC.
-
Check the disk from the PC, TinyUSB MSC and
README.txtwill be displayed. -
Open the Device Manager to 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 J203: 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 (J112) to the host PC.
-
Open the Device Manager to check if HID Keyboard Device and HID-Compliant mouse are present or not.
-
Open an editor from the host PC and push the on-board SW0 button. The
awill be typed in after every button press, while the cursor will move right and down by one step, respectively.
- 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.
- Currently, the VS Code project does not include the AVR GCC configuration, as the latest version (AVR GCC v15.1.0) does not yet provide adequate support for long file paths.












