Detecting USB-C Roles
Source, Sink, Host and Device
From low-cost USB fans to smartphones and notebooks, all the way to monitors and docking stations: USB Type-C has established itself as the universal connector standard. As a reversible connector for both power and data, it is suitable for almost anything. From a user's perspective, a very practical connector.
For hardware and embedded developers, however, USB Type-C brings a new challenge. The plug or receptacle alone no longer reveals which role the connected port partner takes on.
This article explains how USB Type-C defines roles and how we can detect the capabilities of the port partner.
The "simple" world before USB Type-C
Before USB Type‑C, the distribution of roles was clear. A USB-A port always supplied power and could additionally act as a USB host (DFP). A USB-B or Micro-B port always consumed power and was a USB device, i.e. a UFP (Upstream Facing Port).
Data role and power role were therefore firmly coupled.
A device developer could define the USB role of a device simply by choosing the USB connector. This came with the restriction, of course, that a USB port could only be used for one role.
What changes with USB Type-C?
For the first time, USB Type-C separates the data role from the power role and no longer ties these roles to the shape of the plug or receptacle.
A smartphone, for example, can:
- operate as a USB device connected to a PC (e.g. as mass storage, webcam, …)
- act as a USB host for a USB flash drive
- draw power (e.g. from a charger, PC, power bank, …)
- supply power (e.g. for a USB-C to 3.5 mm jack digital audio adapter)
USB Type-C defines the following data roles:
| Role | Description | Examples |
|---|---|---|
| UFP (Upstream Facing Port) | Behaves as a USB device. | Mouse, keyboard, USB flash drive |
| DFP (Downstream Facing Port) | Behaves as a USB host. | PC, notebook |
| DRD (Dual Role Data) | Can switch between UFP and DFP. | Smartphone, tablet |
USB Type-C defines the following power roles:
| Role | Description | Examples |
|---|---|---|
| Source | Supplies power. | Power supply, docking station, PC |
| Sink | Draws power. | USB flash drive, digital audio adapter, USB microphone |
| DRP (Dual Role Power) | Can be either source or sink. | Notebook, smartphone, tablet, power bank |
A typical embedded system that is powered via USB and also receives firmware updates over it only requires the UFP and sink roles.
Detecting the port partner
The key to detecting the port partner are the two CC (Configuration Channel) lines.
These lines are used to detect:
- Whether a cable is plugged in
- Which power role the port partner has (source, sink)
- How much current a source port partner can supply
- The orientation of the plug
In addition, extended Type-C functions can be negotiated via the USB Power Delivery (PD) protocol, which runs on the active CC line. However, supporting USB PD is not mandatory and is often not needed, especially for a typical embedded system (UFP, sink).
The initial detection of the power role is done exclusively via pull-up / pull-down resistors. Figure 1 shows where these resistors are applied.
Figure 1 Pull-up/pull-down model of the USB Type-C CC lines. Source: USB Type-C Specification v1.2, Figure 4-5 Pull-Up/Pull-Down CC Model
In a first step, the power roles of the connected devices are detected via the CC lines. For this, the source side provides pull-up resistors (Rp), while the sink side uses pull-down resistors (Rd). By evaluating the CC voltage, each side can detect whether a source or a sink is connected on the other end. This determines the basic role distribution of the connection.
Note
During initial role detection, the following applies at first: source → DFP (host), sink → UFP (device). The initial data roles can therefore be determined indirectly by detecting the power roles. More on how these roles can be swapped later.
In a next step, the sink side measures the pull-up resistor (Rp) applied by the source side and can thus detect how much current the source side can supply.
| Rp | DFP current advertisement |
|---|---|
| 56 kilohms | Default USB power:
|
| 22 kilohms | 1.5 A |
| 10 kilohms | 3 A |
Note
With USB Type-C, the current advertisement takes place via the CC lines. Earlier USB systems often used USB Battery Charging 1.2 (BC1.2) via D+ and D− for this purpose.
Furthermore, the plug orientation can be detected via the active CC line. In many cases, this is not directly relevant. However, if extended pins of the Type-C connector are used (SBU1/2, SSTXp1, SSTXn1, SSRXn2, SSRXp2), detecting the orientation becomes relevant. The inactive CC line becomes VCONN, but this is not covered further in this blog.
In addition to source and sink, USB Type‑C defines further states, which are also detected via the CC lines.
| State | CC1 | CC2 | Description |
|---|---|---|---|
| Unattached | open | open | No connection |
| Device attached | Rd | open | Device attached, orientation detected via CC1 |
| Device attached (flipped) | open | Rd | Device attached, orientation detected via CC2 |
| Debug Accessory | Rd | Rd | Used for development and debugging purposes. For example, D+/D− can be routed to a UART RX/TX interface. |
| Audio Accessory | Ra | Ra | Analog audio adapter. The stereo audio signals are transmitted via D+/D−, microphone and ground via the SBU lines. This mode has been deprecated in newer USB Type-C specifications. |
Note
Since the Analog Audio Adapter Accessory Mode has now been deprecated, current designs typically use USB Audio. If a typical embedded system that has so far operated exclusively as a UFP (device) and sink is to support a digital USB audio adapter, it usually also has to be able to take on the host role (DFP) and thus often becomes a dual-role data device (DRD). Depending on the desired power supply, support for DRP or USB Power Delivery may also be required.
Extensions through USB Power Delivery
As already mentioned, extended Type-C functions can be negotiated via the USB Power Delivery (PD) protocol.
Possible functions:
-
- More power: For example, a device can request a higher voltage (5V, 9V, 15V, 20V)
- Data Role Swap: During operation, one side can request a change of the data role. If the port partner accepts the request, the data roles (UFP ↔ DFP) are swapped.
- Power Role Swap: During operation, one side can request a change of the power role. If the port partner accepts the request, the power roles (source ↔ sink) are swapped.
As already mentioned, support for USB PD is not mandatory for many embedded devices. Depending on the application, however, it may be, and then it can be helpful to know that ST has already integrated this functionality into certain microcontrollers.
See STM32 solutions for USB Type-C and Power Delivery - STMicroelectronics
BC1.2: Why does it still matter today?
Before USB Type‑C was introduced, charging capability was often detected via USB Battery Charging 1.2. This involves evaluating the D+/D− lines, which makes it possible to distinguish between different port types:
-
- Standard Downstream Port (SDP)
- Charging Downstream Port (CDP)
- Dedicated Charging Port (DCP)
In modern Type‑C systems, the current advertisement is primarily done via the CC lines. However, BC1.2 can still be relevant, especially with legacy devices or Type‑A to Type‑C connections.
Implementation in practice
The mechanisms described above for detecting source, sink and plug orientation do not necessarily have to be implemented in firmware in embedded systems. Various USB Type-C ICs are available for these tasks.
These devices typically handle the evaluation of the CC lines and independently detect:
-
- the power role of the port partner (source or sink)
- the active CC line and thus the plug orientation
- the advertised current capability (Default USB, 1.5 A or 3 A)
- special USB Type-C states such as Debug or Audio Accessory
The firmware usually configures the device via I²C and then reads out the detected states. Depending on the IC used, additional functions such as USB Power Delivery, BC1.2 detection or role swaps may also be supported.
This significantly reduces the complexity of a USB Type-C implementation. The firmware does not have to evaluate the CC voltages itself, but merely has to respond to the status information provided by the IC.
Conclusion
What used to be obvious from the shape of the connector must be actively detected with USB Type-C. The CC lines form the basis for detecting source, sink, host and device. Anyone developing USB-C-based products should understand this interaction, even if no support for USB Power Delivery is planned.
Do you have a specific need in the field of USB Type-C? Talk to us: Contact
Pascal Hari
BSc BFH in Mikrotechnik
Embedded Software Engineer
About the Author
Pascal Hari has been working as an Embedded Software Engineer at CSA Engineering AG for 8 years. His focus is on the development of embedded firmware in C++ on STM32 microcontrollers. In the context of various projects, he has been intensively involved with USB Type-C, particularly with the detection of counterparts as well as the integration of corresponding USB Type-C solutions.