ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

USB CDC class

USB CDC class

What is USB CDC?

USB CDC (Communications Device Class)is a USB device class defined by the USB-IF that allows a USB device to present itself as a communication device, such as a serial port, modem, network adapter, or telephony device. The most commonly used CDC subclass in embedded systems isCDC-ACM (Abstract Control Model), which emulates a traditional UART COM port. [usb.org], [en.wikipedia.org]


CDC Class Hierarchy

USB Device Class (0x02) │ ├── CDC-ACM (Virtual COM Port) ├── CDC-ECM (Ethernet Control Model) ├── CDC-NCM (Network Control Model) ├── CDC-ATM ├── CDC-PSTN └── CDC-WMC

The most common embedded implementation is:

USB CDC-ACM ↓ Windows → COM3, COM4 ... Linux → /dev/ttyACM0 macOS → /dev/cu.usbmodemxxxx ``

[usb.org], [en.wikipedia.org]


CDC Architecture

CDC separates communication into two interfaces:

1. Communication Interface (CIC)

Used for control and management.

Class = 0x02 (CDC)

Carries:

  • Line coding configuration
  • DTR/RTS status
  • Notification messages
  • Modem status

Typical endpoint:

Interrupt IN

2. Data Interface (DIC)

Used for actual payload transfer.

Class = 0x0A (CDC Data)

Typical endpoints:

Bulk OUT Bulk IN

Endpoint Layout

A typical CDC-ACM device uses:

EP0 Control EP1 IN Interrupt (Notification) EP2 OUT Bulk (Host → Device) EP2 IN Bulk (Device → Host) ``
Host │ ▼ +---------------+ | CDC Driver | +---------------+ │ ┌────────┴─────────┐ ▼ ▼ Interrupt EP Bulk EP (Control) (Data)

Enumeration Example

During enumeration, the host sees:

Device Descriptor Configuration Descriptor Interface 0 CDC Communication Interface Interface 1 CDC Data Interface ``

The host loads the CDC driver and creates a virtual serial port.

Examples:

Windows : COM5 Linux : /dev/ttyACM0 macOS : /dev/cu.usbmodem101

[en.wikipedia.org], [usb.org]


CDC-ACM Control Requests

After enumeration, the host sends class-specific requests.

SET_LINE_CODING

typedef struct { uint32_t baudrate; uint8_t stopbits; uint8_t parity; uint8_t databits; } LINE_CODING;

Example:

115200 8 data bits No parity 1 stop bit

GET_LINE_CODING

Host requests current UART settings.

SET_CONTROL_LINE_STATE

Controls:

DTR RTS

Many MCU applications use DTR as:

Terminal Connected

signal.


SEND_BREAK

Generate UART break condition.

CDC-ACM Data Flow

Application │ UART-style API │ CDC Driver │ USB Bulk IN/OUT │ USB Host ``

Example:

printf("Hello\r\n");

MCU:

CDC_Transmit_FS()

USB:

Bulk IN Endpoint

PC Terminal:

COM Port Window

shows:

Hello

Why CDC Is Popular

No Custom Driver Needed

Most operating systems already provide CDC drivers.

Windows usbser.sys Linux cdc_acm macOS built-in

UART Replacement

Instead of:

USB-UART Bridge ↓ FT232 CP2102 CH340

the MCU directly implements:

USB CDC-ACM ``

saving hardware cost.

Debug Console

Used for:

Firmware logs CLI commands Bootloader communication AT commands

CDC vs HID

FeatureCDCHID
Appears asCOM PortKeyboard/Mouse
Bulk transferYesNo
Driver supportCDC DriverHID Driver
ThroughputHighLower
Virtual UARTYesNo

CDC vs Vendor Specific

FeatureCDCVendor Class
StandardizedYesNo
Host DriverBuilt-inUsually custom
COM PortYesDepends
PortabilityHighLower

Typical Descriptor Classes

Device Class 0x02 CDC Communication 0x02 CDC Data 0x0A

Functional descriptors:

Header Descriptor Call Management Descriptor ACM Descriptor Union Descriptor

These descriptors tell the host that the device implements the CDC-ACM model and that Interface 0 controls Interface 1. [cscott.net], [usb.org]

For embedded firmware engineers,CDC-ACM is essentially "USB behaving like a UART", although the transport underneath is actually USB control, interrupt, and bulk transfers rather than UART signaling.

返回列表