How to detect USB data polarity?
There is no danger in swapping D+ with D-. If the connection is done wrong, the interface will just fail. If fails, just swap the wires and try again.
The initial bus state is one of wires pulled up (nominal 1.5k to 3.3v). If the pull-up is on D+ wire (as host sees it), the device is FS (or HS) capable. The host will assert &quot;USB_reset&quot; (drive both lines with 45 Ohms to ground), and start &quot;idle&quot; traffic of SOFs (Start-Of-Frames) with proper signal rate (and amplitude).
If the pull-up is on D- (as host senses it), the host will assume the device is LS, and will invoke proper LS signaling.
If the wires are swapped by mistake, the host will engage into wrong interface (relative to the device side). With wrong wire polarity the device will simply not understand the traffic and will simply fail to respond. You will see &quot;unknown device', or &quot;enumeration fail&quot;, or something like this.