See this README for usage of the STM32CubeIDE to flash firmware on the device.
The device tests for continuity and internal resistors within various USB Cables and exposes some pins for multimeter testing. The project is a hardware fork of aroerina/LimePulse that I decided to reverse engineer and write the firmware for.
A STM32C031K6T microcontroller is used for testing connection and orientation, powered by a CR2032 battery. Code is given using STM32 HAL libraries and the device can being programmed over SWD.
KiCad and gerber files are provided for the board layout, as well as the library footprints for non-standard parts ordered from JLCPCB/LCSC. See the BOM.
This USB cable tester has the "B" side on the right, and the "A" side on the left. Receptacles are given for the following:
- Type-C (both sides)
- Type-C to A
- Type-C to micro B (2.0)
- Type-C to mini B
The device has some benefits over a simple continuity tester
- displays the as-plugged orientation of the 4 different possibilities of the USB-C to C cable
- detects pullup and pulldown resistors on the CC lines as required by the USB standard for legacy cables
- identifies active cable with E marker (via the pulldown resistor present on VCONN)
- doesn't apply a +V to the Ground line/pin, instead it uses a MCU to test the presence of a connected ground wire
- exposes various pins to test cable and internal resistors manually with a DMM
Note in this test only one of the USB 2.0 Data pair LEDs will light up depending on the cable orientation, showing that the two pairs are not connected inside the cable (the pairs are also not connected on the PCB). The user must flip the orientation to test both data pairs.
Testing the value of the pulldown resistor on an active cable by measuring between B_CC2
and B_GND
(should be between 800-1.2K Ohms).
Layout
- Various B side pins are biased to VBUS through pullup resistors. A side pins are either connected to ground through an LED, thus lighting up if the corresponding wire is continuous, or the pins are connected into the MCU for inputs. These pins that the MCU tests for are as follows:
- Ground (note all four GND pins are tied together)
- VBUS (note all four VBUS pins are tied together)
- CC1 to test for CC line and orientation
- CC2 to test for VCONN line and pull down resistor for active cables, as well as a flipped CC cable
Note: Both A-side and B-side CC1 and CC2 pins are tapped off into corresponding control inputs to the MCU through a resistor, allowing for pulling the control pins high or low to sense the result on the opposite side.
Simplified layout of testing CC1 pin.
Programming is done via the Serial Wire Debug headers (labeled DEBUG
) via an STLink debugger probe.
The device can also be reset by shorting out the nRESET
line to GND
(pins 1 and 2 on the header).
Caution
In the case where the debugger is providing power to the target, make sure the POWER
switch is OFF
.
Note
For the SWD
pins we need pullup or pulldown resistors on SWDIO
and SDCLK
respectively. These are provided internally by the STM32 MCU, but if there is an issue with the debugger try adding an external weak pulllup and pulldown (10K-100K).
Note
VBUS
: Pulled up on B-side to VDD via 2K, pulled down to ground at A-side MCU input sense pin via 10K. Sense pin reads high if VBUS line is continuous through the cable.
GND
: B-side receptacle ground pin connected to board ground, A-side receptacle pin is direct to input sense pin.
All VBUS pins are tied together and tested via a pulldown resistor on the MCU (similarly for GND pins).
Most B-side receptacle pins are pulled up to supply/VDD through resistors with exception for CC pins and Ground. B-side ground is connected to board ground through a DIP switch for isolation from the MCU ground if needed.
A-side receptacle pins are connected to the MCU input for sensing.
A_VBUS
/A_GND
and connected to VBUS_SENSE
/GND_SENSE
inputs to the MCU through DIP switches for isolation from the MCU during DMM testing.
VBUS_SENSE
pin is an input to the MCU with a pull down resistor forming a voltage divider with the 2K VDD pulllup resistor. If the VBUS
line is discontinuous, the pin reads LOW
. If VBUS
is continuous then the pin reads VCC
x10/12, or digital HIGH
.
Indicator LEDs are driven by the MCU outputs GND_LED
and VBUS_LED
.
Here is the type-C receptacle pinout
Source: "USB 2.0 Type-C Plug Pin-Out" https://ww1.microchip.com/downloads/en/appnotes/00001953a.pdf
Possible orientations of USB-C Plug.
Note Ra is for the active pulldown emarker, but don't take this "straight through" configuration literally as there are diodes preventing shorting of the pins.
We can determine that a C-C type cable is connected by pulling both A_CC1 and A_CC2 HIGH and CCx_CTRL pins LOW, then looking for one of the B_CCx pins coming HIGH.
The pulldown (Ra, for "active") is nominally 800-1.2K. Connection is as follows:
We simply configure the A_CC2
and B_CC2
pins as INPUT_PULLUP
s and test if these lines (the VCONN
line) are pulled low (normally it is open), since the pulldown Ra is strong at ~1K.
Note
It is programmed to work for both USB-C plug orientations
Setup
VBUS
is connected toVCC
through a 2K resistor (ignored for the calculations below)- Write
CC1_CTRL
andCC2_CTRL
→LOW
(pullsB_CCx
pin toward ground through 10K R) - Perform analog read of
B_CC1_sense
andB_CC2_SENSE
- If the analog read is above a threshold,
RP_THRESH
, to account for ground noise, then the 56K Rp pullup exists.
Tip
An analog read is required since the internal Rp is weak enough such that it doesn't pull it all the way up to the digital HIGH
threshold
Note this works for both CC configurations
- Set
A_CC1
asINPUT_PULLUP
(~50K internal pullup) - Read
A_CC1
, if pulledLOW
, then it means thatRp
is present (Rd = 5K which is much stronger than the 50K internal pullup)
Isolation switches are provided to isolate the DMM from the MCU as it injects a test current to measure resistance, and also to allow us to measure the resistance of the cable itself (e.g. VBUS to GND).
Note during testing it was found that even with the switches closed the DMM measurements weren't affected.
In the schematic these are modeled as a multi-unit DIP switch:
SW2A
: SeparatesVCC
fromVBUS
SW2B
: SeparatesB_GND
fromGND
SW2C
: SeparatesA_GND
fromA_GND_SENSE
(input to MCU)SW2D
: SeparatesA_VBUS
fromA_VBUS_SENSE
(input to MCU)
Caution
Verify the following:
- USB cable is in the normal CC Orientation of
STD>STD
before proceeding (or note the configuration to choose the correct pad to test) - All DIP switches are in the OFF position
- Power switch is in the OFF position
For the Type-A to C cable the USB standard specifies at 56K pullup resistor between VBUS
and CC
(since the A side is the host, CC pin needs to be pulled up for the B-side/peripheral to recognize A side as host).
We can test the exact value of this resistor by using a DMM between B_VBUS
and B_CC1
testing pads.
Caution
Verify the following:
- USB cable is in the normal CC Orientation of
STD>STD
before proceeding (or note the configuration to choose the correct pad to test) - All DIP switches are in the OFF position
- Power switch is in the OFF position
For the Type-B to C cable the USB standard specifies at 5K6 pulldown resistor between CC
and GND
(since the B side is the peripheral, CC pin needs to be pulled down for the A-side/host to recognize B side as peripheral).
We can test the exact value of this resistor by using a DMM between
A_GND
and A_CC1
- With device ON, make sure the CC orientation is
STD>STD
- Switch isolation switches to OFF
- Switch power OFF
- Place a DMM between
B_CC2
andB_GND
since the Ra will be on the VCONN line.
Shields are connected together and exposed to a through hole testing terminal. For this we can test with a multimeter.
Note the shield and ground are connected inside the receptacle.
The OTG specification allows a USB device normally acting as a peripheral, to now act as a host (example use case: a tablet normally a peripheral, acting as a host can read from removable media on a flash drive)
For the OTG cable the A-plug side ties its ID pin to ground, and the B-plug side leaves it floating.
Since the ID pin is supposed to be tied to its ground pin within the plug, we just connect an LED between VDD → ID pin (=Ground pin) to test the connection.
The ID pin is also brought out on an exposed pad.
Only one set of the D+ and D- pins light up.
- The D1+/- and D2+/- pins are not connected together to allows the user to test both sets of pins independently (but requires the user to flip the USB-C side)
OTG Cable test doesn't work?
- Make sure the test setup is as shown in the examples
If the OTG cable has two male plugs, the data lines are not connected between the male ends, only from female → male 1 and female → male 2. The proper way to test will require the OTG adapter plus a normal USB cable.
With one end plugged in, when I touch the other cable plug to the receptacle the GND (and sometimes Rd) LEDs light up.
- This happens because the tester first checks for VBUS=+Vsupply, and next checks for Ground=0V. If GND=0V it waits 300ms for the plug to "seat" before running through the other tests. But since the receptacle chassis and plug sheath are connected to GND, if you touch the plug to the receptacle it will read GND as 0V and proceed with the other tests. In the USB C<>B case, the Rd test will run if the CC pins aren't connected through on both sides, so it will also test once this contact is made.
The USB-C Type Spec provides the Rp and Rd requirements for legacy cables.
For example, Type-C to 2.0 Type A:
USB Type-C Spec R2.3 - October 2023.pdf
tl;dr any legacy cable assembly that sources power to a Type C connector must use the default 56K pullup (note this is for both 3.1 and 2.0 versions, since the power negotiation didn't come along until later)
Note the A5 CC pin and the B5 VCONN pin are not connected internally. This means it is up to the hardware developer to implement orientation detection on the C-receptacle side.
And here is for the Type-C to 2.0 Micro-B: ^dzdzs5
- USB C<> Micro/Mini B D+/D- LED pair is dependent on C side orientation - make it more user friendly by only lighting up the bottom 2.0 row
- Low power
Icons
- Fedora Hat by Sanjib Biswas from vecteezy - Silhouette PNGs by Vecteezy
- tip by Hothouse Design from Noun Project (CC BY 3.0)
- Warning by Deylotus Creative Design from Noun Project (CC BY 3.0)
Inspired By
- https://github.com/petl/USB-C-cable-tester-C2C-caberQU
- https://github.com/alvarop/usb_c_cable_tester
- https://github.com/aroerina/LimePulse_USB_cable_checker/ - original inspiration for the design and functionality from its professional quality layout