CDC Basic Example (cdc_basic)
This application demonstrates the ability of the MPLAB Harmony USB Host Stack CDC Client Driver to enumerate and operate a standard CDC USB Device.
Description
This application uses the USB Host Layer and CDC Client driver to enumerate a standard CDC USB device. The demonstration host application then operates and uses the functionality of the attached CDC Device.
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_host/apps/cdc_basic.
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 |
---|---|---|---|
pic32cm_le00_curiosity_pro.X | MPLABX | PIC32CM5164LE00100 | PIC32CM Lx Curiosity Pro Board |
pic32mz_ef_curiosity_2_0.X | MPLABX | PIC32MZ2048EFM144 | Curiosity PIC32MZ EF 2.0 Development Board |
pic32mz_ef_sk.X | MPLABX | PIC32MZ2048EFH144 | PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit |
pic32mz_ef_sk_freertos.X | MPLABX | PIC32MZ2048EFH144 | PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit |
pic32mx470_curiosity.X | MPLABX | PIC32MX470F512H | PIC32MX Curiosity Development Board |
sam_9x60_ek.X | MPLABX | SAM9X60 | SAM9X60-EK Evaluation Board |
sam_9x60_ek_freertos.X | MPLABX | SAM9X60 | SAM9X60-EK Evaluation Board |
sam_9x60_curiosity.X | MPLABX | SAM9X60 | SAM9X60 Curiosity Development Board |
sam_9x60_curiosity_freertos.X | MPLABX | SAM9X60 | SAM9X60 Curiosity Development Board |
sam_9x75_eb.X | MPLABX | SAM9X75 | SAM9X75-DDR3-EB Evaluation Board |
sam_a5d2_xult.X | MPLABX | ATSAMA5D27C | SAMA5D2 Xplained Ultra Board |
sam_a5d2_xult_freertos.X | MPLABX | ATSAMA5D27C | SAMA5D2 Xplained Ultra Board |
sam_a5d27_som1_ek.X | MPLABX | ATSAMA5D27C | SAMA5D27 SOM1 Kit1 |
sam_a5d27_som1_ek_freertos.X | MPLABX | ATSAMA5D27C | SAMA5D27 SOM1 Kit1 |
sam_a5d27_wlsom1_ek1.X | MPLABX | ATSAMA5D27C | ATSAMA5D27 WLSOM1 EK1 |
sam_a5d27_wlsom1_ek1_freertos.X | MPLABX | ATSAMA5D27C | ATSAMA5D27 WLSOM1 EK1 |
sam_a7g5_ek.X | MPLABX | SAMA7G54 | SAMA7G5 EK Board |
sam_d21_xpro.X | MPLABX | ATSAMD21J18A | SAMD21 Xplained Pro Board |
sam_e54_xpro.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 |
sam_g55_xpro.X | MPLABX | ATSAMG55J19 | SAMG55 Xplained Pro Board |
sam_g55_xpro_freertos.X | MPLABX | ATSAMG55J19 | SAMG55 Xplained Pro Board |
sam_v71_xult_freertos.X | MPLABX | ATSAMV71Q21B | SAMV71 Xplained Ultra board |
pic32cz_ca80_curiosity_ultra.X | MPLABX | PIC32CZ8110CA80208 | PIC32CZ Curiosity Development Board |
pic32ck_gc01_curiosity_ultra.X | MPLABX | PIC32CK2051GC01144 | PIC32CK Curiosity Development Board |
Configuring the Hardware
PIC32CZ CA80 Curiosity Development Board
- Connect the USB device to the connector (J102) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED0 on the board is controlled by the attached USB CDC device.
PIC32CK Curiosity Development Board
- Connect the USB device to the USB Type-C connector (J202). A USB Type-C to Type-A Female adapter is required to connect the USB device to the board. (This cable is not included in the kit).
- LED1 on the board is controlled by the attached USB CDC device.
SAMD21 Xplained Pro Board
- Jumper titled “PA03 SELECT” must be shorted between PA03 and USB_ID (positions 2 and 3)
- Connect the USB device to the “TARGET USB” connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED0 on the board is controlled by the attached USB CDC device.
SAME54 Xplained Pro Board
- Connect the USB device to the “TARGET USB” connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED0 on the board is controlled by the attached USB CDC device.
SAME70 Xplained Ultra Board
- Jumper J203 must be shorted between PB08 and LED2(positions 1 and 2).
- Connect the USB device to the “TARGET USB” connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED3 on the board is controlled by the attached USB CDC device.
SAMV71 Xplained Ultra board
- Jumper titled “USB VBUS” must be shorted between PC09 and LED1 (positions 1 and 2) – Connect the USB device to the “TARGET USB” connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED1 on the board is controlled by the attached USB CDC device.
SAMG55 Xplained Pro Board
- Chip Erase Jumper must be open.
- Connect the USB device to the “TARGET USB” connector using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED0 on the board is controlled by the attached USB CDC device.
SAM9X60-EK Evaluation 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 SDMMC connector J4 on the board.
- Reset the board by pressing the Push Button SW3.
- Jumpers J20, J21, and J13 must be open.
- Jumper J2 and J3 must be shorted.
- Connect the USB Micro-B port J22 on board to the computer using a micro USB cable (to enable debug com port).
- Connect the USB Micro-B Connector (J7) on the board to the computer using a micro USB cable to power up the board.
- Connect the USB device to the Type-A connector (J8).
-
LED D1 on the board is controlled by the attached USB CDC device.
Note: Reset push button on SAM9X60 EK is labelled as SW3
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.
- Connect the USB device to the Type-A connector (J10).
-
LED D1 on the board is controlled by the attached USB CDC device.
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 an USB to serial cable to DBGU0 (to enable debug com port).
- Connect the USB device to the Type-A connector or to the micro AB with a specific dongle (in these case the need to be powered by the external power supply).
-
LED near VDDCORE inscription on the board is controlled by the attached USB CDC device.
SAM A5D2 Xplained Ultra 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 SDMMC1 slot on the board.
- Reset the board by pressing the Push Button BP3.
- Connect the EDBG USB Micro-B port J14 on the board to the computer using a micro USB cable.
- Connect the USB device to the USB Type-A connector “A5-USB-B” (J13).
- RGB LED on the board is controlled by the attached USB CDC device.
Curiosity PIC32MX470 Development Board
- Install a jumper in the J13 header to drive the VBUS line in Host mode.
- Connect the USB device to the USB micro-AB connector J12 using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED1 on the board is controlled by the attached USB CDC device.
Curiosity PIC32MZ EF 2.0 Development Board
- Connect the USB device to the “TARGET USB” connector (J201) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED1 on the board is controlled by the attached USB CDC device.
PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit
- Connect the device to the Type A connector J5, which is located on the top side of the starter kit.
- LED1 on the board is controlled by the attached USB CDC device.
SAMA5D27 SOM1 Kit1
- 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 slot (J12) on the board.
- Reset the board by pressing the Push Button PB1.
- Connect the Debug USB port (J10) on the board to the computer using a micro USB cable.
- Connect the USB device to the USB-B Type-C connector (J19) on the board.
- RGB LED on the board is controlled by the attached USB CDC device.
ATSAMA5D27-WLSOM1 Evaluation Kit
- 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 Card Connector (J9) on the board.
- Reset the board by pressing the Reset Button (SW2)
- Connect the USB-A MicroAB connector (J10) on the board to the computer using a micro USB cable.
- Press the “START_SOM” button to activate board start-up.
- Connect the USB device to the USB Type-A connector (J11) on the board.
- RGB LED on the board is controlled by the attached USB CDC device.
SAMA7G5-EK Evaluation Kit
- Powered the board with an external power supply (J1).
- 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 device to the USB Host Type-A connector (J9) on the board. Alternatively, the USB Device could be connected to the Type-C connector (J8) or micro A/B connector (J7).
- RGB LED on the board is controlled by the attached USB CDC device.
Curiosity Pro PIC32CM LE00 Development Board
- Powered the board by connecting an host to “DEBUG USB” (J300) connector.
- Connect the USB device to the USB Host “TARGET USB” (J200) using a USB Type-A Female to micro-B male cable (This cable is not included in the kit).
- LED0 on the board is controlled by the attached USB CDC device.
Running the Application
This application demonstrates the use of the CDC Host Client Driver to enumerate and operate a CDC USB Device. The application uses the USB Host Layer and CDC Client driver to enumerate a CDC USB device. The demonstration host application then operates and uses the functionality of the attached CDC Device.
- Open MPLAB X IDE the project corresponding to the selected board. Refer to the Building the Application section for details.
- Build the code and program the device.
- Follow the directions for setting up and running the cdc_serial_emulator USB device demonstration. Start a terminal program on the USB Host personal computer and select the Serial-to-USB Dongle as the communication port. Select the baud rate as 9600, no parity, One Stop bit, and no flow control.
- Connect the USB Device connector of the CDC USB Device board to the USB Host Target board. Refer to the Configuring the Hardware section for any converter requirements.
- The LED on the USB host board will turn on as soon as the CDC device is connected. Refer to the Configuring the Hardware section for details on the relevant LED.
- The terminal emulator program will immediately display the text “LED ON.”
- Pressing the key “1” on the terminal will cause the LED on the Host USB board to switch on. Pressing any other key on the terminal message will cause the LED to switch off.
- The above step can be repeated.
- Ensure that the CDC serial emulator device is completely powered off before detaching and reattaching to the embedded CDC host.
In the below setup, the USB Device Board emulates a CDC USB-to-Serial Dongle. The USB Host Board (running the cdc_basic demonstration application) sends the prompt message to the CDC device. The CDC device forwards the prompt to the UART port from where it is transmitted to the PC USB Host through the USB serial interface. A key press on the PC USB Host is transmitted to the CDC device, which in turn presents the key press data to the CDC host. The cdc_basic demonstration then analyzes the key press data and switches on the respective LED.