PSoC5LP: Possible to detect USB connect/disconnect through only software (no VBUS)?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
KyTr_1955226
Level 6
Level 6
250 sign-ins 10 likes given 50 solutions authored

Hello,

I have a question about the USBFS component and API as it pertains to managing connection/disconnection from a USB host.

The system I am working with is self-powered.  VBUS is a little weird in this design.  The PSoC does not have any access to VBUS directly.  the signal I am using in place of VBUS Detect is a signal that is high when the PSoC is selected by a USB 2.0 mux.  When the other USB device on the mux is finished, it switches the mux over to the PSoC5LP and alerts the PSoC that it has been selected.  So basically, VBUS Detect is high when it's *possible* for a host to be connected, but most of the time there is no actual host on the other end (the connection is mostly just for bootloading).  See below:

pastedImage_1.png

One thought I had was to use USBFS_GetConfigurationChanged() to detect the config change when a host connects, but what I'm finding is that even without a host connected, it will still pass through if(USBFS_GetConfigurationChanged() != 0) immediately, without regard for if a host is actually connected.

Is there a way through software to detect a connection event without having VBUS available as a trigger?

Thanks for the help!

0 Likes
1 Solution
Aashita_R
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi KyTr_1955226​,

I have tried to produce the issue on my end. I have modified a USB code example and tried to glow the LED on the board as an indication for the configured USB. I have used CY8CKIT-059 to run the project. In this project, the API GetConfiguration() is used in the main.c as shown below-

pastedImage_0.png

This function GetConfiguration() gets the current configuration of the USB device. It returns the currently assigned configuration. If the device is not configured, it returns 0. Initially, when the USB device is left unconnected, then LED does not glow. As soon as the device is connected to the host, the LED glows. Then the device needs to be reset for checking the return value again, else it keeps glowing.

NOTE: When the device is connected to the host, first wait for enumeration and then GetConfiguration() API is used to check.

Another method to check the configuration is with the help of SOF(Start of frames) packet. Enable the SOF Interrupt in the advanced tab of USB Configurator. The host keeps sending SOF packets to the device, when the device is enumerated properly. You can also monitor these SOF packets to check if your USB device is configured or not.

Please try the above methods on your end once and let us know in case of further queries.

Best Regards,

Aashita

View solution in original post

2 Replies
Aashita_R
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi KyTr_1955226​,

I have tried to produce the issue on my end. I have modified a USB code example and tried to glow the LED on the board as an indication for the configured USB. I have used CY8CKIT-059 to run the project. In this project, the API GetConfiguration() is used in the main.c as shown below-

pastedImage_0.png

This function GetConfiguration() gets the current configuration of the USB device. It returns the currently assigned configuration. If the device is not configured, it returns 0. Initially, when the USB device is left unconnected, then LED does not glow. As soon as the device is connected to the host, the LED glows. Then the device needs to be reset for checking the return value again, else it keeps glowing.

NOTE: When the device is connected to the host, first wait for enumeration and then GetConfiguration() API is used to check.

Another method to check the configuration is with the help of SOF(Start of frames) packet. Enable the SOF Interrupt in the advanced tab of USB Configurator. The host keeps sending SOF packets to the device, when the device is enumerated properly. You can also monitor these SOF packets to check if your USB device is configured or not.

Please try the above methods on your end once and let us know in case of further queries.

Best Regards,

Aashita

Hi Aashita,

Thanks for the input.  So from what it sounds like, I can detect a connect event with IsConfigurationChanged()/GetConfiguration(), but I would not be able to catch a disconnect from the host.  Right now my code looks like below, and is called when the Mux SELECT line (PSoC VBUS_DETECT) goes high and enumeration has not yet occurred:

static bool USB_Init (void){

    uint8_t timeout = 0;

    bool connected = true;

    if (USBFS_IsConfigurationChanged()){

      

        while (++timeout < 20){

          

            if (USBFS_bGetConfiguration()){

                connected = true;

                break;

            } else {

                connected = false;

                break;

            }

          

        }

      

    }

    if (connected){

        USBFS_LoadInEP(USBFS_EP1,USB_HIDInBuffer,64);

        USBFS_EnableOutEP(USBFS_EP2);

    }

  

    return connected;

}

This returns true as soon as the SELECT line for the 2.0 Mux (a TI TS3USB221A) goes high, so I wonder if the mux itself is "tricking" the USBFS component into thinking there is a host on the other end and hence IsConfigurationChanged()/GetConfiguration() pass their checks.

I hadn't considered using the SOF interrupt.

I will look into maybe using the SOF interrupt combined with a timer to detect when a host is present/not present on the other end of the line.

For now, enumeration does occur with the host when plugged/unplugged/re-plugged, so I should be OK as-is for now.

Appreciate the help!

0 Likes