Jump to main content

##

# 1.1 CDC COM Port Dual Example (cdc_com_port_dual)

This application demonstrates the ability of the MPLAB Harmony USB Device Stack to support multiple instances of the same device class. It creates a USB CDC Device that enumerates as two serial ports on the USB Host PC.

## Description

This application is example of a USB CDC Device that enumerates as a dual COM port on the USB host PC. The COM port can be opened using any of the terminal applications. To demonstrate communication between the two COM ports, a character typed in one of the COM port is displayed on the other and vice versa.

## Downloading and building the application

To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using content manager by following these instructions.

Path of the application within the repository is usb_apps_device/apps/cdc_com_port_dual.

Following table gives the details of project configurations, target device used, hardware and its IDE. Open the project using the respective IDE and build it.

Project Name | IDE | Target Device | Hardware / Configuration
--- | --- | --- | ---
sam_9x75_eb.X | MPLABX | SAM9X75 | SAM9X75-DDR3-EB Evaluation Board
sam_9x60_curiosity.X | MPLABX | SAM9X60 | SAM9X60 Curiosity Development Board
sam_d11_xpro.X | MPLABX | ATSAMD11D14A | SAMD11 Xplained Pro board
sam_d21_xpro.X | MPLABX | ATSAMD21J18A | SAMD21 Xplained Pro board
sam_a7g5_ek.X | MPLABX | SAMA7G54 | SAMA7G5 EK Board
sam_e54_xpro.X | MPLABX | ATSAME54P20A | SAME54 Xplained Pro board
sam_e54_xpro_freertos.X | MPLABX | ATSAME54P20A | SAME54 Xplained Pro board
sam_e70_xult.X | MPLABX | ATSAME70Q21B | SAME70 Xplained Ultra board
sam_e70_xult_freertos.X | MPLABX | ATSAME70Q21B | SAME70 Xplained Ultra board
pic32cz_ca70_curiosity_ultra.X | MPLABX | PIC32CZ2051CA70144 | PIC32CZ CA70 Curiosity Ultra Development Board
pic32cz_ca70_curiosity_ultra_freertos.X | MPLABX | PIC32CZ2051CA70144 | PIC32CZ CA70 Curiosity Ultra Development Board
sam_v71_xult.X | MPLABX | ATSAMV71Q21B | SAMV71 Xplained Ultra board
sam_v71_xult_freertos.X | MPLABX | ATSAMV71Q21B | SAMV71 Xplained Ultra board
pic32mz_ef_curiosity_2_0.X | MPLABX | PIC32MZ2048EFM144 | Curiosity PIC32MZ EF 2.0 Development Board
pic32mx470_curiosity.X | MPLABX | PIC32MX470F512H | PIC32MX Curiosity Development Board
pic32mm_usb_curiosity.X | MPLABX | PIC32MM0256GPM064 | PIC32MM USB Curiosity Development Board
pic32cz_ca80_curiosity_ultra.X | MPLABX | PIC32CZ8110CA80208 | PIC32CZ CA80 Curiosity Ultra development board
pic32ck_gc01_curiosity_ultra.X | MPLABX | PIC32CK2051GC01144 | PIC32CK GC Curiosity Ultra Development Board
pic32cx_sg41_curiosity_ultra.X | MPLABX | PIC32CX1025SG41128 | PIC32CX SG41 Curiosity Ultra Evaluation Board
sam_a5d29_curiosity.X | MPLABX | ATSAMA5D29 | SAMA5D29 Curiosity Development Board
sam_9x75_curiosity.X | MPLABX | SAM9X75D2G | SAM9X75-Curiosity Development Board
sam_a7d65_curiosity.X | MPLABX | SAMA7D65 | SAMA7D65 Curiosity Development Board
pic32wm_bz6_curiosity.X | MPLABX | PIC32WM_BZ6204 | PIC32WM BZ6 Curiosity Board
pic32cm_gc_curiosity_pro.X | MPLABX | PIC32CM5112GC00100 | PIC32CM GC Curiosity Pro Board

## Configuring the Hardware

SAMD11 Xplained Pro board

- Use TARGET USB connector on the board to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

SAMD21 Xplained Pro board

- Use TARGET USB connector on the board to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

SAME54 Xplained Pro board

- Use TARGET USB connector on the board to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

SAME70 Xplained Ultra board

- Jumper J203 must be shorted between PB08 and VBUS (positions 2 and 3).
- Use TARGET USB J200 connector on the board to connect the USB Device to the USB Host PC.
- LED3 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

PIC32CZ CA70 Curiosity Ultra board

- Use TARGET USB J203 connector on the board to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

SAMV71 Xplained Ultra board

- Jumper titled "USB VBUS" must be shorted between PC09 and VBUS (positions 2 and 3)
- Use TARGET USB connector on the board to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

PIC32CZ CA80 Curiosity Ultra development board

- Use the USB micro-B connector (J102) to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (The USB device functionality has been activated by the USB Host).

PIC32CK GC Curiosity Ultra Development Board

- Use the Barrel jack connector(J200) to connect an external power supply to the board.
- Use the USB Type-c connector (J202) to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (The USB device functionality has been activated by the USB Host).

PIC32CX SG41 Curiosity Ultra Evaluation Board

- Use the micro-B USB connector TARGET USB( J200) on the board to connect the USB Device to the USB Host PC.
- LED1 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

Curiosity Pro PIC32CM LE00 Development Board

- Use the USB micro-A/B "TARGET USB" connector (D200) to connect the USB Device to the USB Host PC.
- LED0 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

Curiosity PIC32MZ EF 2.0 Development Board

- Use the USB micro-B port J201 to connect the USB Device to the USB Host PC.
- LED1 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

Curiosity PIC32MX470 Development Board

- Use the USB micro-B port J12 to connect the USB Device to the USB Host PC.
- LED1 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

PIC32MM USB Curiosity Development Board

- Use the micro-B USB connector USB2 on the board to connect the USB Device to the USB Host PC.
- LED1 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

SAM9X75-DDR3-EB Evaluation Board

- Powered the board with an external power supply (or use the micro AB connector).

- Setup the SD card (Note: exFAT formatted SD Cards are not supported)

  - Download harmony MPU bootstrap loader from this location.
  - Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
  - Insert the SD card into the SDMMC connector (SDMMC0) on the board.
  - Reset the board by pressing the Push Button RESET, then START.

- Connect the USB Micro-AB Connector on the board to the computer using a micro USB cable.

- LED near VDDCORE inscription on the board indicates USB Device Configuration Set Complete event (The USB device functionality has been activated by the USB Host).

SAMA7G5-EK Evaluation Kit

- Powered the board with an external power supply (J1) or power supply the board by connecting J7 to the computer using a micro USB cable.
- Setup the SD card (Note: exFAT formatted SD Cards are not supported)
  - Download harmony MPU bootstrap loader from this location.
  - Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
  - Insert the SD card into the SD Card Connector (J4) on the board.
  - Reset the board by pressing the Reset Button (nRST)
- Press the "nSTART" button to activate board start-up.
- Connect the USB Micro AB connector (J7) to the computer using an USB cable.
- RGB LED turning to Green indicates USB Device Configuration Set Complete event (The USB device functionality has been activated by the USB Host).

SAM9X60-Curiosity Board

- Setup the SD card (Note: exFAT formatted SD Cards are not supported)
  - Download harmony MPU bootstrap loader from this location.
  - Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
  - Insert the SD card into the SDMMC0 connector J3 on the board.
  - Reset the board by pressing the Push Button RESET.
- Jumper J4 must be shorted.
- Connect the USB Micro-B Connector (J1) on the board to the computer using a micro USB cable.
- LED D1 indicates USB Device Configuration Set Complete event (The USB device functionality has been activated by the USB Host).

SAMA5D29 Curiosity Development Board

- Setup the SD card (Note: exFAT formatted SD Cards are not supported)
  - Download harmony MPU bootstrap loader from this location.
  - Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
  - Insert the SD card into the μSD-CARD connector (J6) on the board.(This connector is present on the bottom face of the board)
  - Reset the board by pressing the Push Button RESET.
- Press the "START" button to activate board start-up.
- Connect the USB Type-C (USB-A) Connector (J1) on the board to the computer using a USB Type-C cable.
- RGB LED (D5) turning to Green indicates USB Device Configuration Set Complete event (The USB device functionality has been activated by the USB Host).

SAM9X75-Curiosity Development Board

- Setup the SD card (Note: exFAT formatted SD Cards are not supported)
  - Download harmony MPU bootstrap loader from this location.
  - Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
  - Insert the SD card into the μSD-CARD connector (J14) on the board.
  - Reset the board by pressing the Push Button RESET.
- Press the "START" button to activate board start-up.
- Connect the USB Micro-B (USB_A) Connector (J2) on the board to the computer using a USB cable.
- RGB LED (LD1) turning to Green indicates USB Device Configuration Set Complete event (The USB device functionality has been activated by the USB Host).

SAMA7D65 Curiosity Development Board

- Setup the SD card (Note: exFAT formatted SD Cards are not supported)
  - Download harmony MPU bootstrap loader from this location.
  - Copy the downloaded boot loader binary (boot.bin) and generated application binary (harmony.bin) into the SD card.
  - Insert the SD card into the SD-CARD connector (J10) on the board.
  - Reset the board by pressing the Push Button RESET.

- Press the "START" button to activate board start-up.
- Connect the USB Type-C Connector (J3) on the board to the computer using a USB cable.
- RGB LED turning to Green indicates USB Device Configuration Set Complete event (The USB device functionality has been activated by the USB Host).

PIC32WM BZ6 Curiosity Board

- Connect a Type-C cable between the DBG USB (J100) port on the board and the PC to power up the board.
- The jumper (J102) must be open for USB device applications.
- Use the TARGET USB (J103) connector on the board to connect the USB Device to the USB Host PC.
- The RGB_LED (D800) turning green indicates the USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

PIC32CM GC Curiosity Pro Board

- Use TARGET USB (J200 )connector on the board to connect the USB Device to the USB Host PC.
- LED1 indicates USB Device Configuration Set Complete event (the USB device functionality has been activated by the USB Host).

## Running the Application

This demonstration creates a USB device that enumerates as two serial (COM) ports on the host. Do the following to run this demonstration:

1. Open the project with appropriate IDE. Compile the project and program the target device.
2. Attach the device to the host. If the host is a personal computer and this is the first time the user has plugged this device into the computer the user may be prompted for a .inf file.
3. Select the "Install from a list or specific location (Advanced)" option. Navigate to the driver path available in the repo - ..\usb_apps_device\apps\cdc_com_port_dual\inf.
   Note: To specifically select the driver, open the Device Manager and expand the Ports (COM & LPT) tab, and right click on Update Driver Software.
   Verify that the enumerated USB device is seen as a virtual USB serial comport in Device Manager.
   Note: The LEDs on the demonstration board will indicate the USB state of the device. Refer to the Configuring the Hardware section for the selected target hardware.
4. Once the device is successfully installed and visible on the Device Manager, open two instances of terminal program, such as HyperTerminal and select the appropriate COM port. Set the serial port settings as follows:
   - Baud : 9600
   - Data : 8 Bits
   - Parity : None
   - Stop : 1 Bit
   - Flow Control : None
   Note: The baud rate can be different from 9600 but the chosen value has to be the same on both the instances of terminal program.
5. To run the demonstration, turn on local echo on both the terminals. If the terminal application is Tera Term, navigate to Setup->Terminal to turn on local echo. Type a character or string in one terminal window. The same character or string shall appear on the second terminal window and vice versa. The following screen shot shows two instances of Tera Term.
   Note: Some terminal programs, such as HyperTerminal, require users to click the disconnect button before removing the device from the computer. Failing to do so may result in having to close and open the program again to reconnect to the device.