1. Overview OTG devices use the ID pin in the plug to distinguish A/B Devices. When the ID is grounded, it is called A-Device, acting as a USB Host. A-Device always provides power to the bus. When the ID is left floating, it is called B-Device, acting as a USB Device. The USB Host/USB Device role of the device can be switched through HNP (Host Switching Protocol). When OTG devices are connected, they cannot cross the USB Hub. If they cross the USB Hub, the HNP function will be lost. A-Device/B-Device has no necessary relationship with USB Host/Device. After the host switch is completed, A-Device becomes a USB slave device, but it still provides power to the bus. 2.USB-OTG slot type As Host Only: Provides a standard A socket, a common USB Host with TPL (supported device list) As Device Only: Can only be used as a peripheral B-Device (divided into plug-in integrated and plug-cable separated) OTG Dual: Uses Micro AB socket, and can switch Host/Device at runtime. OTG Dual will first turn on VBus after the plug is inserted, and turn off VBus if no device is connected, and turn on ADP detection, while EAs Host Only will not turn off VBus again 3. Protocols SRP (Session Request Protocol): SRP protocol allows Adevice to save power consumption by cutting off VBUS when the bus is not in use. Any type of Adevice should be able to respond to SRP requests, and any Bdevice should also be able to initiate SRP requests. ADP (Attach Detection Protocol): Provides detection of whether a peer device is inserted and supports any OTG device HNP (Host Negotiation Protocol): The OTG device switches the host/device role through HNP. A-device determines whether it supports the HNP protocol by querying the OTG performance descriptor of B-device to determine whether B-device is a dual-purpose OTG device. If B-device supports the HNP protocol, B-device will return a valid OTG performance descriptor. Then A-device generates a SetFeature command to inform B-device: you can work as a host when the bus is suspended. A-device suspends the bus after sending this SetFeature command. After this session ends, the host returns to A-device. 4. Device Framework OTG Descriptor During device enumeration, A-Device requests the OTG descriptor from B-device through GetDeor. The OTG descriptor should also be returned as part of GetConfiguration(). bmAttributes indicates whether B-Device supports ADP/HNP/SRP. Standard device features, set by SetFeature(). b_hnp_enable Setting this feature indicates that B-Device is allowed to perform HNP. A device must suspend the bus within T(HOST_REQ_SUSP) time. This feature is cleared at the end of the session. a_hnp_support Compatibility feature of early OTG versions. Setting this feature indicates that the A-Device on the other end of B-Device supports HNP. a_alt_hnp_support This flag has been deprecated. 5. Connection mode (Host -> Device) As Host Only and B-device as a peripheral only (with A plug) The host detects the insertion of A plug, stops ADP, and turns on VBus. Because the A plug of B-Device is integrated with the device, B-Device must be connected to A plug at this time. The host detects the peripheral connection and starts enumeration. As Host Only and B-device as a peripheral only (A plug is cable connected) The host detects the insertion of A plug, stops ADP, and turns on VBus. If B-Device is connected by cable before A plug is inserted, the whole connection process is the same as above. Because B-Device may not have a plug inserted at this time, the device connection times out, VBus is closed again, and waits for the next ADP change (cable connection completed), and VBus is turned on again. At this time, normal bus enumeration begins. OTG Device and OTG Device When the host detects that the plug is inserted, it turns on VBus. If no peripheral is detected, it turns off VBus and turns on ADP Probing. When the device detects that the plug is inserted, it turns on SRP. If the cable is not inserted, the SRP times out and the device starts ADP Probing. When the cable is connected, the device detects the ADP change and sends SRP to request the host to turn on VBus. The host responds to SRP and turns on VBus, completing the device connection. 6. Case Analysis: Some customers reported that their prototype OTG mrio AB socket could not recognize the USB flash drive. The reason was finally found to be that the USB ID pin of the customer's prototype was not grounded, and the prototype did not switch to USB HOST mode.