This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377D: Resetting the port of USB hub can't be completed.

Part Number: TMS320F28377D
Other Parts Discussed in Thread: C2000WARE

We designed TMS320F28377D with a USB hub in a new project. Resetting the port of USB hub can't be completed when

we brought up it. The code stopped at the point of reseting port of USB as the figures shown in below.

  • I am notifying the engineers who worked on the code.
  • Would you help checking the issue mentioned above, please?

  • do you know the answer to this?
  • Hi,

    Has this been resolved? We have not had the chance yet to look into this. But we should have some time in the near term. We are doing some development and testing of the USBlibary for a new device and will look into this.

    We will address this issue next week and reply back if you have not already resolved this.


    sal

  • Hi Sal,

    We have not resolved this. Please help addressing this issue.

    Sincerely,

    LB Shi
  • Hi Lianbing,

    A few questions:

    1. Are you using the latest C2000Ware Version?
    2. What is the USB End Application and are you using a custom board or a TI Evaluation Board?
    3. What is the sequence and when is the port reset happening?

    Regards
    Harshmeet
  • Hi Harshmeet,

    Here is our comments for the questions you raised.

    1. The C2000Ware version we used is V1.00.06.00.

    2. The USB End Application is USB mouse on the board we designed.

    3. For the sequence and the port reset, enclosed please find the usbhhub.c for your review.

    Sincerely,

    LB Shi

    usbhhub.c
    //#############################################################################
    // FILE: usbhhub.c
    // TITLE: This file contains the host HID driver
    //#############################################################################
    // $TI Release: F2837xD Support Library v3.05.00.00 $
    // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $
    // $Copyright:
    // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_types.h"
    #include "inc/hw_ints.h"
    #include "usb.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/rtos_bindings.h"
    #include "include/usblib.h"
    #include "include/host/usbhost.h"
    #include "include/host/usbhostpriv.h"
    #include "include/host/usbhhub.h"
    #ifdef INCLUDE_DEBUG_OUTPUT
    #include "utils/uartstdio.h"
    #define DEBUG_OUTPUT UARTprintf
    #else
    #define DEBUG_OUTPUT while(0)((int (*)(char *, ...))0)
    #endif
    
    //*****************************************************************************
    //
    //! \addtogroup usblib_host_class
    //! @{
    //
    //*****************************************************************************
    
    #ifdef ewarm
    #pragma pack(1)
    #endif
    
    //*****************************************************************************
    //
    //! The USB standard hub descriptor structure.  Full documentation for the
    //! contents of this structure can be found in chapter 11.23.2.1 of the USB
    //! 2.0 specification.
    //
    //*****************************************************************************
    typedef struct
    {
        //
        //! The total number of bytes in the descriptor (including this field).
        //
        uint8_t bLength;
    
        //
        //! The descriptor type. For a hub descriptor, this will be USB_DTYPE_HUB
        //! (0x29 or 41 decimal).
        //
        uint8_t bDescType;
    
        //
        //! The number of downstream-facing ports that the hub supports.
        //
        uint8_t bNbrPorts;
    
        //
        //! Characteristics of the hub device including its power switching
        //! capabilities and over-current protection mode.
        //
        uint16_t wHubCharacteristics;
    
        //
        //! The time between the start of the power-on sequence for a port and
        //! the power to the port becoming stable.  This is expressed in 2mS units.
        //
        uint8_t bPwrOn2PwrGood;
    
        //
        //! The maximum current requirement for the hub circuitry in mA.
        //
        uint8_t bHubContrCurrent;
    
        //
        //! The last two fields in the structure are bit masks indicating which
        //! downstream ports support removable devices and, following this, another
        //! obsolete field from USB1.0 related to port power control.  Each field
        //! is byte aligned and contains a bit for each hub port.  This structure
        //! definition is set up with enough storage to handle ROOT_HUB_MAX_PORTS
        //! ports but beware that the actual size of each field is dependent upon
        //! the bNbrPorts field above.
        //
        uint8_t PortInfo[((ROOT_HUB_MAX_PORTS + 7) / 8) * 2];
    }
    PACKED tUsbHubDescriptor;
    
    #ifdef ewarm
    #pragma pack()
    #endif
    
    //*****************************************************************************
    //
    // This structure holds all data specific to a single hub port.
    //
    //*****************************************************************************
    typedef struct
    {
        //
        // The handle used by the HCD layer to identify this device.
        //
        uint32_t ui32DevHandle;
    
        //
        // The current state of the port.
        //
        volatile tHubPortState iState;
    
        //
        // General counter used in various states.
        //
        volatile uint32_t ui32Count;
    
        //
        // A flag used to indicate that the downstream device is a low speed
        // device.
        //
        bool bLowSpeed;
    
        //
        // This flag is set if the hub reports that a change is pending on this
        // port.
        //
        volatile bool bChanged;
    }
    tHubPort;
    
    //*****************************************************************************
    //
    // USB hub flags values for tHubInstance.ui32Flags.
    //
    //*****************************************************************************
    #define USBLIB_HUB_ACTIVE       0x00000001
    
    //*****************************************************************************
    //
    // This is the structure that holds all of the data for a given instance of
    // a Hub device.
    //
    //*****************************************************************************
    struct tHubInstance
    {
        //
        // Save the device instance.
        //
        tUSBHostDevice *psDevice;
    
        //
        // Used to save the callback function pointer.
        //
        tUSBHHubCallback pfnCallback;
    
        //
        // Callback data provided by caller.
        //
        uint32_t ui32CBData;
    
        //
        // Interrupt IN pipe.
        //
        uint32_t ui32IntInPipe;
    
        //
        // Hub characteristics as reported in the class-specific hub descriptor.
        //
        uint16_t ui16HubCharacteristics;
    
        //
        // The number of downstream-facing ports the hub supports.
        //
        uint8_t ui8NumPorts;
    
        //
        // The number of ports on the hub that we can actually talk to.  This will
        // be the smaller of the number of ports on the hub and MAX_USB_DEVICES.
        //
        uint8_t ui8NumPortsInUse;
    
        //
        // The size of a status change packet sent by the hub.  This is determined
        // from the number of ports supported by the hub.
        //
        uint8_t ui8ReportSize;
    
        //
        // Flags indicating whether the hub is connected.
        //
        uint32_t ui32Flags;
    
        //
        // Flag indicating that a device is currently in process of being
        // enumerated.
        //
        volatile bool bEnumerationBusy;
    
        //
        // This is valid if bEnumerationBusy is set and indicates the port
        // that is in the process of enumeration.
        //
        uint8_t ui8EnumIdx;
    
        //
        // The state of each of the ports we support on the hub.
        //
        tHubPort psPorts[MAX_USB_DEVICES];
    
        //
        // The interrupt number for this instance.
        //
        uint32_t ui32IntNum;
    };
    
    //*****************************************************************************
    //
    //! Forward references to the hub class driver functions.
    //
    //*****************************************************************************
    static void *HubDriverOpen(tUSBHostDevice *psDevice);
    static void HubDriverClose(void *pvHubDevice);
    
    //*****************************************************************************
    //
    //! This constant global structure defines the Hub Class Driver that is
    //! provided with the USB library.
    //
    //*****************************************************************************
    const tUSBHostClassDriver g_sUSBHubClassDriver =
    {
        USB_CLASS_HUB,
        HubDriverOpen,
        HubDriverClose,
        0
    };
    
    //*****************************************************************************
    //
    // The instance data storage for attached hub.
    //
    //*****************************************************************************
    static tHubInstance g_sRootHub;
    
    //*****************************************************************************
    //
    // Hub and port state change flags as reported via the hub's IN endpoint.
    //
    //*****************************************************************************
    static volatile uint32_t g_ui32ChangeFlags;
    
    //
    // Note: The following assumes ROOT_HUB_MAX_PORTS is less than 32!
    //
    static uint32_t g_ui32HubChanges;
    
    //*****************************************************************************
    //
    // This function is called to send a request to the hub to set a feature on
    // a given port.
    //
    // \param psHubInstance is the hub device instance.
    // \param ui8Port is the port number for this request.
    // \param ui16Feature is one of the HUB_FEATURE_PORT_* values.
    //
    // This function will send the set feature request to the hub indicated by the
    // \e psHubInstance parameter.  The \e ui8Port value indicates which port
    // number to send this request to and can range from 0 to the number of valid
    // ports on the given hub.  A \e ui8Port value of 0 is an access to the hub
    // itself and not one of the hub ports.  The \e ui16Feature is the feature
    //  request toset on the given port.  For example, a \e ui16Feature value of
    // \e HUB_FEATURE_PORT_RESET and \e ui8Port value of 1 will cause reset
    // signaling to hub port 1.
    //
    // \return None.
    //
    //*****************************************************************************
    static void
    HubSetPortFeature(tHubInstance *psHubInstance, uint8_t ui8Port,
                      uint16_t ui16Feature)
    {
        tUSBRequest sSetupPacket;
        tUSBHostDevice *psDevice;
    
        //
        // Retrieve the hub instance and device pointer.
        //
        psDevice = psHubInstance->psDevice;
    
        //
        // This is a standard OUT request.
        //
        sSetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS |
                                     USB_RTYPE_OTHER;
    
        //
        // Set the field to clear the requested port feature.
        //
        sSetupPacket.bRequest = USBREQ_SET_FEATURE;
        writeusb16_t(&(sSetupPacket.wValue), ui16Feature);
        writeusb16_t(&(sSetupPacket.wIndex), ui8Port);
        writeusb16_t(&(sSetupPacket.wLength), 0);
    
        //
        // Send the request.
        //
        USBHCDControlTransfer(0, &sSetupPacket, psDevice, 0, 0,
                              psDevice->sDeviceDescriptor.bMaxPacketSize0);
    }
    
    //*****************************************************************************
    //
    // This function is called to send a request to the hub to clear a feature on
    // a given port.
    //
    // \param psHubInstance is the hub device instance.
    // \param ui8Port is the port number for this request.
    // \param ui16Feature is one of the HUB_FEATURE_PORT_* values.
    //
    // This function will send the clear feature request to the hub indicated by
    // the \e psHubInstance parameter.  The \e ui8Port value indicates which port
    // number to send this request to and can range from 0 to the number of valid
    // ports on the given hub.  A \e ui8Port value of 0 is an access to the hub
    // itself and not one of the hub ports.  The \e ui16Feature is the feature
    // request to clear on the given port.  For example, a \e ui16Feature value of
    // \e HUB_FEATURE_C_PORT_RESET and \e ui8Port value of 1 will clear the reset
    // complete signaling on hub port 1.  Values like the reset feature will
    // remain set until actively cleared by this function.
    //
    // \return None.
    //
    //*****************************************************************************
    static void
    HubClearPortFeature(tHubInstance *psHubInstance, uint8_t ui8Port,
                        uint16_t ui16Feature)
    {
        tUSBRequest sSetupPacket;
        tUSBHostDevice *psDevice;
    
        //
        // Retrieve the hub instance and device pointer.
        //
        psDevice = psHubInstance->psDevice;
    
        //
        // This is a standard OUT request.
        //
        sSetupPacket.bmRequestType = USB_RTYPE_DIR_OUT | USB_RTYPE_CLASS |
                                     USB_RTYPE_OTHER;
    
        //
        // Set the field to clear the requested port feature.
        //
        sSetupPacket.bRequest = USBREQ_CLEAR_FEATURE;
        writeusb16_t(&(sSetupPacket.wValue), ui16Feature);
        writeusb16_t(&(sSetupPacket.wIndex), ui8Port);
        writeusb16_t(&(sSetupPacket.wLength), 0);
    
        //
        // Send the request.
        //
        USBHCDControlTransfer(0, &sSetupPacket, psDevice, 0, 0,
                              psDevice->sDeviceDescriptor.bMaxPacketSize0);
    }
    
    //*****************************************************************************
    //
    // This function is used to retrieve the current status of a port on the
    // hub.
    //
    // \param psHubInstance is the hub device instance.
    // \param ui8Port is the port number for this request.
    // \param pui16PortStatus is a pointer to the memory to store the current
    // status of the port.
    // \param pui16PortChange is a pointer to the memory to store the current
    // change status of the ports.
    //
    // This function is used to retrieve the current overall status and change
    // status for the port given in the \e ui8Port parameter.  The \e ui8Port value
    // indicates which port number to send this request to and can range from 0 to
    // the number of valid ports on the given hub.  A \e ui8Port value of 0 is an
    // access to the hub itself and not one of the hub ports.
    //
    // \return None.
    //
    //*****************************************************************************
    static bool
    HubGetPortStatus(tHubInstance *psHubInstance, uint8_t ui8Port,
                     uint16_t *pui16PortStatus, uint16_t *pui16PortChange)
    {
        uint32_t ui32Data, ui32Read;
        tUSBRequest sSetupPacket;
        tUSBHostDevice *psDevice;
    
        //
        // Retrieve the device pointer.
        //
        psDevice = psHubInstance->psDevice;
    
        //
        // This is a standard OUT request.
        //
        sSetupPacket.bmRequestType = USB_RTYPE_DIR_IN | USB_RTYPE_CLASS |
                                     USB_RTYPE_OTHER;
    
        //
        // Set the fields to get the hub status.
        //
        sSetupPacket.bRequest = USBREQ_GET_STATUS;
        writeusb16_t(&(sSetupPacket.wValue), 0);
        writeusb16_t(&(sSetupPacket.wIndex), (uint16_t)ui8Port);
        writeusb16_t(&(sSetupPacket.wLength), 4);
    
        //
        // Send the request.
        //
        ui32Read = USBHCDControlTransfer(0, &sSetupPacket, psDevice,
                                    (uint8_t *)&ui32Data, 4,
                                    psDevice->sDeviceDescriptor.bMaxPacketSize0);
    
        //
        // Check that we received the correct number of bytes.
        //
        if(ui32Read != 4)
        {
            return(false);
        }
        else
        {
            //
            // We got 4 bytes from the device. Now translate these into the 2
            // 16-bit values we pass back to the caller.
            //
            *pui16PortStatus = (uint16_t)(ui32Data & 0xFFFF);
            *pui16PortChange = (uint16_t)(ui32Data >> 16);
    
            DEBUG_OUTPUT("Port %d, status 0x%04x, change 0x%04x\n", ui8Port,
                         *pui16PortStatus, *pui16PortChange);
        }
    
        //
        // All is well.
        //
        return(true);
    }
    
    //*****************************************************************************
    //
    // This function handles callbacks for the interrupt IN endpoint for the hub
    // device.
    //
    //*****************************************************************************
    static void
    HubIntINCallback(uint32_t ui32Pipe, uint32_t ui32Event)
    {
        switch (ui32Event)
        {
            //
            // Handles a request to schedule a new request on the interrupt IN
            // pipe.
            //
            case USB_EVENT_SCHEDULER:
            {
                //
                // Set things up to read the next change indication from the hub.
                //
                USBHCDPipeSchedule(ui32Pipe, (uint8_t *)&g_ui32HubChanges,
                                   (uint32_t)g_sRootHub.ui8ReportSize);
                break;
            }
    
            //
            // Called when new data is available on the interrupt IN pipe.
            //
            case USB_EVENT_RX_AVAILABLE:
            {
                //
                // For data transfers on INT IN endpoints, we need to acknowledge
                // the data from this callback.
                //
                USBHCDPipeDataAck(ui32Pipe);
    
                //
                // Update our global "ports needing service" flags with the latest
                // information we have just received.
                //
                g_ui32ChangeFlags |= g_ui32HubChanges;
    
                //
                // Send the report data to the USB host hub device class driver if
                // we have been given a callback function.
                //
                if(g_sRootHub.pfnCallback)
                {
                    g_sRootHub.pfnCallback((void *)g_sRootHub.ui32CBData,
                                           USB_EVENT_RX_AVAILABLE,
                                           ui32Pipe, &g_ui32HubChanges);
                }
    
                break;
            }
            case USB_EVENT_ERROR:
            {
                break;
            }
        }
    }
    
    //*****************************************************************************
    //
    // Query the class-specific hub descriptor.
    //
    //*****************************************************************************
    static bool
    GetHubDescriptor(tUsbHubDescriptor *psDesc)
    {
        uint32_t ui32Read;
        tUSBRequest sSetupPacket;
        tUSBHostDevice *psDevice;
    
        //
        // Retrieve the device pointer.
        //
        psDevice = g_sRootHub.psDevice;
    
        //
        // This is a standard OUT request.
        //
        sSetupPacket.bmRequestType = USB_RTYPE_DIR_IN | USB_RTYPE_CLASS |
                                     USB_RTYPE_DEVICE;
    
        //
        // Set the fields to get the hub descriptor.  Initially, we request only
        // the first 4 bytes of the descriptor.  This will give us the size which
        // we use to determine how many bytes to read to get the full descriptor.
        // This is necessary since we don't know how many ports the hub can support
        // and we only support up to MAX_USB_DEVICES.
        //
        sSetupPacket.bRequest = USBREQ_GET_DESCRIPTOR;
        writeusb16_t(&(sSetupPacket.wValue), ((uint32_t)USB_DTYPE_HUB << 8));
        writeusb16_t(&(sSetupPacket.wIndex), 0);
        writeusb16_t(&(sSetupPacket.wLength), sizeof(tUsbHubDescriptor));
    
        //
        // Send the request.
        //
        ui32Read = USBHCDControlTransfer(0, &sSetupPacket, psDevice,
                                    (void *)psDesc, sizeof(tUsbHubDescriptor),
                                    psDevice->sDeviceDescriptor.bMaxPacketSize0);
    
         //
         // Make sure we got at least some data.
         //
         if(ui32Read == 0)
         {
             return(false);
         }
    
        //
        // All is well.
        //
        return(true);
    }
    
    //*****************************************************************************
    //
    // Open an instance of the hub driver.  This is called when the USB host
    // has enumerated a new hub device.
    //
    //*****************************************************************************
    static void *
    HubDriverOpen(tUSBHostDevice *psDevice)
    {
        tEndpointDescriptor *psEndpointDescriptor;
        tInterfaceDescriptor *psInterface;
        tUsbHubDescriptor sHubDesc;
        bool bRetcode;
        uint32_t ui32Loop;
    
        //
        // If we are already talking to a hub, fail the call.  We only support
        // a single hub.
        //
        if(g_sRootHub.ui32Flags & USBLIB_HUB_ACTIVE)
        {
            return(0);
        }
    
        //
        // Get pointers to the device descriptors we need to look at.
        //
        psInterface = USBDescGetInterface(psDevice->psConfigDescriptor, 0, 0);
        psEndpointDescriptor = USBDescGetInterfaceEndpoint(psInterface, 0,
                                          psDevice->ui32ConfigDescriptorSize);
    
        //
        // If there are no endpoints, something is wrong since a hub must have
        // a single INT endpoint for signaling.
        //
        if(psEndpointDescriptor == 0)
        {
            return 0;
        }
    
        //
        // Make sure we really are talking to a hub.
        //
        if((psInterface->bInterfaceClass != USB_CLASS_HUB) ||
           (psInterface->bInterfaceSubClass != 0))
        {
            //
            // Something is wrong - this isn't a hub or, if it is, we don't
            // understand the protocol it is using.
            //
            return(0);
        }
    
        //
        // Remember the device information for later.
        //
        g_sRootHub.psDevice = psDevice;
    
        //
        // A hub must support an interrupt endpoint so check this.
        //
        if((psEndpointDescriptor->bmAttributes & USB_EP_ATTR_TYPE_M) ==
           USB_EP_ATTR_INT)
        {
            //
            // The endpoint is the correct type. Is it an IN endpoint?
            //
            if(psEndpointDescriptor->bEndpointAddress & USB_EP_DESC_IN)
            {
                //
                // Yes - all is well with the hub endpoint so allocate a pipe to
                // handle traffic from the hub.
                //
                g_sRootHub.ui32IntInPipe = USBHCDPipeAlloc(0, USBHCD_PIPE_INTR_IN,
                                                           psDevice,
                                                           HubIntINCallback);
                USBHCDPipeConfig(g_sRootHub.ui32IntInPipe,
                				 readusb16_t(&(psEndpointDescriptor->wMaxPacketSize)),
                                 psEndpointDescriptor->bInterval,
                                 psEndpointDescriptor->bEndpointAddress &
                                 USB_EP_DESC_NUM_M);
            }
        }
    
        //
        // Did we allocate the endpoint successfully?
        //
        if(!g_sRootHub.ui32IntInPipe)
        {
            //
            // No - return an error.
            //
            return 0;
        }
    
        //
        // Assuming we have a callback, call it to tell the owner that a hub is
        // now connected.
        //
        if(g_sRootHub.pfnCallback != 0)
        {
            g_sRootHub.pfnCallback((void *)g_sRootHub.ui32CBData,
                                   USB_EVENT_CONNECTED, (uint32_t)&g_sRootHub, 0);
        }
    
        //
        // Get the hub descriptor and store information we'll need for later.
        //
        bRetcode = GetHubDescriptor(&sHubDesc);
        if(bRetcode)
        {
    
            //
            // We read the descriptor successfully so extract the parts we need.
            //
            g_sRootHub.ui8NumPorts = sHubDesc.bNbrPorts;
            g_sRootHub.ui16HubCharacteristics = sHubDesc.wHubCharacteristics;
            g_sRootHub.ui8NumPortsInUse =
                (sHubDesc.bNbrPorts > MAX_USB_DEVICES) ? MAX_USB_DEVICES :
                                                         sHubDesc.bNbrPorts;
    
            //
            // The size of the status change report that the hub sends is dependent
            // upon the number of ports that the hub supports.  Calculate this by
            // adding 1 to the number of ports (bit 0 of the report is the hub
            // status, higher bits are one per port) then dividing by 8 (bits per
            // byte) and rounding up.
            //
            g_sRootHub.ui8ReportSize = ((sHubDesc.bNbrPorts + 1) + 7) / 8;
    
            //
            // Enable power to all ports on the hub.
            //
            for(ui32Loop = 1; ui32Loop <= sHubDesc.bNbrPorts; ui32Loop++)
            {
                //
                // Turn on power to this port.
                //
                HubSetPortFeature(&g_sRootHub, ui32Loop,
                                  HUB_FEATURE_PORT_POWER);
            }
    
            //
            // Clear out our port state structures.
            //
            for(ui32Loop = 0; ui32Loop < MAX_USB_DEVICES; ui32Loop++)
            {
                g_sRootHub.psPorts[ui32Loop].bChanged = false;
                g_sRootHub.psPorts[ui32Loop].iState = ePortIdle;
            }
        }
        else
        {
            //
            // Oops - we can't read the hub descriptor!  Tidy up and return
            // an error.
            //
            USBHCDPipeFree(g_sRootHub.ui32IntInPipe);
            g_sRootHub.pfnCallback = 0;
            g_sRootHub.ui32Flags &= ~USBLIB_HUB_ACTIVE;
            return(0);
        }
    
        //
        // If we get here, all is well so remember that the hub is connected and
        // active.
        //
        g_sRootHub.ui32Flags |= USBLIB_HUB_ACTIVE;
    
        //
        // Return our instance data pointer to the caller to use as a handle.
        //
        return((void *)&g_sRootHub);
    }
    
    //*****************************************************************************
    //
    // Close an instance of the hub driver.
    //
    //*****************************************************************************
    static void
    HubDriverClose(void *pvHubDevice)
    {
        uint32_t ui32Loop;
    
        //
        // No device so just exit.
        //
        if(g_sRootHub.psDevice == 0)
        {
            return;
        }
    
        //
        // Disconnect any devices that are currently connected to the hub.
        //
        for(ui32Loop = 0; ui32Loop < MAX_USB_DEVICES; ui32Loop++)
        {
            //
            // Does this port have a device connected to it that we have previously
            // reported to the host control layer?h
            //
            if((g_sRootHub.psPorts[ui32Loop].iState == ePortActive) ||
               (g_sRootHub.psPorts[ui32Loop].iState == ePortResetWait) ||
               (g_sRootHub.psPorts[ui32Loop].iState == ePortEnumerated) ||
               (g_sRootHub.psPorts[ui32Loop].iState == ePortError))
            {
                //
                // Yes - tell the host controller to disconnect the device.
                //
                USBHCDHubDeviceDisconnected(0,
                    g_sRootHub.psPorts[ui32Loop].ui32DevHandle);
    
            }
    
            //
            // Make sure that the state returns to idle.
            //
            g_sRootHub.psPorts[ui32Loop].iState = ePortIdle;
    
        }
    
        //
        // Reset the device pointer.
        //
        g_sRootHub.psDevice = 0;
    
        //
        // Mark the hub as absent.
        //
        g_sRootHub.ui32Flags &= ~USBLIB_HUB_ACTIVE;
    
        //
        // Note that we are not in the middle of enumerating anything.
        //
        g_sRootHub.bEnumerationBusy = false;
    
        //
        // Free the Interrupt IN pipe.
        //
        if(g_sRootHub.ui32IntInPipe != 0)
        {
            USBHCDPipeFree(g_sRootHub.ui32IntInPipe);
        }
    
        //
        // If the callback exists, call it with a DISCONNECTED event.
        //
        if(g_sRootHub.pfnCallback != 0)
        {
            g_sRootHub.pfnCallback((void *)g_sRootHub.ui32CBData,
                                   USB_EVENT_DISCONNECTED, (uint32_t)&g_sRootHub,
                                   0);
        }
    }
    
    //*****************************************************************************
    //
    // Perform any processing required as a result of a change in the reset
    // signaling for a given port.
    //
    //*****************************************************************************
    static void
    HubDriverReset(uint8_t ui8Port, bool bResetActive)
    {
        //
        // Did the reset sequence end or begin?
        //
        if(!bResetActive)
        {
            //
            // The reset ended.  Now wait for at least 10ms before signaling
            // USB enumeration code that a new device is waiting to be enumerated.
            //
            g_sRootHub.psPorts[ui8Port].iState = ePortResetWait;
    
            //
            // Set the wait to 10ms (10 frames) from now.
            //
            g_sRootHub.psPorts[ui8Port].ui32Count = 10;
        }
        else
        {
            //
            // Was this device previously active?
            //
            if(g_sRootHub.psPorts[ui8Port].iState == ePortActive)
            {
                USBHCDHubDeviceDisconnected(0,
                    g_sRootHub.psPorts[ui8Port].ui32DevHandle);
            }
    
            //
            // The reset is active so mark our port as in reset.
            //
            g_sRootHub.psPorts[ui8Port].iState = ePortResetActive;
        }
    }
    
    //*****************************************************************************
    //
    // Start the process of enumerating a new device by issuing a reset to the
    // appropriate downstream port.
    //
    //*****************************************************************************
    static void
    HubDriverDeviceReset(uint8_t ui8Port)
    {
        DEBUG_OUTPUT("Starting enumeration for port %d\n", ui8Port);
    
        //
        // Record the fact that we are in the process of enumerating a device.
        //
        g_sRootHub.bEnumerationBusy = true;
    
        //
        // Save the port that is being enumerated.
        //
        g_sRootHub.ui8EnumIdx = ui8Port;
    
        //
        // Mark the port as being reset.
        //
        g_sRootHub.psPorts[ui8Port].iState = ePortResetActive;
    
        //
        // Initiate a reset on the relevant port to start the enumeration process.
        //
        HubSetPortFeature(&g_sRootHub, ui8Port, HUB_FEATURE_PORT_RESET);
    }
    
    //*****************************************************************************
    //
    // A new device has been connected to the hub.  Allocate resources to manage
    // it and pass details back to the main USB host enumeration code to have the
    // device enumerated.
    //
    //*****************************************************************************
    static void
    HubDriverDeviceConnect(uint8_t ui8Port, bool bLowSpeed)
    {
        DEBUG_OUTPUT("HubDriverDeviceConnect\n");
    
        //
        // We've allocated a port table entry so fill it in then initiate a reset
        // on the device.
        //
        g_sRootHub.psPorts[ui8Port].bChanged = false;
        g_sRootHub.psPorts[ui8Port].bLowSpeed = bLowSpeed;
    
        //
        // Mark the port as having a device present but not enumerated.
        //
        DEBUG_OUTPUT("Deferring enumeration for port %d\n", ui8Port);
        g_sRootHub.psPorts[ui8Port].iState = ePortConnected;
    
        //
        // Wait 100ms to reset the device.
        //
        g_sRootHub.psPorts[ui8Port].ui32Count = 100;
    }
    
    //*****************************************************************************
    //
    // An existing device has been removed from the hub.  Tidy up and let the main
    // USB host code know so that it can free device resources.
    //
    //*****************************************************************************
    static void
    HubDriverDeviceDisconnect(uint8_t ui8Port)
    {
        //
        // This is a device we are currently managing.  Have we already informed
        // the host controller that it is present?
        //
        if((g_sRootHub.psPorts[ui8Port].iState == ePortActive) ||
           (g_sRootHub.psPorts[ui8Port].iState == ePortResetWait) ||
           (g_sRootHub.psPorts[ui8Port].iState == ePortEnumerated) ||
           (g_sRootHub.psPorts[ui8Port].iState == ePortError))
        {
            //
            // Yes - tell the host controller that the device is not longer
            // connected.
            //
            USBHCDHubDeviceDisconnected(0,
                                    g_sRootHub.psPorts[ui8Port].ui32DevHandle);
        }
    
        //
        // If the device was being enumerated, make sure we clear the flag
        // indicating that an enumeration is still ongoing.
        //
        if((g_sRootHub.psPorts[ui8Port].iState == ePortResetActive) ||
           (g_sRootHub.psPorts[ui8Port].iState == ePortResetWait) ||
           (g_sRootHub.psPorts[ui8Port].iState == ePortActive))
        {
            g_sRootHub.bEnumerationBusy = false;
        }
    
        //
        // Free up the port state structure.
        //
        g_sRootHub.psPorts[ui8Port].iState = ePortIdle;
    }
    
    //*****************************************************************************
    //
    // This function is called periodically by USBHCDMain().  We use it to handle
    // the hub port state machine.
    //
    //*****************************************************************************
    void
    USBHHubMain(void)
    {
        uint16_t ui16Status, ui16Changed;
        uint_fast8_t ui8Port;
        bool bRetcode;
    
        //
        // If the hub is not present, just return.
        //
        if((g_sRootHub.ui32Flags & USBLIB_HUB_ACTIVE) == 0)
        {
            return;
        }
    
        //
        // Initialize the status variables.
        //
        ui16Status = 0;
        ui16Changed = 0;
    
        //
        // The hub is active and something changed. Check to see which port changed
        // state and handle as necessary.
        //
        for(ui8Port = 0; ui8Port <= g_sRootHub.ui8NumPortsInUse; ui8Port++)
        {
            //
            // Decrement any wait counter if there is one present.
            //
            if(g_sRootHub.psPorts[ui8Port].ui32Count != 0)
            {
                g_sRootHub.psPorts[ui8Port].ui32Count--;
            }
    
            //
            // Is this port waiting to be enumerated and is the last device
            // enumeration finished?
            //
            if((g_sRootHub.psPorts[ui8Port].iState == ePortConnected) &&
               (!g_sRootHub.bEnumerationBusy) &&
               (g_sRootHub.psPorts[ui8Port].ui32Count == 0))
            {
                //
                // Yes - start the enumeration processing for this device.
                //
                HubDriverDeviceReset(ui8Port);
            }
    
            //
            // If the state is ePortResetWait then the hub is waiting before
            // accessing device as the USB 2.0 specification requires.
            //
            if((g_sRootHub.psPorts[ui8Port].iState == ePortResetWait) &&
               (g_sRootHub.psPorts[ui8Port].ui32Count == 0))
            {
                //
                // Start the enumeration process if the timeout has passed and
                // the hub is waiting to start enumerating the device.
                //
                g_sRootHub.psPorts[ui8Port].iState = ePortActive;
    
                //
                // Call the main host controller layer to have it enumerate the
                // newly connected device.
                //
                g_sRootHub.psPorts[ui8Port].ui32DevHandle =
                    USBHCDHubDeviceConnected(0, 1, ui8Port,
                                     g_sRootHub.psPorts[ui8Port].bLowSpeed);
            }
    
            //
            // If an enumeration is in progress and the loop is not on the port
            // being enumerated then skip the port.
            //
            if(g_sRootHub.bEnumerationBusy &&
               (g_sRootHub.ui8EnumIdx != ui8Port))
            {
                continue;
            }
    
            //
            // Did something change for this particular port?
            //
            if(g_ui32ChangeFlags & ((uint32_t)1 << ui8Port))
            {
                //
                // Yes - query the port status.
                //
                bRetcode = HubGetPortStatus(&g_sRootHub, ui8Port,
                                            &ui16Status, &ui16Changed);
    
                //
                // Clear this change with the USB interrupt temporarily disabled to
                // ensure that we do not clear a flag that the interrupt routine
                // has just set.
                //
                OS_INT_DISABLE(g_sRootHub.ui32IntNum);
                g_ui32ChangeFlags &= ~((uint32_t)1 << ui8Port);
                OS_INT_ENABLE(g_sRootHub.ui32IntNum);
    
                //
                // If there was an error, go on and look at the next bit.
                //
                if(!bRetcode)
                {
                    continue;
                }
    
                //
                // Now consider what changed and handle it as necessary.
                //
    
                //
                // Was a device connected to or disconnected from the port?
                //
                if(ui16Changed & HUB_PORT_CHANGE_DEVICE_PRESENT)
                {
                    DEBUG_OUTPUT("Connection change on port %d\n", ui8Port);
    
                    //
                    // Clear the condition.
                    //
                    HubClearPortFeature(&g_sRootHub, ui8Port,
                                        HUB_FEATURE_C_PORT_CONNECTION);
    
                    //
                    // Was a device connected or disconnected?
                    //
                    if(ui16Status & HUB_PORT_STATUS_DEVICE_PRESENT)
                    {
                        DEBUG_OUTPUT("Connected\n");
    
                        //
                        // A device was connected.
                        //
                        HubDriverDeviceConnect(ui8Port,
                                ((ui16Status & HUB_PORT_STATUS_LOW_SPEED) ?
                                 true : false));
                    }
                    else
                    {
                        DEBUG_OUTPUT("Disconnected\n");
    
                        //
                        // A device was disconnected.
                        //
                        HubDriverDeviceDisconnect(ui8Port);
                    }
                }
    
                //
                // Did a reset on the port complete?
                //
                if(ui16Changed & HUB_PORT_CHANGE_RESET)
                {
                    //
                    // Clear the condition.
                    //
                    HubClearPortFeature(&g_sRootHub, ui8Port,
                                        HUB_FEATURE_C_PORT_RESET);
    
                    //
                    // Yes - query the port status.
                    //
                    bRetcode = HubGetPortStatus(&g_sRootHub, ui8Port,
                                                &ui16Status, &ui16Changed);
    
                    DEBUG_OUTPUT("Reset %s for port %d\n",
                            ((ui16Status & HUB_PORT_STATUS_RESET) ? "asserted" :
                            "deasserted"), ui8Port);
    
                    //
                    // Handle the reset case.
                    //
                    HubDriverReset(ui8Port, (ui16Status & HUB_PORT_STATUS_RESET) ?
                                   true : false);
                }
    
                //
                // Did an over-current reset on the port complete?
                //
                if(ui16Changed & HUB_PORT_CHANGE_OVER_CURRENT)
                {
                    DEBUG_OUTPUT("Port %d over current.\n", ui8Port);
    
                    //
                    // Currently we ignore this and just clear the condition.
                    //
                    HubClearPortFeature(&g_sRootHub, ui8Port,
                                        HUB_FEATURE_C_PORT_OVER_CURRENT);
                }
    
                //
                // Has the port been enabled or disabled?
                //
                if(ui16Changed & HUB_PORT_CHANGE_ENABLED)
                {
                    DEBUG_OUTPUT("Enable change for port %d.\n", ui8Port);
    
                    //
                    // Currently we ignore this and just clear the condition.
                    //
                    HubClearPortFeature(&g_sRootHub, ui8Port,
                                        HUB_FEATURE_C_PORT_ENABLE);
                }
    
                //
                // Has the port been suspended or resumed?
                //
                if(ui16Changed & HUB_PORT_CHANGE_SUSPENDED)
                {
                    DEBUG_OUTPUT("Suspend change for port %d.\n", ui8Port);
    
                    //
                    // Currently we ignore this and just clear the condition.
                    //
                    HubClearPortFeature(&g_sRootHub, ui8Port,
                                        HUB_FEATURE_C_PORT_SUSPEND);
                }
            }
        }
    }
    
    //*****************************************************************************
    //
    //! Informs the hub class driver that a downstream device has been enumerated.
    //!
    //! \param ui8Hub is the address of the hub to which the downstream device
    //! is attached.
    //! \param ui8Port is the port on the hub to which the downstream device is
    //! attached.
    //!
    //! This function is called by the host controller driver to inform the hub
    //! class driver that a downstream device has been enumerated successfully.
    //! The hub driver then moves on and continues enumeration of any other newly
    //! connected devices.
    //!
    //! \return None.
    //
    //*****************************************************************************
    void
    USBHHubEnumerationComplete(uint8_t ui8Hub, uint8_t ui8Port)
    {
        DEBUG_OUTPUT("Enumeration complete for hub %d, port %d\n", ui8Hub, ui8Port);
    
        //
        // Record the fact that the device is up and running.
        //
        g_sRootHub.psPorts[ui8Port].iState = ePortEnumerated;
    
        //
        // Clear the flag we use to defer further enumerations.  This will cause
        // the next connected device (if any) to start enumeration on the next
        // call to USBHHubMain().
        //
        g_sRootHub.bEnumerationBusy = false;
    }
    
    //*****************************************************************************
    //
    //! Informs the hub class driver that a downstream device failed to enumerate.
    //!
    //! \param ui8Hub is the address of the hub to which the downstream device
    //! is attached.
    //! \param ui8Port is the port on the hub to which the downstream device is
    //! attached.
    //!
    //! This function is called by the host controller driver to inform the hub
    //! class driver that an attempt to enumerate a downstream device has failed.
    //! The hub driver then cleans up and continues enumeration of any other newly
    //! connected devices.
    //!
    //! \return None.
    //
    //*****************************************************************************
    void
    USBHHubEnumerationError(uint8_t ui8Hub, uint8_t ui8Port)
    {
        DEBUG_OUTPUT("Enumeration error for hub %d, port %d\n", ui8Hub, ui8Port);
    
        //
        // Record the fact that the device is not working correctly.
        //
        g_sRootHub.psPorts[ui8Port].iState = ePortError;
    
        //
        // Clear the flag we use to defer further enumerations.  This will cause
        // the next connected device (if any) to start enumeration on the next
        // call to USBHHubMain().
        //
        g_sRootHub.bEnumerationBusy = false;
    }
    
    //*****************************************************************************
    //
    //! This function is used to enable the host hub class driver before any
    //! devices are present.
    //!
    //! \param pfnCallback is the driver call back for host hub events.
    //!
    //! This function is called to open an instance of a host hub device and
    //! provides a valid callback function for host hub events in the
    //! \e pfnCallback parameter.  This function must be called before the USB
    //! host code can successfully enumerate a hub device or any devices attached
    //! to the hub.  The \e pui8HubPool is memory provided to the hub class to
    //! manage the devices that are connected to the hub.  The \e ui32PoolSize is
    //! the number of bytes and should be at least 32 bytes per device including
    //! the hub device itself.  A simple formula for providing memory to the hub
    //! class is \b MAX_USB_DEVICES * 32 bytes of data to allow for proper
    //! enumeration of connected devices.  The value for \b MAX_USB_DEVICES is
    //! defined in the usblib.h file and controls the number of devices
    //! supported by the USB library.  The \e ui32NumHubs parameter
    //! defaults to one and only one buffer of size tHubInstance is required to
    //! be passed in the \e psHubInstance parameter.
    //!
    //! \note Changing the value of \b MAX_USB_DEVICES requires a rebuild of the
    //! USB library to have an effect on the library.
    //!
    //! \return This function returns the driver instance to use for the other
    //! host hub functions.  If there is no instance available at the time of
    //! this call, this function returns zero.
    //
    //*****************************************************************************
    tHubInstance *
    USBHHubOpen(tUSBHHubCallback pfnCallback)
    {
        //
        // Only one hub is supported.
        //
        if(g_sRootHub.pfnCallback)
        {
            DEBUG_OUTPUT("USBHHubOpen failed - already connected.\n");
            return(0);
        }
    
        //
        // Save the instance data for this device.
        //
        g_sRootHub.pfnCallback = pfnCallback;
    
        DEBUG_OUTPUT("USBHHubOpen completed.\n");
    
        //
        // Return the device instance pointer.
        //
        return(&g_sRootHub);
    }
    
    //*****************************************************************************
    //
    //! This function is used to release a hub device instance.
    //!
    //! \param psHubInstance is the hub device instance that is to be released.
    //!
    //! This function is called when an instance of the hub device must be
    //! released.  This function is typically made in preparation for shutdown or a
    //! switch to function as a USB device when in OTG mode.  Following this call,
    //! the hub device is no longer available, but it can be opened again using a
    //! call to USBHHubOpen().  After calling USBHHubClose(), the host hub driver
    //! no longer provides any callbacks or accepts calls to other hub driver APIs.
    //!
    //! \return None.
    //
    //*****************************************************************************
    void
    USBHHubClose(tHubInstance *psHubInstance)
    {
        //
        // Forget the instance pointer and callback.
        //
        psHubInstance->psDevice = 0;
        psHubInstance->pfnCallback = 0;
    
        DEBUG_OUTPUT("USBHHubClose completed.\n");
    }
    
    //*****************************************************************************
    //
    // This function is used to initialize the Hub driver.  This is an internal
    // function that should not be called by the application.
    //
    //*****************************************************************************
    void
    USBHHubInit(void)
    {
        //
        // Initialize Hub state.
        //
        g_ui32ChangeFlags = 0;
        g_ui32HubChanges = 0;
    
        g_sRootHub.ui32Flags = 0;
    
        if(g_sRootHub.psDevice != 0)
        {
            //
            // Save the USB interrupt number.
            //
            g_sRootHub.ui32IntNum = INT_USB0;
        }
    }
    
    //*****************************************************************************
    //
    //! @}
    //
    //*****************************************************************************
    

  • Hi,

    I am facing some issue replicating this issue. I will try to get back to you as soon as possible.

    Thanks and Regards
    Harshmeet
  • Hi Lianbing,

    Sorry for the late response.

    I looked at the file you shared.

    I am running the usb host mouse example. Do i need to add something specific to get the port to reset?

    I am not able to reach the file. I tried calling the API Directly but is there a specific sequence? What is the update you made to the Host Mouse example?

    Regards
    Harshmeet

  • Hi Harshmeet,

     

    Thanks for your great support.

    Our hardware configuration is TMS320F377D -> USB hub(any USB hub can duplicate this issue.)->USB mouse.

    The reset can't be completed since there is no correct return value for HubGetPortStatus. It's OK for TMS320F377D ->USB mouse.

    Would you help checking it again following the configuration with USB hub, please?

     

    Attachment is showing the code for you review.

     

    Sincerely,

     

    Lianbing

    6087.usbhostenum.c

  • Hi Lianbing,

    Apologies for the late reply. I was out of office. I will check this today and get back to you in a few hours.

    Thanks and Regards
    Harshmeet Singh
  • Hi Lianbing,

    Can you share your main example file?

    Regards
    Harshmeet
  • Hi Harshment,

    Attachment is showing the main example file. Please take a look.

    Sincerely,

    LB Shi

    usb_host_mouse.c
    //###########################################################################
    //
    // FILE:   usb_host_mouse.c
    //
    // TITLE:  Main application code for the host mouse example.
    //
    //###########################################################################
    // $TI Release: F2837xD Support Library v3.05.00.00 $
    // $Release Date: Thu Oct 18 15:48:42 CDT 2018 $
    // $Copyright:
    // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //###########################################################################
    
    //
    // Included Files
    //
    #include "F28x_Project.h"
    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/uart.h"
    #include "usb.h"
    #include "usb_hal.h"
    #include "include/usblib.h"
    #include "include/usbhid.h"
    #include "include/host/usbhost.h"
    #include "include/host/usbhhid.h"
    #include "include/host/usbhhidmouse.h"
    #include "utils/uartstdio.h"
    #include "include/host/usbhhub.h"
    #include "fatfs/src/ff.h"
    #include "utils/cmdline.h"
    #include "include/host/usbhmsc.h"
    #include "include/usbmsc.h"
    #include <string.h>
    
    //*****************************************************************************
    //
    //! \addtogroup cpu01_example_list
    //! <h1>USB HID Mouse Host (usb_host_mouse)</h1>
    //!
    //! This application demonstrates the handling of a USB mouse attached to the
    //! evaluation kit.  Once attached, the position of the mouse pointer and the
    //! state of the mouse buttons are output to the display.
    //!
    //! The first UART, which is connected to the FTDI virtual serial port on the
    //! controlCARD board, is configured for 115,200 bits per second, and 8-N-1
    //! mode.  When a HID compliant mouse is connected to the microUSB port on the
    //! top of the controlCARD, position and button information will be displayed
    //! to the console.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // The number of SysTick ticks per second.
    //
    //*****************************************************************************
    #define TICKS_PER_SECOND 100
    #define MS_PER_SYSTICK (1000 / TICKS_PER_SECOND)
    
    //*****************************************************************************
    //
    // Our running system tick counter and a global used to determine the time
    // elapsed since last call to GetTickms().
    //
    //*****************************************************************************
    uint32_t g_ui32SysTickCount;
    uint32_t g_ui32LastTick;
    
    //*****************************************************************************
    //
    // Defines the size of the buffers that hold the path, or temporary data from
    // the memory card.  There are two buffers allocated of this size.  The buffer
    // size must be large enough to hold the longest expected full path name,
    // including the file name, and a trailing null character.
    //
    //*****************************************************************************
    #define PATH_BUF_SIZE   80
    
    //*****************************************************************************
    //
    // Defines the size of the buffer that holds the command line.
    //
    //*****************************************************************************
    #define CMD_BUF_SIZE    64
    
    //*****************************************************************************
    //
    // This buffer holds the full path to the current working directory.  Initially
    // it is root ("/").
    //
    //*****************************************************************************
    //static char g_cCwdBuf[PATH_BUF_SIZE] = "/";
    
    //*****************************************************************************
    //
    // A temporary data buffer used when manipulating file paths, or reading data
    // from the memory card.
    //
    //*****************************************************************************
    //static char g_cTmpBuf[PATH_BUF_SIZE];
    
    //*****************************************************************************
    //
    // The buffer that holds the command line.
    //
    //*****************************************************************************
    //static char g_cCmdBuf[CMD_BUF_SIZE];
    
    //*****************************************************************************
    //
    // Current FAT fs state.
    //
    //*****************************************************************************
    static FATFS g_sFatFs;
    //static DIR g_sDirObject;
    //static FILINFO g_sFileInfo;
    //static FIL g_sFileObject;
    
    //*****************************************************************************
    //
    // A structure that holds a mapping between an FRESULT numerical code,
    // and a string representation.  FRESULT codes are returned from the FatFs
    // FAT file system driver.
    //
    //*****************************************************************************
    //typedef struct
    //{
    //    FRESULT fresult;
    //    char *pcResultStr;
    //}
    //tFresultString;
    
    //*****************************************************************************
    //
    // A macro to make it easy to add result codes to the table.
    //
    //*****************************************************************************
    //#define FRESULT_ENTRY(f)        { (f), (#f) }
    
    //*****************************************************************************
    //
    // A table that holds a mapping between the numerical FRESULT code and
    // it's name as a string.  This is used for looking up error codes for
    // printing to the console.
    //
    //*****************************************************************************
    //tFresultString g_sFresultStrings[] =
    //{
    //    FRESULT_ENTRY(FR_OK),
    //    FRESULT_ENTRY(FR_NOT_READY),
    //    FRESULT_ENTRY(FR_NO_FILE),
    //    FRESULT_ENTRY(FR_NO_PATH),
    //    FRESULT_ENTRY(FR_INVALID_NAME),
    //    FRESULT_ENTRY(FR_INVALID_DRIVE),
    //    FRESULT_ENTRY(FR_DENIED),
    //    FRESULT_ENTRY(FR_EXIST),
    //    FRESULT_ENTRY(FR_RW_ERROR),
    //    FRESULT_ENTRY(FR_WRITE_PROTECTED),
    //    FRESULT_ENTRY(FR_NOT_ENABLED),
    //    FRESULT_ENTRY(FR_NO_FILESYSTEM),
    //    FRESULT_ENTRY(FR_INVALID_OBJECT),
    //    FRESULT_ENTRY(FR_MKFS_ABORTED)
    //};
    
    //*****************************************************************************
    //
    // A macro that holds the number of result codes.
    //
    //*****************************************************************************
    //#define NUM_FRESULT_CODES (sizeof(g_sFresultStrings) / sizeof(tFresultString))
    
    //*****************************************************************************
    //
    // The size of the host controller's memory pool in bytes.
    //
    //*****************************************************************************
    #define HCD_MEMORY_SIZE         128
    
    //*****************************************************************************
    //
    // The memory pool to provide to the Host controller driver.
    //
    //*****************************************************************************
    uint8_t g_pui8HCDPool[HCD_MEMORY_SIZE];
    
    //*****************************************************************************
    //
    // The size of the mouse device interface's memory pool in bytes.
    //
    //*****************************************************************************
    #define MOUSE_MEMORY_SIZE       128
    
    //*****************************************************************************
    //
    // The memory pool to provide to the mouse device.
    //
    //*****************************************************************************
    uint8_t g_pui8Buffer[MOUSE_MEMORY_SIZE];
    
    //*****************************************************************************
    //
    // Declare the USB Events driver interface.
    //
    //*****************************************************************************
    DECLARE_EVENT_DRIVER(g_sUSBEventDriver, 0, 0, USBHCDEvents);
    
    //*****************************************************************************
    //
    // The global that holds all of the host drivers in use in the application.
    // In this case, only the Mouse class is loaded.
    //
    //*****************************************************************************
    static tUSBHostClassDriver const * const g_ppHostClassDrivers[][2] =
    {
        {
             &g_sUSBHubClassDriver,
             &g_sUSBEventDriver
        },
    
        {
             &g_sUSBHostMSCClassDriver,
             &g_sUSBEventDriver
        }
    };
    
    //*****************************************************************************
    //
    // This global holds the number of class drivers in the g_ppHostClassDrivers
    // list.
    //
    //*****************************************************************************
    static const uint32_t g_ui32NumHostClassDrivers =
        sizeof(g_ppHostClassDrivers) / sizeof(tUSBHostClassDriver *);
    
    //*****************************************************************************
    //
    // The global value used to store the mouse instance value.
    //
    //*****************************************************************************
    static tUSBHMouse *g_psMouseInstance;
    
    //*****************************************************************************
    //
    // The instance data for the MSC driver.
    //
    //*****************************************************************************
    tUSBHMSCInstance *g_psMSCInstance = 0;
    
    //*****************************************************************************
    //
    // The global values used to store the mouse state.
    //
    //*****************************************************************************
    static uint32_t g_ui32Buttons;
    static int32_t g_i32CursorX;
    static int32_t g_i32CursorY;
    
    //*****************************************************************************
    //
    // The current USB operating mode - Host, Device or unknown.
    //
    //*****************************************************************************
    tUSBMode g_eCurrentUSBMode;
    
    //*****************************************************************************
    //
    // Hold the current state for the application.
    //
    //*****************************************************************************
    typedef enum
    {
        //
        // No device is present.
        //
        STATE_NO_DEVICE,
    
        //
        // Device has been detected and needs to be initialized in the main
        // loop.
        //
        STATE_DEVICE_INIT,
    
        //
        // Mass storage device is being enumerated.
        //
        STATE_DEVICE_ENUM,
    
        //
        // Mass storage device is ready.
        //
        STATE_DEVICE_READY,
    
        //
        // An unsupported device has been attached.
        //
        STATE_UNKNOWN_DEVICE,
    
        //
        // A power fault has occurred.
        //
        STATE_POWER_FAULT
    }
    tState;
    volatile tState g_eState;
    volatile tState g_eUIState;
    
    //*****************************************************************************
    //
    // The error routine that is called if the driver library encounters an error.
    //
    //*****************************************************************************
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif
    
    //*****************************************************************************
    //
    // This is the generic callback from host stack.
    //
    // pvData is actually a pointer to a tEventInfo structure.
    //
    // This function will be called to inform the application when a USB event has
    // occurred that is outside those related to the mouse device.  At this
    // point this is used to detect unsupported devices being inserted and removed.
    // It is also used to inform the application when a power fault has occurred.
    // This function is required when the g_USBGenericEventDriver is included in
    // the host controller driver array that is passed in to the
    // USBHCDRegisterDrivers() function.
    //
    //*****************************************************************************
    void
    USBHCDEvents(void *pvData)
    {
        tEventInfo *pEventInfo;
    
        //
        // Cast this pointer to its actual type.
        //
        pEventInfo = (tEventInfo *)pvData;
    
        switch(pEventInfo->ui32Event)
        {
            //
            // New mouse detected.
            //
            case USB_EVENT_CONNECTED:
            {
    
                g_eState = STATE_DEVICE_INIT;
    
                //
                // See if this is a HID Mouse.
                //
    //            if(USBHCDDevClass(pEventInfo->ui32Instance, 0) == USB_CLASS_MASS_STORAGE)
    //            {
    //                //
    //                // Proceed to the STATE_DEVICE_INIT state so that the main loop
    //                // can finish initialized the mouse since USBHMouseInit()
    //                // cannot be called from within a callback.
    //                //
    //                g_eState = STATE_DEVICE_INIT;
    //            }
    
                break;
            }
            //
            // Unsupported device detected.
            //
            case USB_EVENT_UNKNOWN_CONNECTED:
            {
                //
                // An unknown device was detected.
                //
                g_eState = STATE_UNKNOWN_DEVICE;
                UARTprintf("Unknown Device Connected\n");
    
                break;
            }
            //
            // Device has been unplugged.
            //
            case USB_EVENT_DISCONNECTED:
            {
    
                //
                // Change the state so that the main loop knows that the device is
                // no longer present.
                //
                g_eState = STATE_NO_DEVICE;
                UARTprintf("Device Disconnected\n");
    
                //
                // Reset the button state.
                //
                g_ui32Buttons = 0;
    
                break;
            }
            //
            // Power Fault has occurred.
            //
            case USB_EVENT_POWER_FAULT:
            {
    
                //
                // No power means no device is present.
                //
                g_eState = STATE_POWER_FAULT;
                UARTprintf("Power Fault\n");
    
                break;
            }
    
            default:
            {
                break;
            }
        }
    }
    
    //*****************************************************************************
    //
    // This is the handler for this SysTick interrupt.
    //
    //*****************************************************************************
    __interrupt void
    SysTickIntHandler(void)
    {
        //
        // Update our tick counter.
        //
        g_ui32SysTickCount++;
        PieCtrlRegs.PIEACK.all |= 1;
    }
    
    //*****************************************************************************
    //
    // This function returns the number of ticks since the last time this function
    // was called.
    //
    //*****************************************************************************
    uint32_t
    GetTickms(void)
    {
        uint32_t ui32RetVal;
        uint32_t ui32Saved;
    
        ui32RetVal = g_ui32SysTickCount;
        ui32Saved = ui32RetVal;
    
        if(ui32Saved > g_ui32LastTick)
        {
            ui32RetVal = ui32Saved - g_ui32LastTick;
        }
        else
        {
            ui32RetVal = g_ui32LastTick - ui32Saved;
        }
    
        //
        // This could miss a few milliseconds but the timings here are on a
        // much larger scale.
        //
        g_ui32LastTick = ui32Saved;
    
        //
        // Return the number of milliseconds since the last time this was called.
        //
        return(ui32RetVal * MS_PER_SYSTICK);
    }
    
    //*****************************************************************************
    //
    // USB Mode callback
    //
    // \param ui32Index is the zero-based index of the USB controller making the
    //        callback.
    // \param eMode indicates the new operating mode.
    //
    // This function is called by the USB library whenever an OTG mode change
    // occurs and, if a connection has been made, informs us of whether we are to
    // operate as a host or device.
    //
    // \return None.
    //
    //*****************************************************************************
    void
    ModeCallback(uint32_t ui32Index, tUSBMode eMode)
    {
        //
        // Save the new mode.
        //
        g_eCurrentUSBMode = eMode;
    
    }
    //
    ////*****************************************************************************
    ////
    //// This function returns a string representation of an error code that was
    //// returned from a function call to FatFs.  It can be used for printing human
    //// readable error messages.
    ////
    ////*****************************************************************************
    //const char *
    //StringFromFresult(FRESULT fresult)
    //{
    //    unsigned int uIdx;
    //
    //    //
    //    // Enter a loop to search the error code table for a matching error code.
    //    //
    //    for(uIdx = 0; uIdx < NUM_FRESULT_CODES; uIdx++)
    //    {
    //        //
    //        // If a match is found, then return the string name of the error code.
    //        //
    //        if(g_sFresultStrings[uIdx].fresult == fresult)
    //        {
    //            return(g_sFresultStrings[uIdx].pcResultStr);
    //        }
    //    }
    //
    //    //
    //    // At this point no matching code was found, so return a string indicating
    //    // unknown error.
    //    //
    //    return("UNKNOWN ERROR CODE");
    //}
    //
    ////*****************************************************************************
    ////
    //// This function implements the "ls" command.  It opens the current directory
    //// and enumerates through the contents, and prints a line for each item it
    //// finds.  It shows details such as file attributes, time and date, and the
    //// file size, along with the name.  It shows a summary of file sizes at the end
    //// along with free space.
    ////
    ////*****************************************************************************
    //int
    //Cmd_ls(int argc, char *argv[])
    //{
    //    unsigned long ulTotalSize;
    //    unsigned long ulFileCount;
    //    unsigned long ulDirCount;
    //    FRESULT fresult;
    //    FATFS *pFatFs;
    //
    //    //
    //    // Do not attempt to do anything if there is not a drive attached.
    //    //
    //    if(g_eState != STATE_DEVICE_READY)
    //    {
    //        return(FR_NOT_READY);
    //    }
    //
    //    //
    //    // Open the current directory for access.
    //    //
    //    fresult = f_opendir(&g_sDirObject, g_cCwdBuf);
    //
    //    //
    //    // Check for error and return if there is a problem.
    //    //
    //    if(fresult != FR_OK)
    //    {
    //        return(fresult);
    //    }
    //
    //    ulTotalSize = 0;
    //    ulFileCount = 0;
    //    ulDirCount = 0;
    //
    //    //
    //    // Enter loop to enumerate through all directory entries.
    //    //
    //    while(1)
    //    {
    //        //
    //        // Read an entry from the directory.
    //        //
    //        fresult = f_readdir(&g_sDirObject, &g_sFileInfo);
    //
    //        //
    //        // Check for error and return if there is a problem.
    //        //
    //        if(fresult != FR_OK)
    //        {
    //            return(fresult);
    //        }
    //
    //        //
    //        // If the file name is blank, then this is the end of the listing.
    //        //
    //        if(!g_sFileInfo.fname[0])
    //        {
    //            break;
    //        }
    //
    //        //
    //        // If the attribute is directory, then increment the directory count.
    //        //
    //        if(g_sFileInfo.fattrib & AM_DIR)
    //        {
    //            ulDirCount++;
    //        }
    //
    //        //
    //        // Otherwise, it is a file.  Increment the file count, and add in the
    //        // file size to the total.
    //        //
    //        else
    //        {
    //            ulFileCount++;
    //            ulTotalSize += g_sFileInfo.fsize;
    //        }
    //
    //        //
    //        // Print the entry information on a single line with formatting to show
    //        // the attributes, date, time, size, and name.
    //        //
    //        UARTprintf("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9u  %s\n",
    //                   (g_sFileInfo.fattrib & AM_DIR) ? (uint32_t)'D' : (uint32_t)'-',
    //                   (g_sFileInfo.fattrib & AM_RDO) ? (uint32_t)'R' : (uint32_t)'-',
    //                   (g_sFileInfo.fattrib & AM_HID) ? (uint32_t)'H' : (uint32_t)'-',
    //                   (g_sFileInfo.fattrib & AM_SYS) ? (uint32_t)'S' : (uint32_t)'-',
    //                   (g_sFileInfo.fattrib & AM_ARC) ? (uint32_t)'A' : (uint32_t)'-',
    //                   (uint32_t)((g_sFileInfo.fdate >> 9) + 1980),
    //                   (uint32_t)((g_sFileInfo.fdate >> 5) & 15),
    //                   (uint32_t)(g_sFileInfo.fdate & 31),
    //                   (uint32_t)((g_sFileInfo.ftime >> 11)),
    //                   (uint32_t)((g_sFileInfo.ftime >> 5) & 63),
    //                   (uint32_t)(g_sFileInfo.fsize),
    //                   g_sFileInfo.fname);
    //    }
    //
    //    //
    //    // Print summary lines showing the file, dir, and size totals.
    //    //
    //    UARTprintf("\n%4u File(s),%10u bytes total\n%4u Dir(s)",
    //               ulFileCount, ulTotalSize, ulDirCount);
    //
    //    //
    //    // Get the free space.
    //    //
    //    fresult = f_getfree("/", &ulTotalSize, &pFatFs);
    //
    //    //
    //    // Check for error and return if there is a problem.
    //    //
    //    if(fresult != FR_OK)
    //    {
    //        return(fresult);
    //    }
    //
    //    //
    //    // Display the amount of free space that was calculated.
    //    //
    //    UARTprintf(", %10uK bytes free\n", ulTotalSize * pFatFs->sects_clust / 2);
    //
    //    //
    //    // Made it to here, return with no errors.
    //    //
    //    return(0);
    //}
    //
    ////*****************************************************************************
    ////
    //// This function implements the "cd" command.  It takes an argument that
    //// specifies the directory to make the current working directory.  Path
    //// separators must use a forward slash "/".  The argument to cd can be one of
    //// the following:
    ////
    //// * root ("/")
    //// * a fully specified path ("/my/path/to/mydir")
    //// * a single directory name that is in the current directory ("mydir")
    //// * parent directory ("..")
    ////
    //// It does not understand relative paths, so don't try something like this:
    //// ("../my/new/path")
    ////
    //// Once the new directory is specified, it attempts to open the directory to
    //// make sure it exists.  If the new path is opened successfully, then the
    //// current working directory (cwd) is changed to the new path.
    ////
    ////*****************************************************************************
    //int
    //Cmd_cd(int argc, char *argv[])
    //{
    //    unsigned int uIdx;
    //    FRESULT fresult;
    //
    //    //
    //    // Do not attempt to do anything if there is not a drive attached.
    //    //
    //    if(g_eState != STATE_DEVICE_READY)
    //    {
    //        return(FR_NOT_READY);
    //    }
    //
    //    //
    //    // Copy the current working path into a temporary buffer so it can be
    //    // manipulated.
    //    //
    //    strcpy(g_cTmpBuf, g_cCwdBuf);
    //
    //    //
    //    // If the first character is /, then this is a fully specified path, and it
    //    // should just be used as-is.
    //    //
    //    if(argv[1][0] == '/')
    //    {
    //        //
    //        // Make sure the new path is not bigger than the cwd buffer.
    //        //
    //        if(strlen(argv[1]) + 1 > sizeof(g_cCwdBuf))
    //        {
    //            UARTprintf("Resulting path name is too long\n");
    //            return(0);
    //        }
    //
    //        //
    //        // If the new path name (in argv[1])  is not too long, then copy it
    //        // into the temporary buffer so it can be checked.
    //        //
    //        else
    //        {
    //            strncpy(g_cTmpBuf, argv[1], sizeof(g_cTmpBuf));
    //        }
    //    }
    //
    //    //
    //    // If the argument is .. then attempt to remove the lowest level on the
    //    // CWD.
    //    //
    //    else if(!strcmp(argv[1], ".."))
    //    {
    //        //
    //        // Get the index to the last character in the current path.
    //        //
    //        uIdx = strlen(g_cTmpBuf) - 1;
    //
    //        //
    //        // Back up from the end of the path name until a separator (/) is
    //        // found, or until we bump up to the start of the path.
    //        //
    //        while((g_cTmpBuf[uIdx] != '/') && (uIdx > 1))
    //        {
    //            //
    //            // Back up one character.
    //            //
    //            uIdx--;
    //        }
    //
    //        //
    //        // Now we are either at the lowest level separator in the current path,
    //        // or at the beginning of the string (root).  So set the new end of
    //        // string here, effectively removing that last part of the path.
    //        //
    //        g_cTmpBuf[uIdx] = 0;
    //    }
    //
    //    //
    //    // Otherwise this is just a normal path name from the current directory,
    //    // and it needs to be appended to the current path.
    //    //
    //    else
    //    {
    //        //
    //        // Test to make sure that when the new additional path is added on to
    //        // the current path, there is room in the buffer for the full new path.
    //        // It needs to include a new separator, and a trailing null character.
    //        //
    //        if(strlen(g_cTmpBuf) + strlen(argv[1]) + 1 + 1 > sizeof(g_cCwdBuf))
    //        {
    //            UARTprintf("Resulting path name is too long\n");
    //            return(0);
    //        }
    //
    //        //
    //        // The new path is okay, so add the separator and then append the new
    //        // directory to the path.
    //        //
    //        else
    //        {
    //            //
    //            // If not already at the root level, then append a /
    //            //
    //            if(strcmp(g_cTmpBuf, "/"))
    //            {
    //                strcat(g_cTmpBuf, "/");
    //            }
    //
    //            //
    //            // Append the new directory to the path.
    //            //
    //            strcat(g_cTmpBuf, argv[1]);
    //        }
    //    }
    //
    //    //
    //    // At this point, a candidate new directory path is in chTmpBuf.  Try to
    //    // open it to make sure it is valid.
    //    //
    //    fresult = f_opendir(&g_sDirObject, g_cTmpBuf);
    //
    //    //
    //    // If it can't be opened, then it is a bad path.  Inform user and return.
    //    //
    //    if(fresult != FR_OK)
    //    {
    //        UARTprintf("cd: %s\n", g_cTmpBuf);
    //        return(fresult);
    //    }
    //
    //    //
    //    // Otherwise, it is a valid new path, so copy it into the CWD.
    //    //
    //    else
    //    {
    //        strncpy(g_cCwdBuf, g_cTmpBuf, sizeof(g_cCwdBuf));
    //    }
    //
    //    //
    //    // Return success.
    //    //
    //    return(0);
    //}
    //
    ////*****************************************************************************
    ////
    //// This function implements the "pwd" command.  It simply prints the current
    //// working directory.
    ////
    ////*****************************************************************************
    //int
    //Cmd_pwd(int argc, char *argv[])
    //{
    //    //
    //    // Do not attempt to do anything if there is not a drive attached.
    //    //
    //    if(g_eState != STATE_DEVICE_READY)
    //    {
    //        return(FR_NOT_READY);
    //    }
    //
    //    //
    //    // Print the CWD to the console.
    //    //
    //    UARTprintf("%s\n", g_cCwdBuf);
    //
    //    //
    //    // Return success.
    //    //
    //    return(0);
    //}
    //
    ////*****************************************************************************
    ////
    //// This function implements the "cat" command.  It reads the contents of a file
    //// and prints it to the console.  This should only be used on text files.  If
    //// it is used on a binary file, then a bunch of garbage is likely to printed on
    //// the console.
    ////
    ////*****************************************************************************
    //int
    //Cmd_cat(int argc, char *argv[])
    //{
    //    FRESULT fresult;
    //    unsigned short usBytesRead;
    //
    //    //
    //    // Do not attempt to do anything if there is not a drive attached.
    //    //
    //    if(g_eState != STATE_DEVICE_READY)
    //    {
    //        return(FR_NOT_READY);
    //    }
    //
    //    //
    //    // First, check to make sure that the current path (CWD), plus the file
    //    // name, plus a separator and trailing null, will all fit in the temporary
    //    // buffer that will be used to hold the file name.  The file name must be
    //    // fully specified, with path, to FatFs.
    //    //
    //    if(strlen(g_cCwdBuf) + strlen(argv[1]) + 1 + 1 > sizeof(g_cTmpBuf))
    //    {
    //        UARTprintf("Resulting path name is too long\n");
    //        return(0);
    //    }
    //
    //    //
    //    // Copy the current path to the temporary buffer so it can be manipulated.
    //    //
    //    strcpy(g_cTmpBuf, g_cCwdBuf);
    //
    //    //
    //    // If not already at the root level, then append a separator.
    //    //
    //    if(strcmp("/", g_cCwdBuf))
    //    {
    //        strcat(g_cTmpBuf, "/");
    //    }
    //
    //    //
    //    // Now finally, append the file name to result in a fully specified file.
    //    //
    //    strcat(g_cTmpBuf, argv[1]);
    //
    //    //
    //    // Open the file for reading.
    //    //
    //    fresult = f_open(&g_sFileObject, g_cTmpBuf, FA_READ);
    //
    //    //
    //    // If there was some problem opening the file, then return an error.
    //    //
    //    if(fresult != FR_OK)
    //    {
    //        return(fresult);
    //    }
    //
    //    //
    //    // Enter a loop to repeatedly read data from the file and display it, until
    //    // the end of the file is reached.
    //    //
    //    do
    //    {
    //        //
    //        // Read a block of data from the file.  Read as much as can fit in the
    //        // temporary buffer, including a space for the trailing null.
    //        //
    //        fresult = f_read(&g_sFileObject, g_cTmpBuf, sizeof(g_cTmpBuf) - 1,
    //                         &usBytesRead);
    //
    //        //
    //        // If there was an error reading, then print a newline and return the
    //        // error to the user.
    //        //
    //        if(fresult != FR_OK)
    //        {
    //            UARTprintf("\n");
    //            return(fresult);
    //        }
    //
    //        //
    //        // Null terminate the last block that was read to make it a null
    //        // terminated string that can be used with printf.
    //        //
    //        g_cTmpBuf[usBytesRead] = 0;
    //
    //        //
    //        // Print the last chunk of the file that was received.
    //        //
    //        UARTprintf("%s", g_cTmpBuf);
    //
    //        //
    //        // Continue reading until less than the full number of bytes are read.
    //        // That means the end of the buffer was reached.
    //        //
    //    }
    //    while(usBytesRead == sizeof(g_cTmpBuf) - 1);
    //
    //    //
    //    // Return success.
    //    //
    //    return(0);
    //}
    //
    ////*****************************************************************************
    ////
    //// This function implements the "help" command.  It prints a simple list of the
    //// available commands with a brief description.
    ////
    ////*****************************************************************************
    //int
    //Cmd_help(int argc, char *argv[])
    //{
    //    tCmdLineEntry *pEntry;
    //
    //    //
    //    // Print some header text.
    //    //
    //    UARTprintf("\nAvailable commands\n");
    //    UARTprintf("------------------\n");
    //
    //    //
    //    // Point at the beginning of the command table.
    //    //
    //    pEntry = &g_psCmdTable[0];
    //
    //    //
    //    // Enter a loop to read each entry from the command table.  The end of the
    //    // table has been reached when the command name is NULL.
    //    //
    //    while(pEntry->pcCmd)
    //    {
    //        //
    //        // Print the command name and the brief description.
    //        //
    //        UARTprintf("%s%s\n", pEntry->pcCmd, pEntry->pcHelp);
    //
    //        //
    //        // Advance to the next entry in the table.
    //        //
    //        pEntry++;
    //    }
    //
    //    //
    //    // Return success.
    //    //
    //    return(0);
    //}
    //
    ////*****************************************************************************
    ////
    //// This is the table that holds the command names, implementing functions, and
    //// brief description.
    ////
    ////*****************************************************************************
    //tCmdLineEntry g_psCmdTable[] =
    //{
    //    { "help",   Cmd_help,      " : Display list of commands" },
    //    { "h",      Cmd_help,   "    : alias for help" },
    //    { "?",      Cmd_help,   "    : alias for help" },
    //    { "ls",     Cmd_ls,      "   : Display list of files" },
    //    { "chdir",  Cmd_cd,         ": Change directory" },
    //    { "cd",     Cmd_cd,      "   : alias for chdir" },
    //    { "pwd",    Cmd_pwd,      "  : Show current working directory" },
    //    { "cat",    Cmd_cat,      "  : Show contents of a text file" },
    //    { 0, 0, 0 }
    //};
    //
    ////*****************************************************************************
    ////
    //// This is the callback from the MSC driver.
    ////
    //// \param ulInstance is the driver instance which is needed when communicating
    //// with the driver.
    //// \param ulEvent is one of the events defined by the driver.
    //// \param pvData is a pointer to data passed into the initial call to register
    //// the callback.
    ////
    //// This function handles callback events from the MSC driver.  The only events
    //// currently handled are the MSC_EVENT_OPEN and MSC_EVENT_CLOSE.  This allows
    //// the main routine to know when an MSC device has been detected and
    //// enumerated and when an MSC device has been removed from the system.
    ////
    //// \return Returns \e true on success or \e false on failure.
    ////
    ////*****************************************************************************
    //void
    //MSCCallback(tUSBHMSCInstance *psMSCInstance, uint32_t ui32Event, void *pvEventData)
    //{
    //    //
    //    // Determine the event.
    //    //
    //    switch(ui32Event)
    //    {
    //        //
    //        // Called when the device driver has successfully enumerated an MSC
    //        // device.
    //        //
    //    case MSC_EVENT_OPEN:
    //    {
    //        //
    //        // Proceed to the enumeration state.
    //        //
    //        g_eState = STATE_DEVICE_ENUM;
    //        break;
    //    }
    //
    //    //
    //    // Called when the device driver has been unloaded due to error or
    //    // the device is no longer present.
    //    //
    //    case MSC_EVENT_CLOSE:
    //    {
    //        //
    //        // Go back to the "no device" state and wait for a new connection.
    //        //
    //        g_eState = STATE_NO_DEVICE;
    //
    //        break;
    //    }
    //
    //    default:
    //    {
    //        break;
    //    }
    //    }
    //}
    //
    ////*****************************************************************************
    ////
    //// This function reads a line of text from the UART console.  The USB host main
    //// function is called throughout this process to keep USB alive and well.
    ////
    ////*****************************************************************************
    //void
    //ReadLine(void)
    //{
    //    unsigned long ulIdx, ulPrompt;
    //    unsigned char ucChar;
    //    tState eStateCopy;
    //
    //    //
    //    // Start reading at the beginning of the command buffer and print a prompt.
    //    //
    //    g_cCmdBuf[0] = '\0';
    //    ulIdx = 0;
    //    ulPrompt = 1;
    //
    //    //
    //    // Loop forever.  This loop will be explicitly broken out of when the line
    //    // has been fully read.
    //    //
    //    while(1)
    //    {
    //
    //        //
    //        // See if a mass storage device has been enumerated.
    //        //
    //        if(g_eState == STATE_DEVICE_ENUM)
    //        {
    //            //
    //            // Take it easy on the Mass storage device if it is slow to
    //            // start up after connecting.
    //            //
    //            if(USBHMSCDriveReady(g_psMSCInstance) != 0)
    //            {
    //                //
    //                // Wait about 100ms before attempting to check if the
    //                // device is ready again.
    //                //
    //                SysCtlDelay(SysCtlClockGet(SYSTEM_CLOCK_SPEED)/30);
    //
    //                break;
    //            }
    //
    //            //
    //            // Reset the working directory to the root.
    //            //
    //            g_cCwdBuf[0] = '/';
    //            g_cCwdBuf[1] = '\0';
    //
    //            //
    //            // Attempt to open the directory.  Some drives take longer to
    //            // start up than others, and this may fail (even though the USB
    //            // device has enumerated) if it is still initializing.
    //            //
    //            f_mount(0, &g_sFatFs);
    //            if(f_opendir(&g_sDirObject, g_cCwdBuf) == FR_OK)
    //            {
    //                //
    //                // The drive is fully ready, so move to that state.
    //                //
    //                g_eState = STATE_DEVICE_READY;
    //            }
    //        }
    //
    //        //
    //        // See if the state has changed.  We make a copy of g_eUIState to
    //        // prevent a compiler warning about undefined order of volatile
    //        // accesses.
    //        //
    //        eStateCopy = g_eUIState;
    //        if(g_eState != eStateCopy)
    //        {
    //            //
    //            // Determine the new state.
    //            //
    //            switch(g_eState)
    //            {
    //                //
    //                // A previously connected device has been disconnected.
    //                //
    //            case STATE_NO_DEVICE:
    //            {
    //                if(g_eUIState == STATE_UNKNOWN_DEVICE)
    //                {
    //                    UARTprintf("\nUnknown device disconnected.\n");
    //                }
    //                else
    //                {
    //                    UARTprintf("\nMass storage device disconnected.\n");
    //                }
    //                ulPrompt = 1;
    //                break;
    //            }
    //
    //            //
    //            // A mass storage device is being enumerated.
    //            //
    //            case STATE_DEVICE_ENUM:
    //            {
    //                break;
    //            }
    //
    //            //
    //            // A mass storage device has been enumerated and initialized.
    //            //
    //            case STATE_DEVICE_READY:
    //            {
    //                UARTprintf("\nMass storage device connected.\n");
    //                ulPrompt = 1;
    //                break;
    //            }
    //
    //            //
    //            // An unknown device has been connected.
    //            //
    //            case STATE_UNKNOWN_DEVICE:
    //            {
    //                UARTprintf("\nUnknown device connected.\n");
    //                ulPrompt = 1;
    //                break;
    //            }
    //
    //            //
    //            // A power fault has occurred.
    //            //
    //            case STATE_POWER_FAULT:
    //            {
    //                UARTprintf("\nPower fault.\n");
    //                ulPrompt = 1;
    //                break;
    //            }
    //            }
    //
    //            //
    //            // Save the current state.
    //            //
    //            g_eUIState = g_eState;
    //        }
    //
    //        //
    //        // Print a prompt if necessary.
    //        //
    //        if(ulPrompt)
    //        {
    //            //
    //            // Print the prompt based on the current state.
    //            //
    //            if(g_eState == STATE_DEVICE_READY)
    //            {
    //                UARTprintf("%s> %s", g_cCwdBuf, g_cCmdBuf);
    //            }
    //            else if(g_eState == STATE_UNKNOWN_DEVICE)
    //            {
    //                UARTprintf("UNKNOWN> %s", g_cCmdBuf);
    //            }
    //            else
    //            {
    //                UARTprintf("NODEV> %s", g_cCmdBuf);
    //            }
    //
    //            //
    //            // The prompt no longer needs to be printed.
    //            //
    //            ulPrompt = 0;
    //        }
    //
    //        //
    //        // Loop while there are characters that have been received from the
    //        // UART.
    //        //
    //        while(UARTCharsAvail(UARTA_BASE))
    //        {
    //            //
    //            // Read the next character from the UART.
    //            //
    //            ucChar = UARTgetc();
    //
    //            //
    //            // See if this character is a backspace and there is at least one
    //            // character in the input line.
    //            //
    //            if((ucChar == '\b') && (ulIdx != 0))
    //            {
    //                //
    //                // Erase the last character from the input line.
    //                //
    //                UARTprintf("\b \b");
    //                ulIdx--;
    //                g_cCmdBuf[ulIdx] = '\0';
    //            }
    //
    //            //
    //            // See if this character is a newline.
    //            //
    //            else if((ucChar == '\r') || (ucChar == '\n'))
    //            {
    //                //
    //                // Return to the caller.
    //                //
    //                UARTprintf("\n");
    //                return;
    //            }
    //
    //            //
    //            // See if this character is an escape or Ctrl-U.
    //            //
    //            else if((ucChar == 0x1b) || (ucChar == 0x15))
    //            {
    //                //
    //                // Erase all characters in the input buffer.
    //                //
    //                while(ulIdx)
    //                {
    //                    UARTprintf("\b \b");
    //                    ulIdx--;
    //                }
    //                g_cCmdBuf[0] = '\0';
    //            }
    //
    //            //
    //            // See if this is a printable ASCII character.
    //            //
    //            else if((ucChar >= ' ') && (ucChar <= '~') &&
    //                    (ulIdx < (sizeof(g_cCmdBuf) - 1)))
    //            {
    //                //
    //                // Add this character to the input buffer.
    //                //
    //                g_cCmdBuf[ulIdx++] = ucChar;
    //                g_cCmdBuf[ulIdx] = '\0';
    //                UARTprintf("%c", (unsigned long)ucChar);
    //            }
    //        }
    //
    //        //
    //        // Tell the OTG state machine how much time has passed in
    //        // milliseconds since the last call.
    //        //
    //        USBHCDMain();
    ////        USBOTGMain(GetTickms());
    //    }
    //}
    
    //*****************************************************************************
    //
    // This is the callback from the USB HID mouse handler.
    //
    // \param psMsInstance is ignored by this function.
    // \param ui32Event is one of the valid events for a mouse device.
    // \param ui32MsgParam is defined by the event that occurs.
    // \param pvMsgData is a pointer to data that is defined by the event that
    // occurs.
    //
    // This function will be called to inform the application when a mouse has
    // been plugged in or removed and any time mouse movement or button pressed
    // is detected.
    //
    // \return None.
    //
    //*****************************************************************************
    void
    MouseCallback(tUSBHMouse *psMsInstance, uint32_t ui32Event,
                  uint32_t ui32MsgParam, void *pvMsgData)
    {
        int32_t i32DoUpdate;
        volatile char pcBuffer[20];
    
        //
        // Do an update unless there is no reason to.
        //
        i32DoUpdate = 1;
    
        switch(ui32Event)
        {
            //
            // Mouse button press detected.
            //
            case USBH_EVENT_HID_MS_PRESS:
            {
                //
                // Save the new button that was pressed.
                //
                g_ui32Buttons |= ui32MsgParam;
    
                break;
            }
    
            //
            // Mouse button release detected.
            //
            case USBH_EVENT_HID_MS_REL:
            {
                //
                // Remove the button from the pressed state.
                //
                g_ui32Buttons &= ~ui32MsgParam;
    
                break;
            }
    
            //
            // Mouse X movement detected.
            //
            case USBH_EVENT_HID_MS_X:
            {
            	//
            	// The mouse returns a 8 bit signed value...check to see if we
                // need to sign extend
            	//
            	if(ui32MsgParam & 0x80)
            		ui32MsgParam |= 0xFF00;
                //
                // Update the cursor X position.
                //
                g_i32CursorX += (int16_t)ui32MsgParam ;
    
                //
                // Cap the value to not cause an overflow.
                //
                if(g_i32CursorX > 9999)
                {
                    g_i32CursorX = 9999;
                }
    
                if(g_i32CursorX < -9999)
                {
                    g_i32CursorX = -9999;
                }
    
                break;
            }
    
            //
            // Mouse Y movement detected.
            //
            case USBH_EVENT_HID_MS_Y:
            {
            	//
            	// The mouse returns a 8 bit signed value...check to see if we
                // need to sign extend
            	//
            	if(ui32MsgParam & 0x80)
            		ui32MsgParam |= 0xFF00;
    
                //
                // Update the cursor Y position.
                //
                g_i32CursorY += (int16_t)ui32MsgParam;
    
                //
                // Cap the value to not cause an overflow.
                //
                if(g_i32CursorY > 9999)
                {
                    g_i32CursorY = 9999;
                }
    
                if(g_i32CursorY < -9999)
                {
                    g_i32CursorY = -9999;
                }
    
                break;
            }
            default:
            {
                //
                // No reason to update.
                //
                i32DoUpdate = 0;
    
                break;
            }
        }
    
        //
        // Display the current mouse position and button state if there was an
        // update.
        //
        if(i32DoUpdate)
        {
        	//
    		// Display the current mouse position and button state.
    		//
    		UARTprintf("\rPos: %l, %l  Buttons: %l%l%l    ", g_i32CursorX,
                       g_i32CursorY, g_ui32Buttons & 1, (g_ui32Buttons & 2) >> 1,
    				   (g_ui32Buttons & 4) >> 2);
    
    
        }
    }
    
    //*****************************************************************************
    //
    // Configure the UART and its pins.  This must be called before UARTprintf().
    //
    //*****************************************************************************
    void
    ConfigureUART(void)
    {
    
        //
        // Enable UART0
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_SCI1);
    
        //
        // Configure GPIO Pins for UART mode.
        //
    //    EALLOW;
    //    GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 1;
    //    GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;
    //    GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;
    //    GpioCtrlRegs.GPADIR.bit.GPIO28 = 0;
    //
    //    GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 1;
    //    GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;
    //    GpioCtrlRegs.GPADIR.bit.GPIO29 = 1;
    //    EDIS;
    
        EALLOW;
        GpioCtrlRegs.GPEGMUX1.bit.GPIO136 = 1;
        GpioCtrlRegs.GPEMUX1.bit.GPIO136 = 2;
        GpioCtrlRegs.GPEPUD.bit.GPIO136 = 0;
        GpioCtrlRegs.GPEQSEL1.bit.GPIO136 = 3;
        GpioCtrlRegs.GPEDIR.bit.GPIO136 = 0;
    
        GpioCtrlRegs.GPEGMUX1.bit.GPIO135 = 1;
        GpioCtrlRegs.GPEMUX1.bit.GPIO135 = 2;
        GpioCtrlRegs.GPEPUD.bit.GPIO135 = 0;
        GpioCtrlRegs.GPEDIR.bit.GPIO135 = 1;
        EDIS;
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
    //    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, SysCtlLowSpeedClockGet(SYSTEM_CLOCK_SPEED));
    
    }
    
    //*****************************************************************************
    //
    // This is the main loop that runs the application.
    //
    //*****************************************************************************
    int
    main(void)
    {
        int iStatus;
    
    #ifdef _FLASH
    // Copy time critical code and Flash setup code to RAM
    // This includes the following functions:  InitFlash();
    // The  RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart
    // symbols are created by the linker. Refer to the device .cmd file.
        memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    #endif
    
        //
        // Set the clocking to run from the PLL at 50MHz
        //
        SysCtlClockSet(SYSCTL_OSCSRC_XTAL | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(20) |
                       SYSCTL_SYSDIV(2));
        SysCtlAuxClockSet(SYSCTL_OSCSRC_XTAL | SYSCTL_PLL_ENABLE |
                          SYSCTL_IMULT(12) | SYSCTL_SYSDIV(4));
    
    
    #ifdef _FLASH
    // Call Flash Initialization to setup flash waitstates
    // This function must reside in RAM
        InitFlash();
    #endif
    
        //
        // Initially wait for device connection.
        //
        g_eState = STATE_NO_DEVICE;
        g_eUIState = STATE_NO_DEVICE;
    
        //
        // Initialize interrupt controller and vector table
        //
        InitPieCtrl();
        InitPieVectTable();
    
        //
        // Configure SysTick for a 100Hz interrupt.
        //
        SysTickInit();
        SysTickPeriodSet(SysCtlClockGet(SYSTEM_CLOCK_SPEED) / TICKS_PER_SECOND);
        SysTickIntRegister(SysTickIntHandler);
        SysTickEnable();
        SysTickIntEnable();
    
        //
        // Enable Clocking to the USB controller.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
    
        //
        // Configure the required pins for USB operation.
        //
        USBGPIOEnable();
        USBIntRegister(USB0_BASE, f28x_USB0HostIntHandler);
    
        //
        // Configure UART0 for debug output.
        //
        ConfigureUART();
        UARTprintf("\033[2JHost Mouse Application\n");
    
        //
        // Initialize the USB stack mode and pass in a mode callback.
        //
        USBStackModeSet(0, eUSBModeForceHost, ModeCallback);
    
        //
        // Register the host class drivers.
        //
        USBHCDRegisterDrivers(0, g_ppHostClassDrivers[0], 2);
        USBHCDRegisterDrivers(1, g_ppHostClassDrivers[1], 2);
    
        //
        // Initialized the cursor.
        //
        g_ui32Buttons = 0;
        g_i32CursorX = 0;
        g_i32CursorY = 0;
    
        //
        // Open an instance of the mouse driver.  The mouse does not need
        // to be present at this time, this just saves a place for it and allows
        // the applications to be notified when a mouse is present.
        //
        g_psMouseInstance =
            USBHMouseOpen(MouseCallback, g_pui8Buffer, MOUSE_MEMORY_SIZE);
    
        //
        // Open an instance of the mass storage class driver.
        //
    //    g_psMSCInstance = USBHMSCDriveOpen(0, (tUSBHMSCCallback)MSCCallback);
    
        //
        // Initialize the power configuration. This sets the power enable signal
        // to be active high and does not enable the power fault.
        //
        USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);
    
        //
        // Initialize the USB controller for OTG operation with a 2ms polling
        // rate.
        //
        USBHCDInit(0, g_pui8HCDPool, HCD_MEMORY_SIZE);
    
        IntMasterEnable();
    
        //
        // Initialize the file system.
        //
        f_mount(0, &g_sFatFs);
    
        //
        // The main loop for the application.
        //
        while(1)
        {
            //
            // Tell the OTG state machine how much time has passed in
            // milliseconds since the last call.
            //
            USBHCDMain();
    
            switch(g_eState)
            {
                //
                // This state is entered when the mouse is first detected.
                //
                case STATE_DEVICE_INIT:
                {
                    //
                    // Initialize the newly connected mouse.
                    //
                    USBHMouseInit(g_psMouseInstance);
    
    //                //
    //                // Enter an infinite loop for reading and processing commands from the
    //                // user.
    //                //
    //                while(1)
    //                {
    //                    //
    //                    // Get a line of text from the user.
    //                    //
    //                    ReadLine();
    //                    if(g_cCmdBuf[0] == '\0')
    //                    {
    //                        continue;
    //                    }
    //
    //                    //
    //                    // Pass the line from the user to the command processor.
    //                    // It will be parsed and valid commands executed.
    //                    //
    //                    iStatus = CmdLineProcess(g_cCmdBuf);
    //
    //                    //
    //                    // Handle the case of bad command.
    //                    //
    //                    if(iStatus == CMDLINE_BAD_CMD)
    //                    {
    //                        UARTprintf("Bad command!\n");
    //                    }
    //
    //                    //
    //                    // Handle the case of too many arguments.
    //                    //
    //                    else if(iStatus == CMDLINE_TOO_MANY_ARGS)
    //                    {
    //                        UARTprintf("Too many arguments for command processor!\n");
    //                    }
    //
    //                    //
    //                    // Otherwise the command was executed.  Print the error
    //                    // code if one was returned.
    //                    //
    //                    else if(iStatus != 0)
    //                    {
    //                        UARTprintf("Command returned error code %s\n",
    //                                   StringFromFresult((FRESULT)iStatus));
    //                    }
    //                }
    
                    //
                    // Proceed to the mouse connected state.
                    //
                    g_eState = STATE_DEVICE_READY;
    
                    break;
                }
    
                case STATE_DEVICE_READY:
                {
                    //
                    // Nothing is currently done in the main loop when the mouse
                    // is connected.
                    //
                    break;
                }
    
                case STATE_NO_DEVICE:
                {
                    //
                    // The mouse is not connected so nothing needs to be done here.
                    //
                    break;
                }
    
                default:
                {
                    break;
                }
            }
        }
    }
    
    //
    // End of file
    //
    

  • Hi Harshmeet,

    Would you help updating the status of this issue, please?

    Sincerely,

    LB Shi

  • Hi Lianbing,

    I am trying to run the file you sent but i am also facing some issue.

    I will get back to you by tomorrow positively.

    Thanks and Regards
    Harshmeet Singh
  • Hi Lianbing,

    I am also facing the same issue. I will have to need to check with Sal on this issue.

    Regards
    Harshmeet
  • Hi,

    Did you find anything from your end?


    Regards

    Harshmeet

  • Hi Harshmeet,

    Till now, we haven't made any progress for it.

    Sincerely,

    LB Shi

  • Lianbing,

    Wanted to check back in from the TI side to see if there was any update or further action needed from the TI side.

    Best,

    Matthew

  • Hi Matthew,

    Thanks for your great support. We'd like to solve the issue soonest since the USB hub can't be used on our board.

    Sincerely,

    LB Shi

  • Hi Lianbing,

    The source file you share earlier will have the issue as it is not meant for HUB Connections.

    There are USB Hub Init and Stack functions to be used for HUB Init and for the USB to enumerate.

    We currently have no example to show. But i have been trying to make a sequence to help you.

    Apologies for the delay.

    Thanks and Regards

    Harshmeet

  • Hi Harshmeet,

    Thanks for your great support. We will try it once receive your sequence.

    Sincerely,

    LB SHi

  • Hi Lianbing,

    The points I have taken care while making a hub example:

    You need to call USBHMouseOpen to open instance of Mouse. Then call the USBHHubOpen to open the Hub Instance.

    The Hub should be initialized before any host is connected and them connect the host device.

    Then you need to constantly check if a device is connected.

    I am making an example for this. Hope the above sequence is helpful for you.

    Thanks and Regards

    Harshmeet

  • Hi Harshmeet,

    Thanks.

    We will try it and feedback to you soonest.

    Sincerely,

    LB Shi

  • Hi Lianbing,

    I have provided the solution over email.

    Please check and let us know. I have got the hub connections working.

    Regards
    Harshmeet

  • Hi Lianbing,

    What is the issue you are facing?

    Regards

    Harshmeet

  • Hi Harshmeet,

     

    Thanks for your great support.

     

    We have tried the sequence you provided and USB HUB example code for 2838x. The USB hub can be enumerated. However, the devices being

    connected to the USB hub can’t be enumerated.

     

    Attachment is showing the detail information and the USB HUB example code for 2838x. Please take a look.

     

    Sincerely,

     

    LB Shi

    USB HUB Files.zip

     28377d_usb_hub_Enumerate_Device_Issue.pdf

  • Hi Lianbing,

    Some questions:

    1. Why is it printing USB Mouse Application?

    The example I sent you should print "USB Host Hub Example" only, while running it before connecting any device.

    2. Are you running in Debug Mode?

    2. Is it getting stuck in an ESTOP?

    Some points here for running this example:

    1. Please build the usblib.lib and driverlib.lib in Release mode and make sure the correct ones are linked to the examples.

    2. First, connect the Hub and wait for the "USB Host Hub Example" to be displayed.

    3. Then connect a Host Device and wait for "Host Mouse is connected on Hub Port "

    4. Replace the usbhhub.c updates in the usblib file before building the USB library.

    Please use the libraries in Release configuration and link it to the example.

    It has been working for me and I am expecting the same for you.

    Please do try the above and let me know.

    Thanks and Regards

    Harshmeet Singh

  • Hi Harshmeet,

    We will try it and feed back the result to you soonest.

    Sincerely,

    LB Shi

  • Hi Harshmeet,

    We tried it as per the procedure you provided. "USB Host Hub Example" displayed as expected.

    However, an error occurred when acquired DevIndex.

    Attachment is showing the detail information. Please take a look.

    Sincerely,

    LB Shi

    28377D_usb_DevIndex_Error.pdf

  • Hi Lianbing,

    From the error, looks like the hub detected that a device was connected and tried to enumerate the device 3 times  but did not succeed. In this case, the enumeration was cancelled and hence you see the error state.

    The example is working fine for me.

    Can you let us know the system clock speed and the value getting assigned to "g_ui32Tickms" variable in the USBHCDInit function in usbhostenum.c file?

    Thanks & Regards

    Siddharth

  • Hi Siddharth,

    Here is the clock associated setting. Please take a look.

    In addition, The example that is working fine is running on TMS320F28377, or TMS320F3202828x?


    (1)    SysCtlClockSet(SYSCTL_OSCSRC_XTAL | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(20) |

                           SYSCTL_SYSDIV(2));
            SysCtlAuxClockSet(SYSCTL_OSCSRC_XTAL | SYSCTL_PLL_ENABLE |
                           SYSCTL_IMULT(12) | SYSCTL_SYSDIV(4));
    (2)    SysTickPeriodSet(SysCtlClockGet(SYSTEM_CLOCK_SPEED) / TICKS_PER_SECOND);

            SysCtlClockGet(SYSTEM_CLOCK_SPEED) = 200 000 000

    (3)    #define SYSTEM_CLOCK_SPEED      20000000

            g_ui32Tickms = MAP_SysCtlClockGet(SYSTEM_CLOCK_SPEED) / 3000;

    Sincerely,

    LB Shi

  • The example Siddarth was using was for f2837x.

    Can you make sure AuxCLK is 60MHz by outputing it to XCLKOUT and using an oscilloscope.

    sal