Main Site Documentation

USB Host power cycling


#1

I use the below code to power cycle the USB host on EMX. What is the equivalent on ChipX

static public void ResetUSBPort()
        {
            DispPrint("Power cycling USB Port");
            StorageStatus = 7;

            Register HcRhDescriptorA = new Register(0xFFE0C000 + 0x48);
            Register HcRhStatus = new Register(0xFFE0C000 + 0x50);

            HcRhDescriptorA.ClearBits( 3 << 8 );
            HcRhStatus.SetBits(1);
            Thread.Sleep(300);
            HcRhStatus.SetBits(1 << 16);
            HcRhDescriptorA.SetBits( 3 << 8 );
            Thread.Sleep(500);
        }

#2

By default, our development boards do not have a power switch on USB host. Maybe what you are doing is a reset to the root hub but not reseting power (I am not the USB expert at GHI)

IT would be a good practice to add one of those USB power controller chips in your end application. They are cheap and give you better protection and control.


#3

This is a hack and should not be normally used but you can try it at your own risk.
On ChipworkX, replace 0xFFE0C000 with 0x00500000.


#4

Will try and let you know

It was working…good on EMX


#5

working good but not supported and not direct use of using NETMF.

Ideally, your code will port one device to other with minimal efforts but with using registr access this will make things very difficult.


#6

I agree…but because these boards are alreay in the field I do not have an option to add anything to the ciruit right now.

I have made this change as of now.
Is it the root hub register. Will it work for both the USB Host ports?

        static public void ResetUSBPort()
        {
            DispPrint("Power cycling USB Port");
            StorageStatus = 7;

            UInt32 USBRootHubAddr = 0xFFE0C000;

            if ((SystemModelType)SystemInfo.SystemID.Model == SystemModelType.ChipworkX)
            {
                USBRootHubAddr = 0x00500000;
            }

            Register HcRhDescriptorA = new Register(USBRootHubAddr + 0x48);
            Register HcRhStatus = new Register(USBRootHubAddr + 0x50);

            HcRhDescriptorA.ClearBits(3 << 8);
            HcRhStatus.SetBits(1);
            Thread.Sleep(300);
            HcRhStatus.SetBits(1 << 16);
            HcRhDescriptorA.SetBits(3 << 8);
            Thread.Sleep(500);
        }

#7

Any updats please


#8

I think it will work on both ports. We will look into adding this to next release…


#9

What are you trying to accomplish with the reset?


#10

I have put many of these USB data loggers in the field and it runs for days. But some times the USB flash drive does not respond.
If I unplug the drive and plug it back in it works.

So in order to simulate a unplug I run this code snippet. And it used to work.
I guess it is resetting the root hub, rather than power cycling the drive but if it can bring back the drive from the stuck state it is good enough for me.


#11

I see in some cases this resetting code is triggered and nothing happens. The USB drive does not re-enumerate


#12

Like suggested to you in the past, the only way to guarantee is by controlling the power on the USB connector. This is how the PC or the a USB hub does it


#13

We will add a reset function but still software reset is not guaranteed to make your device work…