USB-C for Engineers, Part 3

Check out Part 1 for an overview of all the USB3.1 specs, and Part 2 for more details on the USB-C connector.

USB Power Delivery is a new specification that enables new functionality for the USB-C connector. In this part, I'll go over the benefits of the specification and details of its implementation.

USB Power Delivery Rev 3.0 is included in the USB 3.1 specification, which you can download from here. The spec has three major purposes.

  1. Enable a much wider range of power options
  2. Provide a side-band channel for standard and vendor defined messaging
  3. Allow the use of Alternate Modes.

Power

Under the USB-C specifiction, without Power Delivery, the maximum power allowed is 15 W. Additionally, the only allowable voltage for Vbus is 5 V. With power delivery, the maximum allowed power increases to 100 W with a maximum voltage of 20 V. A Power Delivery Explicit Contract overrides any other means of determining power levels, as shown in the USB-C spec.

In addition to fixed voltage supplies, there a few other options (section 7.1.3). Variable supplies are "very poorly regulated Sources". Battery supplies expose a direct connection to a device's battery. Programmable supplies expose a well regulated, but adjustable voltage output. Regardless of its other capabilities, any Source must provide a fixed 5V supply.

Side-band Communication

Vendor Defined Messages (VDMs) allow devices to exchange information not defined by the USB specifications. There are structured and unstructured VDMs. Unstructured VDMs provide 14 bits in the header to use for your own purpose, along with up to an additional six objects, each 32 bits long.

Structured VDMs are used to send information about, and agree on, Alternate Modes. For example, under DisplayPort over USB-C, Hot Plug Detect (HPD) is sent as a structured VDM.

Alternate Modes

Alternate modes let you use some of the pins in the USB-C connector for your own purposes. The most common alternate mode is DisplayPort over USB-C. A spec for HDMI over USB-C has also been released. Modes are distinguished with the Standard or Vendor ID (SVID), a unique 16-bit number assigned by the USB-IF (section 6.4.4 of USB-PD spec).

For a full featured cable, you can reconfigure the four SuperSpeed pairs and the Side-Band Use (SBU) pair. If the device has a "captive cable" (cannot be unplugged) or has a "direct connect application" (plug orientation is otherwise assured), three more pins are available. These are the two pins opposite the USB2.0 D+/D- lines and Vconn. You can learn about the connector requirements in section 5.1 of the USB-C spec.

BMC Communication

As of Rev 3.0 of the USB Power Delivery specification, only Biphase Mark Coding (BMC) over USB-C is supported. The physical layer is defined in section 5 of the spec. BMC uses a single wire to communicate between two devices, up to two cable plugs, and up to two debug devices. All communication is half duplex with collision avoidance and 4b5b encoding for DC-balance. The data rate is about 300 kbaud. CRC32 is used to ensure data integrity.

BMC is a version of Manchester coding. There is a transition at the start of every unit interval, and a second transition to indicate a 1. A preamble is used to train the receiver on the exact bit rate. This is followed by a sequence of K-codes that form a Start of Packet (SOP*), which is essentially an address. Then the data is sent, along with a CRC, then finally an End of Packet (EOP).

The SOP* can be one of a few options. SOP addresses the other device, and only Power Delivery Capable Sources or Sinks can respond. SOP' (aka SOP Prime) is used to communicate with the cable plug, such as in the case of an electronically marked cable. SOP'' (double prime) is the other cable plug. SOP'_Debug and SOP''_Debug are undefined, but I'm assuming they will be used for debugging purposes based on the name.

For symbol and bit ordering, everything is least significant first. For an SOP* sequence, K-code 1 is sent first. For each K-code, bit 0 is sent first. When transmitting 16-bit headers or 32-bit data objects, the least significant byte is sent first, and the first bit of the 4b5b nibble transmitted is bit 0.

Section 5.6.2 provides the details of the CRC-32 calculation. I've used this calculator to double check CRCs I've received. Be sure to select Hex and reorder your bytes if needed.

USB-PD Protocol

Everything that happens with USB Power Delivery happens with messages. There are three types of messages.

  1. Control Messages (no payload)
  2. Data Messages (short payload, up to 240 bits)
  3. Extended Messages (bigger payload, up to 2080 bits)

All messages have a 16-bit header. The structure of the header is defined in section 6.2.1. A control message is just this 16-bit header. If bit 15 is set, the message is an extended message. If bits 14..12 are not zero, it is a data message. Otherwise, it is a control message. The other bits of the header determine the current power and data roles of the sender, specification revision used, and a 3-bit rotating message id. The bottom four bits are the message type. Depending on if the message is control, data, or extended, you will need to check a different table.

Most of the control messages (section 6.3) are self explanatory. The most common control message is GoodCRC. It is sent in response to every correctly received message, and has to start within 195 microseconds. Get_Source_Cap is used to request the power source capabilities of the other device. PR_Swap, DR_Swap, and VCONN_Swap are used to swap power, data, and Vconn providing roles, respectively. PS_RDY is used to indicate the power supply is ready.

The data messages (section 6.4) are more complicated. Each data message has at least one 32-bit data object following the header. Capabilities messages are used to share the port's options for power. This must include a 5V fixed supply, which is always the first option, and up to five additional options. Fixed supplies are first, lower to highest voltage. Next are battery supplies by minimum voltage, then variable by minimum voltage, then programmable by maximum voltage, all lowest to highest voltage.

The Request data message is used by a Sink to request a power option from the Source Capabilities list. The Sink then provides some information about how it will use the supply, including if it supports USB communications, USB Suspend, and its maximum and nominal current or power usage.

Vendor Defined Messages were discussed above. BIST is used to enter Built-In Self Test mode. Battery_Status and Get_Country_Info are self-explanatory. Alert is used to indicate a change of status.

Extended Messages (section 6.5) are new to Rev 3 of the spec. They are used to send a lot more information than is possible with just Control and Data messages. This can include hardware and firmware version IDs, manufacturer strings, additional battery capabilities, security information and authentication, and even firmware updates.

Implementation

I've been putting together some code to implement the USB Type-C and USB Power Delivery specs. As of the time of this writing, it is still early days. I started with the Google Chromebook code base and ported it to C++. After 4000 to 5000 lines of code, including a 1200 line state machine with 29 states, I have something that might be a bit messy, but is starting to work.

Last week, I used this code to get 14.8 V out of my Macbook charger, using my FUSB302 breakout board. The code ran on an Arduino and used 70% of the program space. I've been pulling the Arduino-specific functionality out into separate functions. My intention is to create a more standalone library suited for embedded development on a variety of platforms. Any help and suggestions are appreciated. You can find me on Twitter, among other places.

USB-C for Engineers, Part 2

This part will focus on the USB-C connector itself. Check out Part 1 for an overview of all the USB3.1 specs.

The USB Type-C connector is slightly larger than the micro-B connector. It has 24 pins in a radially symmetric pinout, making its orientation reversible. Unlike previous versions of the USB connectors, there is no physical distinction in the plug depending on the functionality supported by the port or plug. USB-C does it all.

The Type-C Spec is part of the USB3.1 Spec, as explained in Part 1. You can download the full USB3.1 specification from usb.org. Follow along with the USB Type-C Specification Release 1.2 in the USB Type-C folder.

Pinout

Taking a quick look at the pinout, the radial symmetry is obvious. The GND pins are always on the outside, and the VBUS pins are always four in from the outside. GND, VBUS, DP, DM, and SSTX/SSRX are all familiar from the USB3.0 spec. The new pins are CC, VCONN, and SBU.

Section 3.2.3 of the USB Type-C Spec (page 55) lists the pinout in more detail, but here's a summary.

Click to enlarge

  • VBUS - provides power to the sink
  • DP/DM - USB2.0 communication, up to High-Speed USB (480 Mbps)
  • SSTX1/2, SSRX1/2 - SuperSpeed transmit, differential pairs, usually twisted pairs in the cable
  • CC - Configuration Channel used to configure the connection and send Power Delivery messages
  • VCONN - Connector power to power active cables and accessories
  • SBU - Sideband Use, basically extra wires used in Alternate Modes

Traps for the Unsuspecting

Click to enlarge

  • The SuperSpeed Tx and Rx lines swap in the cable. So do the SBU wires. That means that SSTX1 on one side is connected to SSRX1 on the other side. Similarly, SBU1 is connected to SBU2 on the other side. You cannot use the mux to fix this. I speak from personal experience.
  • The differential pairs will have a 90 Ohm differential impedance. If you are using an alternate mode, make sure it can handle 90 Ohm +/- 5 Ohm (section 3.7.1)
  • Cables can be electronically marked. This means there is a microcontroller inside one of the plugs, connected to the CC line. It is responsible for reporting the capabilities of the cable. "All USB Full-Featured Type-C cables shall be electronically marked." (section 4.9). Cables that only support USB2.0 do not need to be marked.
  • Be careful powering anything off of VBUS. With USB Power Delivery 2.0, VBUS can go up to 20V. Make sure this doesn't violate voltage ratings in your circuits. Benson Leung has had a few incidents in his famous Amazon reviews. Consider making anything connected to VBUS or CC over-Volt tolerant.
  • Also be careful powering anything from VCONN. You might not have it. Or you might have to provide it. Check in with section 4.4.3 of the spec.

Muxes

To support the reversible pinout, and make things easier for the user, each USB receptacle is required to have "the functional equivalent of a switch in both the host and device to appropriately route the SuperSpeed TX and RX signal pairs to the connected path through the cable." (section 4.5.1.1) The USB spec leaves the implementation up to the designer. For USB2.0, you can just short both possible positions together. For the SuperSpeed pairs, this usually means you need a mux.

Figuring out which way the cable is connected is done through the use of the CC line. This wire is always in the same location on the plug, and it can only be connected to one of two pins in the receptacle. The location opposite CC in the plug is VCONN. This is why the plug has CC and VCONN, but the receptacle has CC1 and CC2.

Using the CC line

The Configuration Channel is used to determine plug orientation, communication device roles, power capabilities, and send Power Delivery messages. Section 4.5 of the spec describes the details about this line and its uses.

To communicate device roles, pull-up (Rp) and pull-down (Rd) resistors are used. In reality, these will likely be current sources and sinks. In general, devices that once had a Type-A port will use the pull-up, and devices that once had a Type-B port will use the pull-down. In the below example, the source looks for a drop in the voltage on either CC1 or CC2. The pin that drops with an Rd pull-down is connected to the CC line. When it sees that, it can then provide power to VCONN and VBUS.

Meanwhile, the sink is monitoring for either CC1 or CC2 going higher in voltage. Then it can activate a pull-up on the other pin to read the value of Ra (pull-down for accessory).

Type-C Current

Even without supporting USB Power Delivery, it is possible to get as much as 15W through the USB connector. VBUS is still limited to 5 Volts, but the current can be as high as 3 Amps. This is done with analog signaling of voltages on the CC line. Essentially, the source changes its value of the Rp pull-up resistor to set the voltage of the CC line within certain ranges. Section 4.6.2.1 describes the details, and section 4.11 has the parameters.

USB2.0 Designs on Type-C

Supporting Type-C from an existing USB2.0 design is straightforward and cheap (except for the connector). Basically you tie the DP pins together, tie the DM pins together, and add one pull-down resistor to each CC pin. This new Type-C device will identify as a data and power sink, use the default USB2.0 power of 500 mA, and work in either orientation of the plug.

Type-C Connector Designs

In the last year alone, many new designs of USB-C connectors have come onto the market. Most of the major players have a good line-up. Here's a few parameters to consider, beyond the usual.

E8124-015-01

  • USB2.0 vs USB3.0 vs USB3.1 - Usually Type-C connectors are rated for a max data rate. USB3.1 supports up to 10 Gbps, USB3.0 would be 5 Gbps, and USB2.0 is 480 Mbps on the DP/DM pins. USB2.0 might not have as much shielding.
  • Right-angle vs Vertical Mount - Fairly self-explanatory. Be sure to have a plan to mechanically support the vertical mount connector.
  • Dual-SMT or Hybrid - Some connectors have two rows of 12 SMT pads each. The hybrid connectors have a outer row of SMT pads and an inner row of thru-hole pins. Beware that usually the thru-hole pins are designed for 0.6-1.0 mm thick PCBs.
  • Current and Voltage Rating - Gone are the days you can rely on USB connectors supporting the current and voltage you expect. If you need more than 3.0 Amps or 5.0 Volts, take a close look at the current and voltage ratings.

More Info

Here's a few links to check out with more detail.

If you want to experiment with Type-C at home, you can buy an Fairchild FUSB302B Power Delivery PHY breakout board from my Tindie store and download the library I put together from GitHub. Just add an Arduino and you're good to go.

Part 3 will take a closer look at USB Power Delivery and the BMC signaling uses on the CC line to set up features like higher voltages on VBUS and Alternate Modes.

USB-C for Engineers, Part 1

USB Type-C (USB-C for short) is a new connector that promises wonderful things, including reversibility, 100W of power, and 20 Gbps data transfer. However, I've noticed a lot of confusion about this new standard and how it relates to the rest of the USB ecosystem. I've been having to learn all about USB-C for my day job, and I'd like to share what I've learned and help other engineers design USB-C into their products.

The first point of confusion with USB-C is with the variety of other specs that came out at the same time, including

  • USB 3.1
  • USB SuperSpeed and SuperSpeedPlus
  • USB Type-C
  • USB Power Delivery 2.0

In this post, I'd like to go over what each of these specs are how they interrelate. In future posts, I'll go into more detail on each one.

USB 3.1

USB 3.1 is a specification published by the USB Implementers Forum. This is the overall standard for the next generation of USB devices and cables. Inside is everything you need to connect to the latest USB hosts and devices. It includes by reference the other specs listed above. If you download the spec from the USB-IF website (here), you will receive the following documents in a zip file.

  • USB 3.1 Rev 1.0
  • USB Type-C Rev 1.2 or later
  • USB Power Delivery Rev 2.0 or later
  • USB Port Controller Rev 1.0 or later
  • various other specifications, agreements, and redline versions of the above

USB SuperSpeedPlus

USB SuperSpeedPlus refers the latest USB data bus. In this case it operates at 10 Gbps/lane. SuperSpeedPlus is used to refer the new features that distinguish it from SuperSpeed (not Plus). USB 3.1 uses "Enchanced SuperSpeed" as a general term to refer features common to both. To make matters more confusing, SuperSpeed is also referred to as USB 3.1 Gen 1. Although this is usually more specifically referring to the physical layer.

The blue Type-A plugs you see add five wires to support the new USB 3.1 bus. There is one differential pair each for receive and transmit, e.g. full duplex, as well as an extra ground.

USB Type-C

USB Type-C is the connector itself. This name follows from the USB 2.0 connectors of Type-A (host side) and various forms of Type-B (device side), including standard B, mini-B, and micro-B. With USB Type-C, there is no distinguishing the power and data role based on the physical connector. Both devices and hosts, sources and sinks, will have the USB-C receptacle. USB-C cables have the same plug on both ends.

The spec includes mechanical, electrical, and some functional details on how to use it. Some of these functions include signaling data and power roles, available power, and whether or not a device is an accessory. The USB Port Controller Specification provides a common interface to ICs that are directly connected to a port. The goal of this spec is to ease the development of software.

USB Power Delivery

USB Power Delivery is where most of the revolutionary features are. "Power Delivery" is a bit of a misnomer, because it does so much more. This is the spec that describes how to swap data roles, swap power roles, move Vbus to different voltages, and use the pins on the USB-C connector for other purposes like DisplayPort. This is what lets you plug your laptop into your monitor to present slides while recharging and running a full USB 2.0 hub, all with one cable.

Technically Type-A and Type-B connectors can use Power Delivery, but I've never seen it implemented. The spec that lets your phone charge at high speed if D+ and D- are tied together is the USB Battery Charging Spec. Power Delivery will likely be a de facto replacement for Battery Charging as more phone go to USB-C, but it is not a direct replacement.

Conclusion

I hope this helps clear things up. The important take away is that USB 3.1 is the overall spec, and each of these new features and connectors are parts of that spec. In part 2, I will go into more details on the Type-C spec.

Charging Safely over USB

Highlighting the security risks of using USB to charge mobile devices, BadUSB – a class of exploits that can lead to malware infections – was recently in the news. With the adoption of USB-C, concerns are only going to increase. New devices, including the new Apple Macbook and Chromebook Pixel, only have USB-C ports, which means the only way to charge your device is through a data port that could open your computer to attack. This vulnerability is especially a concern if you want to use untrusted USB chargers, like you might find in coffee shops and airports.

One way to stop these attacks is to use a device that physically disconnects the USB data lines, while leaving the power and ground lines connected. This approach has a major disadvantage because devices and chargers use the data lines to negotiate power requirements, usually via the USB Battery Charging specification. Without that negotiation, the device can’t determine what capabilities the charger has. Instead of being able to draw 7.5 W or more, the device can only safely draw 0.5 W, which means it could take 15 times longer to charge your phone with this technique.

Fortunately, there is a way to block the USB data signals and still allow the device and charger to negotiate the correct amount of power. The key is that the power negotiation occurs much more slowly than the data flow: 100 Hz instead of 1 MHz. A capacitor across either of the data lines limits the bandwidth so that the charging negotiation can occur, but traditional USB data transfers are blocked. In fact, the USB specification has a maximum allowed capacitance between a data line and ground for this reason.

Because the difference in speed from USB Battery Charging to even USB Low Speed is so large, there is plenty of room for error. Anything over 75 pF is outside the official USB spec for data. The data lines have a typical series resistance of 33 Ohms which means a 33 nF capacitor will create an RC filter with a time constant of approximately 1 μs. A time constant of up to 100 μs is acceptable for passing USB Battery Charging signals, and under 0.1 μs is needed for USB Low Spped, so a variety of capacitance values will work.

To test my ideas, I ran an experiment. I tried three USB cable configurations and, with each configuration, measured how much power my phone drew and whether or not my desktop recognized the device. I tried the original cable as a control. Then I soldered a 22 nF capacitor between D- and GND. Finally, I cut the D- line entirely. The results are below.

  • Intact cable: 9.1 W - Good connection to desktop
  • Capacitor installed: 7.4 W - "USB Device Unrecognized"
  • D- line cut - 2.4 W: "USB Device Unrecognized"

These results are in line with my expectations. The difference between having the intact cable and having the capacitor installed could result from a difference in battery load. I suspect my phone drew more current than it should have in the third test. It seemed to draw 500 mA instead of 100 mA, which is all that is allowed by the spec. Still, with the D- line connected, it drew significantly less power.

I've designed a small device that incorporates these capacitors, along with some test and debug features, into a small board with a plug on one end and a receptacle on the other. It’s called USB Power Armor. I plan to build prototypes and do further testing this coming week. Here's a preview.

Update: The first units of USB Power Armor Type-A are available for sale now. Click here to get yours.