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.

TM4C123gxl Launchpad mouse host problem

I am trying the board to act as a usb host four standard usb mouse I wrote two file looking some examples but it gives error and interrupt occurs. WHY? Two files are exist first the main and the other is module. The required files are included in library in project and building the project does not give any error but gives warning since some vars are defined but not used.

Main file

#include <stdbool.h>
#include <stdint.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/udma.h"
#include "driverlib/uart.h"
#include "usblib/usblib.h"
#include "usblib/usbhid.h"
#include "usblib/host/usbhost.h"
#include "usblib/host/usbhhid.h"
#include "drivers/buttons.h"
#include "usbhhidgamepad.h"
#include "utils/uartstdio.h"
//*****************************************************************************
//
// The size of the host controller's memory pool in bytes.
//
//*****************************************************************************
#define HCD_MEMORY_SIZE         128

//*****************************************************************************
//
// Structure to hold the status of the attached mouse.
//
//*****************************************************************************
typedef struct
{
    //
    // Holds if there is a device connected to this port.
    //
    bool bConnected;

    //
    // Holds if the mouse state has been updated.
    //
    bool bUpdate;

    //
    // The instance data for the device if bConnected is true.
    //
    uint32_t ui32Instance;

    //
    // The mouse button state.
    //
    uint32_t ui32Buttons;

    //
    // The mouse X position.
    //
    int32_t i32XPos;

    //
    // The mouse Y position.
    //
    int32_t i32YPos;
}
tMouseStatus;

//*****************************************************************************
//
// The memory pool to provide to the Host controller driver.
//
//*****************************************************************************
unsigned char g_pHCDPool[HCD_MEMORY_SIZE];

//*****************************************************************************
//
// The global application status structure.
//
//*****************************************************************************
tMouseStatus g_sStatus;

//*****************************************************************************
//
// The memory pool to provide to the Host controller driver.
//
//*****************************************************************************
uint8_t g_pui8HCDPool[HCD_MEMORY_SIZE * MAX_USB_DEVICES];

//*****************************************************************************
//
// 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 HID class is loaded.
//
//*****************************************************************************
static tUSBHostClassDriver const * const g_ppHostClassDrivers[] =
{
    &g_sUSBHIDClassDriver,
    &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_psMouse;

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//*****************************************************************************
//
// This enumerated type is used to hold the states of the mouse.
//
//*****************************************************************************
enum
{
    //
    // No device is present.
    //
    eStateNoDevice,

    //
    // Mouse has been detected and needs to be initialized in the main loop.
    //
    eStateMouseInit,

    //
    // Mouse is connected and waiting for events.
    //
    eStateMouseConnected,
}
g_iMouseState;


//*****************************************************************************
//
// Configure the UART and its pins.  This must be called before UARTprintf().
//
//*****************************************************************************
void
ConfigureUART(void)
{
    //
    // Enable the GPIO Peripheral used by the UART.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable UART0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure GPIO Pins for UART mode.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // 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, 16000000);
}

//*****************************************************************************
//
// This is the callback from the USB HID mouse handler.
//
// pvCBData is ignored by this function.
// ui32Event is one of the valid events for a mouse device.
// ui32MsgParam is defined by the event that occurs.
// 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 a mouse movement or button pressed
// has occurred.
//
// This function will return 0.
//
//*****************************************************************************
void
MouseCallback(tUSBHMouse *psMouse, uint32_t ui32Event, uint32_t ui32MsgParam,
              void *pvMsgData)
{
    //
    // Start with the assumption that the data on the serial port will need
    // updating.
    //
    g_sStatus.bUpdate = true;

    switch(ui32Event)
    {
        //
        // New mouse detected.
        //
        case USB_EVENT_CONNECTED:
        {
            //
            // Proceed to the eStateMouseInit state so that the main loop
            // can finish initializing the mouse since USBHMouseInit() cannot
            // be called from within a callback.
            //
            g_iMouseState = eStateMouseInit;

            //
            // Indicate that the mouse has been detected.
            //
            UARTprintf("\nMouse Connected\n");

            break;
        }

        //
        // Mouse has been unplugged.
        //
        case USB_EVENT_DISCONNECTED:
        {
            //
            // Change the state so that the main loop knows that a device is no
            // longer present.
            //
            g_iMouseState = eStateNoDevice;

            //
            // Need to clear out any held buttons.
            //
            g_sStatus.ui32Buttons = 0;

            //
            // Indicate that the device was disconnected.
            //
            UARTprintf("\nMouse disconnected\n");

            //
            // There shouldn't be any updates from a disconnected mouse.
            //
            g_sStatus.bUpdate = false;

            break;
        }

        //
        // New button press detected.
        //
        case USBH_EVENT_HID_MS_PRESS:
        {
            //
            // Save the new button that was pressed.
            //
            g_sStatus.ui32Buttons |= ui32MsgParam;

            break;
        }

        //
        // A button was released on a HID mouse.
        //
        case USBH_EVENT_HID_MS_REL:
        {
            //
            // Remove the button from the pressed state.
            //
            g_sStatus.ui32Buttons &= ~ui32MsgParam;

            break;
        }

        //
        // The HID mouse detected movement in the X direction.
        //
        case USBH_EVENT_HID_MS_X:
        {
            //
            // Update the cursor X position.
            //
            g_sStatus.i32XPos += (int8_t) ui32MsgParam;

            break;
        }

        //
        // The HID mouse detected movement in the Y direction.
        //
        case USBH_EVENT_HID_MS_Y:
        {
            //
            // Update the cursor Y position.
            //
            g_sStatus.i32YPos += (int8_t) ui32MsgParam;

            break;
        }
        default:
        {
            //
            // This was an event that we don't recognize, so there is no reason
            // to update the UART output.
            //
            g_sStatus.bUpdate = false;

            break;
        }
    }

    //
    // If we have an update for the UART, send it now.
    //
    if(g_sStatus.bUpdate == true)
    {
        //
        // Print an update to the UART showing the current mouse position and
        // the state of all three buttons.
        //
        UARTprintf("\rPos: %d, %d  Buttons: %d%d%d    ",
                   g_sStatus.i32XPos, g_sStatus.i32YPos,
                   g_sStatus.ui32Buttons & 1,
                   (g_sStatus.ui32Buttons & 2) >> 1,
                   (g_sStatus.ui32Buttons & 4) >> 2);
    }
}

//*****************************************************************************
//
// The main routine for handling the USB mouse.
//
//*****************************************************************************
void
MouseMain(void)
{
    switch(g_iMouseState)
    {
        //
        // This state is entered when they mouse is first detected.
        //
        case eStateMouseInit:
        {
            //
            // Initialized the newly connected mouse.
            //
            USBHMouseInit(g_psMouse);

            //
            // Proceed to the mouse connected state.
            //
            g_iMouseState = eStateMouseConnected;

            break;
        }
        case eStateMouseConnected:
        {
            //
            // Nothing is currently done on mouse connect.
            //
            break;
        }
        default:
        {
            break;
        }
    }
}



//*****************************************************************************
//
// 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)
    {
        case USB_EVENT_UNKNOWN_CONNECTED:
        case USB_EVENT_CONNECTED:
        {
            //
            // Save the device instance data.
            //
            g_sStatus.ui32Instance = pEventInfo->ui32Instance;
            g_sStatus.bConnected = true;

            break;
        }
        //
        // A device has been unplugged.
        //
        case USB_EVENT_DISCONNECTED:
        {
            //
            // Device is no longer connected.
            //
            g_sStatus.bConnected = false;

            break;
        }
        default:
        {
            break;
        }
    }
}



*/

//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{

    uint32_t  ui32PLLRate;

    //
    // Set the application to run at 120 MHz with a PLL frequency of 480 MHz.
    //
    //ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
	
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    //
    // Set the part pin out appropriately for this device.
    //
    //PinoutSet(false, true);
    ConfigureUART();
    //
    // Configure UART0 for 115,200 baud serial data output.
    //
    //UARTStdioConfig(0, 115200, ui32SysClock);

    //
    // Print a welcome message
    //
    UARTprintf("\033[2J\033[H");
    UARTprintf("USB Host Mouse Example\n");
    UARTprintf("Waiting for device....\n");

    //
    // Save the PLL rate used by this application.
    //
    ui32PLLRate = 480000000;

    //
    // Initialize the connection status.
    //
    g_sStatus.bConnected = false;
    g_sStatus.ui32Buttons = 0;

    //
    // Enable Clocking to the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Initialize the USB stack mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeHost, 0);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Open an instance of the mouse driver.  The mouse does not need
    // to be present at this time, this just save a place for it and allows
    // the applications to be notified when a mouse is present.
    //
    g_psMouse = USBHMouseOpen(MouseCallback, 0, 0);

    //
    // 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);

    //
    // Tell the USB library the CPU clock and the PLL frequency.  This is a
    // new requirement for TM4C129 devices.
    //
    //USBHCDFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock);
    //USBHCDFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Initialize the USB controller for Host mode.
    //
    USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool));
	

    //
    // The main loop for the application.
    //
    while(1)
    {
      	
        //
        // Call the USB library to let non-interrupt code run.
        //
        USBHCDMain();

        //
        // Call the mouse and mass storage main routines.
        //
        MouseMain();
    }
}



usbhhidgamepad.c file


#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_types.h"
#include "usblib/usblib.h"
#include "usblib/host/usbhost.h"
#include "usblib/usbhid.h"
#include "usblib/host/usbhhid.h"
#include "usbhhidgamepad.h"


//*****************************************************************************
//
// Prototypes for local functions.
//
//*****************************************************************************
static uint32_t USBHMouseCallback(void *pvMouse, uint32_t ui32Event,
                                  uint32_t ui32MsgParam, void *pvMsgData);

//*****************************************************************************
//
// The size of a USB mouse report.
//
//*****************************************************************************
#define USBHMS_REPORT_SIZE      4

//*****************************************************************************
//
// These are the flags for the tUSBHMouse.ui32HIDFlags member variable.
//
//*****************************************************************************
#define USBHMS_DEVICE_PRESENT   0x00000001

//*****************************************************************************
//
// This is the structure definition for a mouse device instance.
//
//*****************************************************************************
struct tUSBHMouse
{
    //
    // Global flags for an instance of a mouse.
    //
    uint32_t ui32HIDFlags;

    //
    // The applications registered callback.
    //
    tUSBHIDMouseCallback pfnCallback;

    //
    // The current state of the buttons.
    //
    uint8_t ui8Buttons;

    //
    // This is a local buffer to hold the current HID report that comes up
    // from the HID driver layer.
    //
    uint8_t pui8Buffer[USBHMS_REPORT_SIZE];

    //
    // Heap data for the mouse currently used to read the HID Report
    // Descriptor.
    //
    uint8_t *pui8Heap;

    //
    // Size of the heap in bytes.
    //
    uint32_t ui32HeapSize;

    //
    // This is the instance value for the HID device that will be used for the
    // mouse.
    //
    tHIDInstance *psHIDInstance;
};

//*****************************************************************************
//
// This is the per instance information for a mouse device.
//
//*****************************************************************************
static tUSBHMouse g_sUSBHMouse =
{
    0
};


//*****************************************************************************
//
//! This function is used open an instance of a mouse.
//!
//! \param pfnCallback is the callback function to call when new events occur
//! with the mouse returned.
//! \param pui8Buffer is the memory used by the driver to interact with the
//! USB mouse.
//! \param ui32Size is the size of the buffer provided by \e pui8Buffer.
//!
//! This function is used to open an instance of the mouse.  The value
//! returned from this function should be used as the instance identifier for
//! all other USBHMouse calls.  The \e pui8Buffer memory buffer is used to
//! access the mouse.  The buffer size required is at least enough to hold
//! a normal report descriptor for the device.
//!
//! \return Returns the instance identifier for the mouse that is attached.
//! If there is no mouse present this will return 0.
//
//*****************************************************************************
tUSBHMouse *
USBHMouseOpen(tUSBHIDMouseCallback pfnCallback, uint8_t *pui8Buffer,
              uint32_t ui32Size)
{
    //
    // Save the callback and data pointers.
    //
    g_sUSBHMouse.pfnCallback = pfnCallback;

    //
    // Save the instance pointer for the HID device that was opened.
    //
    g_sUSBHMouse.psHIDInstance = USBHHIDOpen(eUSBHHIDClassMouse,
                                             USBHMouseCallback,
                                             (void *)&g_sUSBHMouse);

    //
    // Save the heap buffer and size.
    //
    g_sUSBHMouse.pui8Heap = pui8Buffer;
    g_sUSBHMouse.ui32HeapSize = ui32Size;

    return(&g_sUSBHMouse);
}

//*****************************************************************************
//
//! This function is used close an instance of a mouse.
//!
//! \param psMsInstance is the instance value for this mouse.
//!
//! This function is used to close an instance of the mouse that was opened
//! with a call to USBHMouseOpen().  The \e psMsInstance value is the value
//! that was returned when the application called USBHMouseOpen().
//!
//! \return Returns 0.
//
//*****************************************************************************
uint32_t
USBHMouseClose(tUSBHMouse *psMsInstance)
{
    //
    // Reset the callback to null.
    //
    psMsInstance->pfnCallback = 0;

    //
    // Call the HID driver layer to close out this instance.
    //
    USBHHIDClose(psMsInstance->psHIDInstance);

    return(0);
}

//*****************************************************************************
//
//! This function is used to initialize a mouse interface after a mouse has
//! been detected.
//!
//! \param psMsInstance is the instance value for this mouse.
//!
//! This function should be called after receiving a \b USB_EVENT_CONNECTED
//! event in the callback function provided by USBHMouseOpen(), however it
//! should only be called outside of the callback function.  This will
//! initialize the mouse interface and determine how it reports events to the
//! USB host controller.  The \e psMsInstance value is the value that was
//! returned when the application called USBHMouseOpen().  This function only
//! needs to be called once per connection event but it should be called every
//! time a \b USB_EVENT_CONNECTED event occurs.
//!
//! \return Non-zero values should be assumed to indicate an error condition.
//
//*****************************************************************************
uint32_t
USBHMouseInit(tUSBHMouse *psMsInstance)
{
    //
    // Set the initial rate to only update on mouse state changes.
    //
    USBHHIDSetIdle(psMsInstance->psHIDInstance, 0, 0);

    //
    // Read out the Report Descriptor from the mouse and parse it for
    // the format of the reports coming back from the mouse.
    //
    USBHHIDGetReportDescriptor(psMsInstance->psHIDInstance,
                               psMsInstance->pui8Heap,
                               psMsInstance->ui32HeapSize);

    //
    // Set the mouse to boot protocol.
    //
    USBHHIDSetProtocol(psMsInstance->psHIDInstance, 1);

    return(0);
}

//*****************************************************************************
//
// This function handles updating the state of the mouse buttons and axis.
//
// \param psMsInstance is the pointer to an instance of the mouse data.
//
// This function will check for updates to buttons or X/Y movements and send
// callbacks to the mouse callback function.
//
// \return None.
//
//*****************************************************************************
static void
UpdateMouseState(tUSBHMouse *psMsInstance)
{
    uint32_t ui32Button;

    if(psMsInstance->pui8Buffer[0] != psMsInstance->ui8Buttons)
    {
        for(ui32Button = 1; ui32Button <= 0x4; ui32Button <<= 1)
        {
            if(((psMsInstance->pui8Buffer[0] & ui32Button) != 0) &&
               ((psMsInstance->ui8Buttons & ui32Button) == 0))
            {
                //
                // Send the mouse button press notification to the application.
                //
                psMsInstance->pfnCallback(0, USBH_EVENT_HID_MS_PRESS,
                                          ui32Button, 0);
            }
            if(((psMsInstance->pui8Buffer[0] & ui32Button) == 0) &&
               ((psMsInstance->ui8Buttons & ui32Button) != 0))
            {
                //
                // Send the mouse button release notification to the
                // application.
                //
                psMsInstance->pfnCallback(0, USBH_EVENT_HID_MS_REL,
                                         ui32Button, 0);
            }
        }

        //
        // Save the new state.
        //
        psMsInstance->ui8Buttons = psMsInstance->pui8Buffer[0];
    }

    if(psMsInstance->pui8Buffer[1] != 0)
    {
        //
        // Send the mouse button release notification to the
        // application.
        //
        psMsInstance->pfnCallback(0, USBH_EVENT_HID_MS_X,
                                  (uint32_t)psMsInstance->pui8Buffer[1], 0);
    }

    if(psMsInstance->pui8Buffer[2] != 0)
    {
        //
        // Send the mouse button release notification to the
        // application.
        //
        psMsInstance->pfnCallback(0, USBH_EVENT_HID_MS_Y,
                                  (uint32_t)psMsInstance->pui8Buffer[2], 0);
    }
}

//*****************************************************************************
//
//! This function handles event callbacks from the USB HID driver layer.
//!
//! \param pvMouse is the pointer that was passed in to the USBHHIDOpen()
//! call.
//! \param ui32Event is the event that has been passed up from the HID driver.
//! \param ui32MsgParam has meaning related to the \e ui32Event that occurred.
//! \param pvMsgData has meaning related to the \e ui32Event that occurred.
//!
//! This function will receive all event updates from the HID driver layer.
//! The mouse driver itself will mostly be concerned with report callbacks
//! from the HID driver layer and parsing them into keystrokes for the
//! application that has registered for callbacks with the USBHMouseOpen()
//! call.
//!
//! \return Non-zero values should be assumed to indicate an error condition.
//
//*****************************************************************************
uint32_t
USBHMouseCallback(void *pvMouse, uint32_t ui32Event,
                  uint32_t ui32MsgParam, void *pvMsgData)
{
    tUSBHMouse *psMsInstance;

    //
    // Recover the pointer to the instance data.
    //
    psMsInstance = (tUSBHMouse *)pvMouse;

    switch(ui32Event)
    {
        //
        // New mouse has been connected so notify the application.
        //
        case USB_EVENT_CONNECTED:
        {
            //
            // Remember that a mouse is present.
            //
            psMsInstance->ui32HIDFlags |= USBHMS_DEVICE_PRESENT;

            //
            // Notify the application that a new mouse was connected.
            //
            psMsInstance->pfnCallback(0, ui32Event, ui32MsgParam, pvMsgData);

            break;
        }
        case USB_EVENT_DISCONNECTED:
        {
            //
            // No mouse is present.
            //
            psMsInstance->ui32HIDFlags &= ~USBHMS_DEVICE_PRESENT;

            //
            // Notify the application that the mouse was disconnected.
            //
            psMsInstance->pfnCallback(0, ui32Event, ui32MsgParam, pvMsgData);

            break;
        }
        case USB_EVENT_RX_AVAILABLE:
        {
            //
            // New mouse report structure was received.
            //
            USBHHIDGetReport(psMsInstance->psHIDInstance, 0,
                             psMsInstance->pui8Buffer, USBHMS_REPORT_SIZE);

            //
            // Update the current state of the mouse and notify the application
            // of any changes.
            //
            UpdateMouseState(psMsInstance);

            break;
        }
    }
    return(0);
}

//*****************************************************************************
//
//! This function forwards an LPM request for a device to enter L1 sleep state.
//!
//! \param psMsInstance is the HID keyboard instance that was returned
//! from the call to USBHMouseOpen().
//!
//! This function forwards a request from an application to the HID device
//! class to request that a device enter the LPM L1 sleep state.  The
//! caller must check the return value to see if the request can be
//! attempted at this time.  If another LPM transaction is busy on this or
//! another device, then this function returns \b USBHCD_LPM_PENDING.  If
//! the LPM request was scheduled to be sent the function returns
//! \b USBHCD_LPM_AVAIL.  The caller should check the USBHCDLPMStatus()
//! function to determine if the request completed successfully or if there
//! was an error.
//!
//! \return This function returns the following values:
//! - \b USBHCD_LPM_AVAIL - The transition to L1 state is scheduled to be sent.
//! - \b USBHCD_LPM_PENDING - There is already an LPM request pending.
//
//*****************************************************************************
uint32_t
USBHMouseLPMSleep(tUSBHMouse *psMsInstance)
{
    //
    // Call the HID function to send the sleep command.
    //
    return(USBHHIDLPMSleep(psMsInstance->psHIDInstance));
}

//*****************************************************************************
//
//! This function returns the current status of an LPM request.
//!
//! \param psMsInstance is the HID keyboard instance that was returned
//! from the call to USBHMouseOpen().
//!
//! This function returns the current status of LPM requests for a given
//! device.  This is called to determine if a previous request completed
//! successfully or if there was an error.
//!
//! \return This function returns the following values:
//! - \b USBHCD_LPM_AVAIL - There are no pending LPM requests on this specific
//!   device or the last request completed successfully.
//! - \b USBHCD_LPM_ERROR - The last LPM request for this device did not
//!   complete successfully.
//! - \b USBHCD_LPM_PENDING - The last LPM request has not completed.
//
//*****************************************************************************
uint32_t
USBHMouseLPMStatus(tUSBHMouse *psMsInstance)
{
    //
    // Call the HID function to get the current LPM status.
    //
    return(USBHHIDLPMStatus(psMsInstance->psHIDInstance));
}

//*****************************************************************************
//
//! @}
//
//*****************************************************************************

  • Also I connect the VCC pin of female usb to PB1 and GND to GND. D- and D+ to test probes behind the micro usb b on board. Is this right. Do I need takeing the USBEPEN or something like that into acount. 

    Thanks.

  • Hi,

        Post the error message here.

       

    Arden Kuyumcu said:
    #include "usbhhidgamepad.h"

        Is this the file? Did you put include guards at this header file. Attach the .h file in this post.

    - kel  

  • That header file is also included and the source code of that header file is the seconde piece of the code in my post and I wrote the file name as usbhidgamepad.c to indicate wihcih file is in which file.

    I dont know about NMI I'll look for it.

    I am using IAR workbench and dont have any compling issue. It goes infinite loop and if there is any example for usb host use for this board. I will be appraciate to see it. I am not sure hot to connect pin to my female usb input pins to the board to detect usb connection or removal.

    It can be said I am new in embedded and electronics so some of the datasheets are not clear enough for me about some concepts.

    //*****************************************************************************
    //
    // usbhhidgamepad.h - This file holds the application interfaces for USB
    // joy devices.
    //
    // Copyright (c) 2008-2012 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    // 
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    // 
    // This is part of revision 9453 of the Stellaris USB Library.
    //
    //*****************************************************************************
    
    #ifndef __USBHHIDgamePad_H__
    #define __USBHHIDgamePad_H__
    
    //*****************************************************************************
    //
    // If building with a C++ compiler, make all of the definitions in this header
    // have a C binding.
    //
    //*****************************************************************************
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    //*****************************************************************************
    //
    //! \addtogroup usblib_host_device
    //! @{
    //
    //*****************************************************************************
    
    typedef struct tUSBHMouse tUSBHMouse;  
    //*****************************************************************************
    //
    //! \addtogroup usblib_host_device
    //! @{
    //
    //*****************************************************************************
    //*****************************************************************************
    //
    // The prototype for the host USB mouse driver callback function.
    //
    //*****************************************************************************
    typedef void (*tUSBHIDMouseCallback)(tUSBHMouse *psMsInstance,
                                         uint32_t ui32Event,
                                         uint32_t ui32MsgParam,
                                         void *pvMsgData);
    
    extern tUSBHMouse * USBHMouseOpen(tUSBHIDMouseCallback pfnCallback,
                                      uint8_t *pui8Buffer, uint32_t ui32Size);
    extern uint32_t USBHMouseClose(tUSBHMouse *psMsInstance);
    extern uint32_t USBHMouseInit(tUSBHMouse *psMsInstance);
    extern uint32_t USBHMouseLPMSleep(tUSBHMouse *psMsInstance);
    extern uint32_t USBHMouseLPMStatus(tUSBHMouse *psMsInstance);
    
    //*****************************************************************************
    //
    //! @}
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // Mark the end of the C bindings section for C++ compilers.
    //
    //*****************************************************************************
    #ifdef __cplusplus
    }
    #endif
    
    #endif

  • Arden

    You are mixing concepts and files a lot - it is wise to clear up the concepts first - ask about in separate threads, then go to coding phase. Here you ask about "host" while including "usbhhidgamepad.h"  which is a device class file. And you use files from different Stellaris and Tiva versions (last one published here is from StellarisWare 9453). Do not do that - choose only the latest version.

    Also, in another thread I warned you to not mixing with TM4C129 code, you do it here again - although (apparently) not used, your variable relating to PLL clock to be 480MHz is wrong - only in 129 micros you may choose the PLL clock from two variants; on TM4C123 the PLL clock is fixed at 400 MHz, and divided by 2 before to be used for system clock.

    The closest host examples you can find are in Tiva/examples/boards/ek-lm4f232/usb_host_mouse and /usb_host_keyboard. Explore these before anything else, see how connecting/disconnecting a mouse/keyboard behaves and then apply to your case. But take into account these examples may use the graphical display, missing on your board (and you need to remove that displaying to).

    And last - if your code snippet is longer than 50 lines, it is better to attach the files instead inserting the code.

    Petrei