8 Replies Latest reply on Apr 13, 2020 12:05 AM by Peya_4162826

    How to identify plug in usb device or cold reboot.

    Peya_4162826

      I use the sample code "C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\dma_examples\cyfxbulklpmandcache", I use API CyU3PDeviceReset(CyFalse); to reboot device, The function CyFxBulkLpApplnInit() will be invoke after execute "CyU3PDeviceReset(CyFalse)", when plug in USB device, the function CyFxBulkLpApplnInit() will be invoke too, so the function CyFxBulkLpApplnInit() will be invoke two times(the first is plug in usb device, second is to run CyU3PDeviceReset(CyFalse) ), I want to identify which time to execute  CyFxBulkLpApplnInit(). example: when hot plug USB device on host, do action A inside function CyFxBulkLpApplnInit(), after execute CyU3PDeviceReset(CyFalse), then run CyFxBulkLpApplnInit() again, do action B(Not do action A) inside function CyFxBulkLpApplnInit(). how to implement it?

        • 1. Re: How to identify plug in usb device or cold reboot.
          YashwantK_46

          Hello,

           

          I have some question before i can suggest a possible way to implement the application that you require:

          1.) What is the board that you are using ? Is it a custom board? If yes, do you have onboard FLASH or EEPROM on it?

          2.) Also, what are the actions A and B that need to be implemented based on the type of enumeration?

           

          Regards,

          Yashwant

          • 2. Re: How to identify plug in usb device or cold reboot.
            Peya_4162826

            Hi Yashwantk,

            Answer:

            1.  It is a custom board, it has onboard eeprom.

            2.  action A: CyU3PConnectState(CyTrue, CyTrue); Action B: CyU3PConnectState(CyTrue, CyFalse);

            • 3. Re: How to identify plug in usb device or cold reboot.
              YashwantK_46

              Hello,

               

              So, we can use the onboard EEPROM to keep track of the CyU3PDeviceReset() API by writing a particular location of that EEPROM by a fixed value before the reset happens when CyU3PDeviceReset() is used.

               

              Here's what you can do:

              1.) Initialize the I2C block of FX3 and add the I2C read and I2C write functions. You can use cyfxusbi2cregmode example available in the SDK as an example and modify the code.

              The path of cyfxusbi2cregmode is: C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\serialif_examples\cyfxusbi2cregmode

              2.) In the function where you call CyU3PDeviceReset() API, before calling it, use the CyU3PI2cTransmitBytes to write to a location of the EEPROM with a fixed value (say 0x55). This will make the device reset and CyFxBulkLpApplnInit() to run.

              3.) In CyFxBulkLpApplnInit(), you will have to firstly read the EEPROM location and store that data in a buffer using CyU3PI2cReceiveBytes() API and then clear the value in that location.

              4.) In the CyFxBulkLpApplnInit(), add a if condition where you compare the value of the buffer with 0x55 (or whatever is stored in that location) and if that is true, just set a flag in the loop or call the function that will call the USB 2.0 connection.

              5.) If you set a flag in the if condition, then check for that flag in the for (;;) loop and if that is true, call the function to disable the USB 3.0 connection to make the device enumerate as a 2.0 device.

              6.) If the flag is not set, you can just continue the device operation in SS mode.

               

              Hope this helps. Please implement the above steps and see if you can get the desired outcome.


              Regards,

              Yashwant

              • 4. Re: How to identify plug in usb device or cold reboot.
                Peya_4162826

                Hi ,

                it doesn't make sense, the USB device can be pull out from host at anytime. example: pull out FX3 while  execute "CyU3PDeviceReset()" and save the flag into EPROM , then plug in FX3.

                • 5. Re: How to identify plug in usb device or cold reboot.
                  YashwantK_46

                  Hello,

                   

                  Can you please say which steps makes this approach not feasible?

                   

                  If you pull out the device from the host at anytime, Option A will be carried out since the EEPROM location is not filled with the expected value.

                  If the device is reset using CyU3PDeviceReset(), before the device get reset, the EEPROM location will be written with the value, and since the value is checked in the CyFxBulkLpApplnInit(), Option B will be carried out.

                   

                  Which of this doesn't make sense to you?

                   

                  Regards,

                  Yashwant

                  • 6. Re: How to identify plug in usb device or cold reboot.
                    Peya_4162826

                    example:

                    Flag=1 mean cold reset. flag=0 mean plug in device.

                    before execute CyU3PDeviceReset(), Save the flag =1. Then call "CyU3PDeviceReset()", The device to be ready reboot, but not actually reboot, at this time, remove FX3 from host,so the function CyFxBulkLpApplnInit is NOT called , wait 10 minutes, then plug in FX3 again, The flag==1 when execute "CyFxBulkLpApplnInit(), ", it is wrong.

                    ARM core has a register can identify power on by AC or SW, it is better if you have a API relevant this register. Thanks!

                    • 7. Re: How to identify plug in usb device or cold reboot.
                      YashwantK_46

                      Hello,

                       

                      Apologies for the delayed response.

                       

                      Please find the attached firmware which implements vendor commands to read a register which can be used for your application.

                       

                      You can program the firmware to EEPROM or FLASH and perform the steps mentioned. Please connect the UART debug cable as well since the debug prints print the register values over UART interface.

                       

                      Please do the following in the control center over control endpoint :

                      1.) Send 0xC0 to read the initial state of the register. Bit 0 of the register will be set when the device is plugged into a host PC.

                      2.) Send 0xC2 over control center which will clear Bit 0 of the register. This will clear the bit 0 and it will stay cleared until there's a new plug/unplug of the device.

                      3.) Send the vendor command 0xC1 which calls the CyU3PDeviceReset(CyFalse); API and resets the device and since the bootmode is I2C boot, the device will re-enumerate.

                      4.) Again send vendor command 0xC0 and you will see the Bit 0 cleared.

                      5.) Unplug the device and plug it again.

                      6.) Send vendor command 0xC0 to read the register again. You should see that Bit 0 is set.


                      Please do the following and confirm if you see the same behaviour.


                      Regards,
                      Yashwant

                      • 8. Re: How to identify plug in usb device or cold reboot.
                        Peya_4162826

                        Hi ,

                        Thank you!, This issue can be closed.