Ground Embedded KO Subscribe

Notes / Communication Protocols

USB basics: talking to a PC over a virtual serial port

Descriptors, endpoints and classes, up to CDC, which makes an MCU appear as a COM port when plugged into USB.

GROUND EMBEDDED · NOTECommunication Protocols 09USB basicsUARTSPII2CCAN

Structure

Plugged inPC requests descriptorsDevice type knownCDC = virtual COMDriver attachedData on endpoints
How the PC recognises a device. The device introduces itself with descriptors and the PC attaches the matching driver.

In USB the host (PC) starts all communication. A device answers only when the host asks.

  • Enumeration: when a device is plugged in, the host reads its descriptors to learn what kind of device it is and what it can do, and attaches a driver.
  • Endpoints: the data windows inside the device. Endpoint 0 is for control, the rest for data (IN is device → host, OUT is host → device)

Transfer types

Type Use
Control Configuration, enumeration
Bulk Large data, no guaranteed bandwidth (storage, CDC)
Interrupt Small and periodic (keyboard, mouse)
Isochronous Real-time, no retransmission (audio)
RoadmapSee where this note sits in Communication Protocols→

CDC: virtual COM port

Implement the CDC class and the device shows up on the PC as a COM port, so you can talk to it straight from a serial terminal. The baud-rate setting has no meaning; data moves at USB speed. In STM32CubeMX, enable USB_DEVICE → CDC and you can send with CDC_Transmit_FS().

Hardware cautions

  • USB needs an accurate 48 MHz clock (HSE, or an HSI48 with CRS on parts that support it).
  • Route D+ and D- as a 90 Ω differential pair, with ESD protection next to the connector
  • Self-powered devices need VBUS detection.
FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →