G120 USB Host. Problem when the device reboots


I made a module with a G120. In order to be able to sell it, we made some EMC test to make a CE certification. During the tests we encountered a bug, that I want to share with you.

My application is a custom PCB with two usb port on it. The first one is an USB device used to connect to a pc as an HID keyboard. The second is an USB host in which a keyboard is connected. The objectif of the module is to get the key hited on the keyboard, and after compute transmit the same or an other key to the pc.

The problems we have is, that even if the g120 and the custom board behave well, the keyboard used, reboots on some test. And after a reboot of the keyboard, the connection between the g120 and the keyboard is lost. After some test, I figure that no events were raised when the keyboard reboots.
In order to detect that the g120 and the keyboard lost connection I send some data with the SendSetupTransfer() methods. If the connection is lost, this throw an exception. I try-catch the SendSetupTransfer(), and in the catch i read the last error with USBHostController.GetLastError(), if the error is CompletionCode_NoResponse I reset the USBHostController. This work around works pretty well, after few seconds the keyboard is available again.
But I feel this is more an hack than a solution.

My question is: Is there a simplier way to know that the device reboots, or an automatic way for the usbhostcontroller to handle this ?

If you need more explanations or something is not understandable, I can clarify some points.

Sorry for my bad english, and thanks in advance for your answers.


19 dec -> Modification of some sentences.

@ Tulmandil -

Is there any simple code you can share with us?

@ Tulmandil -

Depends on your code, usually after a device reset, all objects or variables will be 0 or un- initialize

an automatic way for the usbhostcontroller to handle this[/quote]

Make another thread to monitor it,

But both are not good, better if we find out the reason.

I tried with the classes of the premium library, and I was able to reproduct the case. In fact the difficulty is to reset the keyboard. With an ESD on the shield of the USB Host, it makes reboot the 2 keyboads that I tested. To simulate the ESD, I took the piezoelectric of a lighter and I was able to make a piezoelectric spark on the shield. With this, the keyboard resets.
Once the keyboard resets, the actions on the keys will not trig the events keyUp and keyDown.

public class Program
        private static USBH_Keyboard _keyboardHost;
        private static USBC_Keyboard _keyboardClient;

        public static void Main()
            USBHostController.DeviceConnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceConnectedEvent);


        static void USBHostController_DeviceConnectedEvent(GHI.Premium.System.USBH_Device device)
            if (device.TYPE == USBH_DeviceType.Keyboard)
                _keyboardHost = new USBH_Keyboard(device);
                _keyboardHost.Disconnected += new USBH_KeyboardEventHandler(KeyboardHost_Disconnected);

                _keyboardClient = USBClientController.StandardDevices.StartKeyboard();

                while (USBClientController.GetState() != USBClientController.State.Running)

                _keyboardHost.KeyDown += new USBH_KeyboardEventHandler(KeyboardHost_KeyDown);
                _keyboardHost.KeyUp += new USBH_KeyboardEventHandler(KeyboardHost_KeyUp);

        static void KeyboardHost_KeyUp(USBH_Keyboard sender, USBH_KeyboardEventArgs args)

        static void KeyboardHost_KeyDown(USBH_Keyboard sender, USBH_KeyboardEventArgs args)

        static void KeyboardHost_Disconnected(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
            _keyboardHost.Disconnected -= KeyboardHost_Disconnected;
            _keyboardHost.KeyDown -= KeyboardHost_KeyDown;
            _keyboardHost.KeyUp -= KeyboardHost_KeyUp;