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.

USB Host Mode not recognizing usb stick on Tiva Launchpad (EK-TM4C123GXL)

Other Parts Discussed in Thread: TM4C123GH6PM, EK-TM4C123GXL

I've made all the necessary hardware modifications to allow host functionality on the DEVICE micro usb port of the Launchpad. 

  • R25 and R29 0-ohm resistors are populated 
  • H18 is shorted to H19, to supply +5v to VBUS.

I've been modifying the usb_host_msc example written for the dk-tm4c123g  board. Since I do not have an LCD for displaying the file structure, I've muted all the calls to the graphics library. At this stage, I simply want the host to recognize the usb flash drive. The 4gb flash drive I'm using has been formatted to fat32 and it is connected via a USB-OTG cable. I know it's receiving enough power because I checked the voltage on VBUS and the flash drive has an LED that is glowing. However, there seems to be no information being exchanged which would've caused the LED to blink. 

Upon stepping through the program, I can see that it is stuck STATE_NO_DEVICE of the state machine. 

Code for the main routine is attached, I would've pasted it here but I though it might be a text file might improve readability. 

//---------------------------------------------------------------------------
// main()
//---------------------------------------------------------------------------
void main(void)
{
	uint32_t ui32DriveTimeout, ui32SysClock, ui32PLLRate;

	//
	// Set the clocking to run from the PLL at 50MHz
	//
	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
					   SYSCTL_XTAL_16MHZ);

	//
	// Configure the device pins.
	//

	// Enable rgb LED
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

	// Enable USB
	SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
	SysCtlUSBPLLEnable();

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); //id  and vbus

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); //dp and dm

	//
	// Configure SysTick for a 100Hz interrupt.
	//
	SysTickPeriodSet(SysCtlClockGet() / TICKS_PER_SECOND);
	SysTickEnable();
	SysTickIntEnable();

	//
	// Enable the uDMA controller and set up the control table base.
	// The uDMA controller is used by the USB library.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
	uDMAEnable();
	uDMAControlBaseSet(g_psDMAControlTable);

	//
	// Initially wait for device connection.
	//
	g_eState = STATE_NO_DEVICE;

	//
	// Initialize the USB stack for host mode only.
	//
	USBStackModeSet(0, eUSBModeHost, 0);

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

	//
	// Open an instance of the mass storage class driver.
	//
	g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback);

    //
    // Initialize the drive timeout.
    //
    ui32DriveTimeout = USBMSC_DRIVE_RETRY;


	//
	// Initialize the USB stack for host mode.
	//
	USBStackModeSet(0, eUSBModeHost, 0);

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

	//
	// Open an instance of the mass storage class driver.
	//
	g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback);

	//
	// Initialize the drive timeout.
	//
	ui32DriveTimeout = USBMSC_DRIVE_RETRY;

    //
    // 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 operation.
	//
	USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);

	//
	// Initialize the file system.
	//
	FileInit();

	//
	// Enter an (almost) infinite loop for reading and processing commands from
	// the user.
	//
	while(1)
	{
		//
		// Call the USB stack to keep it running.
		//
		USBHCDMain();


		switch(g_eState)
		{
			case 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 500ms before attempting to check if the
					// device is ready again.
					//
					SysCtlDelay(ui32SysClock / (3 * 2));

					//
					// Decrement the retry count.
					//
					ui32DriveTimeout--;

					//
					// If the timeout is hit then go to the
					// STATE_TIMEOUT_DEVICE state.
					//
					if(ui32DriveTimeout == 0)
					{
						g_eState = STATE_TIMEOUT_DEVICE;
					}
					break;
				}

				//
				// Getting here means the device is ready.
				// Reset the CWD to the root directory.
				//
				g_cCwdBuf[0] = '/';
				g_cCwdBuf[1] = 0;

				//
				// Set the Device Present flag.
				//
				g_ui32Flags = FLAGS_DEVICE_PRESENT;
				break;
			}

			//
			// If there is no device then just wait for one.
			//
			case STATE_NO_DEVICE:
			{
				if(g_ui32Flags == FLAGS_DEVICE_PRESENT)
				{
                    //
                    // Clear the Device Present flag.
                    //
					g_ui32Flags &= ~FLAGS_DEVICE_PRESENT;
				}
				break;
			}

			//
			// An unknown device was connected.
			//
			case STATE_UNKNOWN_DEVICE:
			{
				//
				// If this is a new device then change the status.
				//
				if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)
				{
					//indicate unknown device is present
				}

				//
				// Set the Device Present flag.
				//
				g_ui32Flags = FLAGS_DEVICE_PRESENT;
				break;
			}

			//
			// The connected mass storage device is not reporting ready.
			//
			case STATE_TIMEOUT_DEVICE:
			{
				//
				// If this is the first time in this state then print a
				// message.
				//
				if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)
				{
					//indicate unknown device is present
				}

				//
				// Set the Device Present flag.
				//
				g_ui32Flags = FLAGS_DEVICE_PRESENT;
				break;
			}

			//
			// Something has caused a power fault.
			//
			case STATE_POWER_FAULT:
			{
				break;
			}
			default:
			{
				break;
			}
		}
	}

}

  • Hello Krithik,

    May be this thread would be the info you are looking for

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/348883/1236645.aspx#1236645

    Regards,

    Amit

  • Hello Amit, 

    I made the changes as per the thread and the wiki, since I'm not monitoring the VBUS line, I've now modified the call to

    USBStackModeSet(0, eUSBModeForceHost, 0);

    And I've also tried shorting PB0/USBID pin to ground, but it hasn't changed anything. The note on Operating Modes in the TivaWare USB Library User's Guide requires me to tie the ID pin to ground only if I'm monitoring VBUS.

    I've commented out the line USBHCDPowerConfigInit, as I'm not sure about the parameter to use there as per the example it is set to USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER. But I'm inclined to think that I should use USBHCD_FAULT_VBUS_NONE, since I'm not monitoring it.

    There were also calls to USBHCDFeatureSet  for which I'm unable to find documentation in the User Guide. 

  • Hello Krithik,

    The function is mentioned in SW-TM4C-USBL-UG-2.1.0.12573.pdf which comes along with TivaWare Installer.

    As for the example code, I would need to try out the same (need some time to go over a few things) and confirm. Hopefully early next week (unless our forum members jump in to my rescue)

    Regards

    Amit

  • Hello Amit, 

    Appreciate the help.

    It seems like I had an older version of the USB Library Guide, I didn't catch that function. In any case I've looked into the Host Programming Examples section to make sure I didn't miss anything. Besides the pin mapping and the power configuration, everything else is the same. Will look forward to replies that might help me move forward. I'll try and experiment with different usb sticks to see if that changes anything. 

    I have a feeling that something is amiss in the way the power configuration is handled. 

    Thanks,
    Krithik 

  • Amit,

    I was able to resolve this. I completely missed defining the interrupt handlers in startup_ccs.c file. Commenting the call to USBHCDPowerConfigInit also helped. The board now recognizes the usb stick. 

    The specific interrupt handlers were: 

    extern void SysTickHandler(void);
    extern void USB0OTGModeIntHandler(void);
    

    Replaced the default handlers with the above in the vector table. 

    Thanks,
    Krithik 

  • Hello Krithik,

    Nice work isolating the issue and posting the update as well.

    Regards

    Amit

  • could you please elaborate the use of making changes in the interrupt vector table when there is no interrupt enabled in the main function?
  • Hello Anupsingh

    The Interrupt is enabled by the usblib file based on the mode being used. You can do a search of "OSBOTGIntHandler"

    Regards
    Amit
  • Hello amit,

    In our application we have to connect pendrive at J9 connector through OTG cable. Currently we are using "USB0HostIntHandler" , is it correct.? or do I need to use "USB0OTGModeInt Handler" ?

  • Sir,

    we have implemented everything mentioned in this thread but our USB pen drive is not detected by EK-TM4C123GH6PM.

    We have populated R25 and R29 and also shorted H18 and H19.

    We have also declared the SysTickIntHandler and USB0OTGModeIntHandler in the vector table  in the startup file.

    The following is my code. I have taken the usb_host_msc example for DK-TM4C123GXL and commented the part of code not related to detection of pen drive. Please point out any mistakes.

     

                //TM4C123GH6PMI USB Host functionality

                // Basic configuration as a host- mass storage programming example

     

                //The following code shows the basic setup code needed for any application that is using the USB library in host mode.

    //The g_pui8HCDPool array which is passed to the USBHCDInit( ) is used as a heap memory for by the USB library and

    //thus should not be used by the application. In this example, the g_ppsHostClassDrivers array holds the MSC (mass storage class)

    //drivers. The macros provided in the pin_map.h file included with DriverLib can be used to indicate which pin and peripheral

    //to use for a given part. The USBHCDRegisterDrivers( ) call passes in the static array of supported USB host class drivers that

    //are supported by the application. Typically, the reading or writing to a device is left to a file system layer or through direct

    //read and write calls.

     

    #include "inc/tm4c123gh6pm.h"

    #include <stdint.h>

    #include <stdbool.h>

    #include "driverlib/gpio.h"

    #include "inc/hw_gpio.h"

    #include "driverlib/sysctl.h"

    #include "inc/hw_sysctl.h"

    #include "inc/hw_types.h"

    #include "inc/hw_memmap.h"

    #include "driverlib/debug.h"

    #include "driverlib/rom.h"

    #include "driverlib/pin_map.h"

    #include "grlib/grlib.h"

    #include "grlib/widget.h"

    #include "utils/ustdlib.h"

    #include "driverlib/fpu.h"

    #include "driverlib/interrupt.h"

    #include <string.h>

    #include "driverlib/systick.h"

    #include "driverlib/udma.h"

    #include "driverlib/usb.h"

    #include "inc/hw_usb.h"

    #include "usblib/host/usbhost.h"     //contains host mode function prototypes and data types

    #include "usblib/host/usbhmsc.h"   //contains Mass Storage Class definitions specific to hosts

    #include "usblib/usblib.h"

    #include "usblib/usbmsc.h"

    #include "third_party/fatfs/src/ff.h"

    #include "third_party/fatfs/src/diskio.h"

     

    //#include "drivers/cfal96x64x16.h"

    //#include "drivers/buttons.h"

    //#include "drivers/slidemenuwidget.h"

    //********************************************************************************************************************************

    //

    // The number of SysTick ticks per second

    //

    //*********************************************************************************************

    #define TICKS_PER_SECOND 100

    #define MS_PER_SYSTICK (1000 / TICKS_PER_SECOND)

     

    //*************************************************************************************************

    //

    // A counter for system clock ticks, used for simple timing.

    //

    //**********************************************************************************************

    static uint32_t g_ui32SysTickCount;

     

     

    //*****************************************************************************

    //*****************************************************************************

    //

    // The following are data structures used by FatFs.

    //

    //*****************************************************************************

    //static FATFS g_sFatFs;

    //static DIR g_sDirObject;

    //static FILINFO g_sFileInfo;

     

    //*****************************************************************************

    //

    // 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 and

    // providing a human-readable string.

    //

    //*****************************************************************************

    /*

    tFresultString g_sFresultStrings[] =

    {

       FRESULT_ENTRY(FR_OK),

       FRESULT_ENTRY(FR_DISK_ERR),

       FRESULT_ENTRY(FR_INT_ERR),

       FRESULT_ENTRY(FR_NOT_READY),

       FRESULT_ENTRY(FR_NO_FILE),

       FRESULT_ENTRY(FR_NO_PATH),

       FRESULT_ENTRY(FR_INVALID_NAME),

       FRESULT_ENTRY(FR_DENIED),

       FRESULT_ENTRY(FR_EXIST),

       FRESULT_ENTRY(FR_INVALID_OBJECT),

       FRESULT_ENTRY(FR_WRITE_PROTECTED),

       FRESULT_ENTRY(FR_INVALID_DRIVE),

       FRESULT_ENTRY(FR_NOT_ENABLED),

       FRESULT_ENTRY(FR_NO_FILESYSTEM),

       FRESULT_ENTRY(FR_MKFS_ABORTED),

       FRESULT_ENTRY(FR_TIMEOUT),

       FRESULT_ENTRY(FR_LOCKED),

     

       FRESULT_ENTRY(FR_NOT_ENOUGH_CORE),

       FRESULT_ENTRY(FR_TOO_MANY_OPEN_FILES),

       FRESULT_ENTRY(FR_INVALID_PARAMETER),

    };

    */

    //***********************************************************************************************************************

    //

    // Defines the number of times to call to check if the attached device is

    // ready.

    //

    //***********************************************************************************************************************

    #define USBMSC_DRIVE_RETRY     4

     

    //*****************************************************************************

     

    //*****************************************************************************

    //

    // Holds global flags for the system.

    //

    //*****************************************************************************

    static uint32_t g_ui32Flags = 0;

     

    //*****************************************************************************

    //

    // Flag indicating that some USB device is connected.

    //

    //*****************************************************************************

    #define FLAGS_DEVICE_PRESENT   0x00000001

    //

    // Hold the current state for the application.

    //

    //*****************************************************************************

    typedef enum

    {

       //

       // No device is present.

       //

       STATE_NO_DEVICE,

       //

       // 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 mass storage device was connected but failed to ever report ready.

       //

       STATE_TIMEOUT_DEVICE,

     

       //

       // A power fault has occurred.

       //

       STATE_POWER_FAULT

    }

    tState;

     

    volatile tState g_eState;

    volatile tState g_eUIState;

     

    //*****************************************************************************

    //

    // Define a pair of buffers that are used for holding path information.

    // The buffer size must be large enough to hold the longest expected

    // full path name, including the file name, and a trailing null character.

    // The initial path is set to root "/".

    //

    //*****************************************************************************

    //#define PATH_BUF_SIZE   80

    //static char g_cCwdBuf[PATH_BUF_SIZE] = "/";

    //static char g_cTmpBuf[PATH_BUF_SIZE];

     

    //*****************************************************************************************************************************

     

    void * g_psDMAControlTable;

     

    //*****************************************************************************

    //

    // The current USB operating mode - Host, Device or unknown.

    //

    //*****************************************************************************

    tUSBMode g_eCurrentUSBMode;

     

    //*****************************************************************************

     

    uint32_t g_ui32UnknownClass;   // class of the unknown device

     

    //**************************************************************************************************************************

    #define HCD_MEMORY_SIZE 128   //the size of the host controller’s memory size in bytes

    unsigned char g_pui8HCDPool [HCD_MEMORY_SIZE]; //the memory pool to provide to the host controller driver

     

    //*****************************************************************************

    //

    // The instance data for the MSC driver.

    //

    //*****************************************************************************

    tUSBHMSCInstance * g_psMSCInstance = 0;

     

    //*****************************************************************************

     

    //Declare the USB events driver interface

     

    DECLARE_EVENT_DRIVER(g_sUSBEventDriver, 0, 0, USBHCDEvents);

     

    static tUSBHostClassDriver const * const g_ppsHostClassDrivers[] =

                                                                            {

                                                                                                    &g_sUSBHostMSCClassDriver,

                                                                                                    &g_sUSBEventDriver                         // why do we add this?

                                                                            };

                // the global that holds all of the host drivers in use in the application

     

    static const unsigned long g_ui32NumHostClassDrivers =   sizeof ( g_ppsHostClassDrivers ) / sizeof ( tUSBHostClassDriver * );

    //this global holds the number of class drivers in the g_ppsHostClassDrivers list

     

    //*****************************************************************************

    //

    // The control table used by the uDMA controller. This table must be aligned

    // to a 1024 byte boundary. In this application uDMA is only used for USB,

    // so only the first 6 channels are needed.

    //

    //*****************************************************************************

    #if defined(ewarm)

    #pragma data_alignment=1024

    tDMAControlTable g_sDMAControlTable[6];

    #elif defined(ccs)

    #pragma DATA_ALIGN(g_sDMAControlTable, 1024)

    tDMAControlTable g_sDMAControlTable[6];

    #else

    tDMAControlTable g_sDMAControlTable[6] __attribute__ ((aligned(1024)));

    #endif

     

    //*****************************************************************************

    //

    // 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 handler for the SysTick interrupt. It simply increments a counter that is used for timing.

    //

    //**********************************************************************************

    void

    SysTickHandler (void)

                {

                g_ui32SysTickCount++;

                }

     

    //*****************************************************************************

    //

    // Initializes the file system module.

    //

    // \param None.

    //

    // This function initializes the third party FAT implementation.

    //

    // \return Returns \e true on success or \e false on failure.

    //

    //*****************************************************************************

    /*static bool

    FileInit(void)

    {

       //

       // Mount the file system, using logical disk 0.

       //

       if(f_mount(0, &g_sFatFs) != FR_OK)

       {

           return(false);

       }

     return(true);

    }

    */

    //************************************************************************************************************

     

    // MSCCallBack

     

    //*************************************************************************************************************

    void MSCCallBack (tUSBHMSCInstance *g_psMSCInstance, uint32_t ui32Event, void *pvEventData)

                {

                switch (ui32Event)

                            {

                                        // new pen drive detected

                            case USB_EVENT_CONNECTED:

                                        {

                                                    g_eState= STATE_DEVICE_ENUM;

                                                    break;

                                        }

     

                                        //pen drive has been unplugged

                            case USB_EVENT_DISCONNECTED:

                                        {

                                                    g_eState= STATE_NO_DEVICE;

                                                    break;

                                        }

                            default:

                            {

                                        break;

                            }

                            }

                }

     

    //*****************************************************************************

    //

    // This is the generic callback from host stack.

    //

    // \param 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 mass storage 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.

    //

    // \return None.

    //

    //*****************************************************************************

     

    void

    USBHCDEvents(void *pvEventData)

    {

       tEventInfo *pEventInfo;

     

       //

       // Cast this pointer to its actual type.

       //

       pEventInfo = (tEventInfo *)pvEventData;

     

       switch(pEventInfo->ui32Event)

       {

           //

           // Unknown device detected.

           //

           case USB_EVENT_UNKNOWN_CONNECTED:

           {

               //

               // Save the unknown class.

               //

               g_ui32UnknownClass = pEventInfo->ui32Instance;

     

               //

               // An unknown device was detected.

               //

               g_eState = STATE_UNKNOWN_DEVICE;

     

               break;

           }

     

           //

           // USB Device has been unplugged.

           //

           case USB_EVENT_DISCONNECTED:

           {

               //

               // Unknown device has been removed.

              //

               g_eState = STATE_NO_DEVICE;

     

               break;

           }

     

           case USB_EVENT_POWER_FAULT:

           {

               //

               // No power means no device is present.

               //

               g_eState = STATE_POWER_FAULT;

     

               break;

           }

     

           default:

           {

               break;

           }

       }

    }

     

    //*************************************************************************************************************

     

    //Application Start

     

    //**************************************************************************************************************

     

                void main (void)

                {

                uint32_t ui32DriveTimeout, ui32SysClock, ui32PLLRate;

                //tState eStateCopy;

     

                FPULazyStackingEnable();

     

                //

                // Enable Interrupts

                //

                IntMasterEnable();

     

       // Set the clocking to run from the PLL at 50 MHz

                SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

     

                // enable clocking

                SysCtlPeripheralEnable (SYSCTL_PERIPH_USB0);

                SysCtlUSBPLLEnable();

     

                //*****************************************************************************************************************

     

                // LED initialization

     

                volatile uint32_t ui32Loop;

       SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;

       ui32Loop = SYSCTL_RCGC2_R;

       GPIO_PORTF_DIR_R = 0xFF;

       GPIO_PORTF_DEN_R = 0xFF;

     

                            //*****************************************************************************************************************

     

     

                //Enable the GPIO peripherals used by the USB pins

                            SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOB);

     

                //enable PB0 and PB1 as VBUS and ID pins

                            GPIOPinTypeUSBAnalog (GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);         // PB0- ID; PB1- VBUS

     

                            SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOD);

                // Enable the D+/ D- as USB pins

                            GPIOPinTypeUSBAnalog (GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);         // PD4- D-, PD5- D+

     

                //          SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOC);

                // configure USBEPEN as a USB pin

                //          GPIOPinConfigure (GPIO_PC6_USB0EPEN);

                //          GPIOPinTypeUSBDigital (GPIO_PORTC_BASE, GPIO_PIN_6);

     

                //Configure SysTick for a 100 Hz interrupt

                            SysTickPeriodSet (SysCtlClockGet()/ TICKS_PER_SECOND);

                            SysTickEnable();

                            SysTickIntEnable();

     

                //Enable the uDMA controller and set up the control table base

                //The uDMA controller is used by the USB library.

                            SysCtlPeripheralEnable (SYSCTL_PERIPH_UDMA);

                            uDMAEnable ();

                            uDMAControlBaseSet (g_psDMAControlTable);

     

                //

       // Initially wait for device connection.

       //

                            g_eState = STATE_NO_DEVICE;

                            g_eUIState = STATE_NO_DEVICE;

     

                //Initialize the USB stack for host mode

                            USBStackModeSet(0,eUSBModeForceHost,0);

     

                //Register the host class drivers

                            USBHCDRegisterDrivers (0, g_ppsHostClassDrivers, g_ui32NumHostClassDrivers);

     

                // Initialize the power configuration. Set the power enable signal to be active high and does not enable the power fault.

    //                      USBHCDPowerConfigInit (0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

     

                // call any open routines here for the application to be ready for a new mass storage device

                            g_psMSCInstance= USBHMSCDriveOpen (0, MSCCallBack);      // open an instance of the mass storage class driver

     

                            ui32DriveTimeout= USBMSC_DRIVE_RETRY; //initialize drive timeout

     

                            //

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

     

                            USBHCDInit (0, g_pui8HCDPool, HCD_MEMORY_SIZE); // initialize the host controller

     

                //          FileInit(); //initialize the file system

     

                            //LED glow

                            GPIO_PORTF_DATA_R |= 0x16;

                            for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++);

                            GPIO_PORTF_DATA_R &= ~(0x16);

                            for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++);

                            // main loop of the application

     

                            while (1)

                                        {

                                        //

                                        // Call the USB stack to keep it running.

                                        //

     

                                        USBHCDMain( );   // Periodic call for the Host Controller Drivers

                                        //

                                        // 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 500ms before attempting to check if the

                                                   // device is ready again.

                                                   //

                                                   SysCtlDelay(SysCtlClockGet()/(3*2));

     

                                                   //

                                                   // Decrement the retry count.

                                                   //

                                           ui32DriveTimeout--;

                                           //

                                                   // If the timeout is hit then go to the

                                                   // STATE_TIMEOUT_DEVICE state.

                                                   //

                                                   if(ui32DriveTimeout == 0)

                                                               {

                                                       g_eState = STATE_TIMEOUT_DEVICE;

                                                       break;

                                                       }

                                                   }

                                                 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)

                                                               {

                                                               //This state is entered when the pen drive is first detected.

                                                               case 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 500ms before attempting to check if the

                                                                                                                                     // device is ready again.

                                                                                                                                     //

                                                                                                                                     SysCtlDelay(ui32SysClock/(3*2));

     

                                                                                                                                     //

                                                                                                                                     // Decrement the retry count.

                                                                                                                                     //

                                                                                                                             ui32DriveTimeout--;

                                                                                                                              //

                                                                                                                                     // If the timeout is hit then go to the

                                                                                                                                     // STATE_TIMEOUT_DEVICE state.

                                                                                                                                     //

                                                                                                                                     if(ui32DriveTimeout == 0)

                                                                                                                                                 {

                                                                                                                                          g_eState = STATE_TIMEOUT_DEVICE;

                                                                                                                                         // break;

                                                                                                                                         }

                                                                                                                                     break;

                                                                                                                                     }

     

                                                                       //

                                                                     // Getting here means the device is ready.

                                                                     // Reset the CWD to the root directory.

                                                                     //

     

     

                //                                                     g_cCwdBuf[0]='/';

                            //                                         g_cCwdBuf[1]=0;

     

                                                                       //

                                                                       // Set the Device Present flag.

                                                                       //

     

                                                                       g_ui32Flags=FLAGS_DEVICE_PRESENT;

                                                                       //g_eState = STATE_DEVICE_READY;

                                                                                      break;

                                                                          }

                            /*                                 case STATE_DEVICE_READY:

                                                                          {

                                                                                      // glow an LED if the pen drive is detected.

                                                                                      GPIO_PORTF_DATA_R |= 0x08;

                                                                          for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++);

                                                                                      GPIO_PORTF_DATA_R &= ~(0x08);

                                                                          for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++);

                                                                                      break;

                                                                          }

     

                            */

                                                               case STATE_NO_DEVICE:

                                                                          {

                                                                                      if(g_ui32Flags == FLAGS_DEVICE_PRESENT)

                                                                                                  {

                                                           // Clear the Device Present flag.

                                                           //

                                                                                                    g_ui32Flags &= ~FLAGS_DEVICE_PRESENT;

                                                                                                  }

                                                                                      // glow an LED if no device is connected.

                                                                                      GPIO_PORTF_DATA_R |= 0x04;

                                                                                      for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++);

                                                                                      GPIO_PORTF_DATA_R &= ~(0x04);

                                                                                       for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++);

                                                                                      break;

                                                                          }

                                                               case STATE_UNKNOWN_DEVICE:

                                                                                                   {

                                                                                                               //

                                                                                                               // If this is a new device then change the status.

                                                                                                               //

                                                                                                               if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)

                                                                                                               {

                                                                                                                           //indicate unknown device is present

                                                                                                               }

     

                                                                                                               //

                                                                                                               // Set the Device Present flag.

                                                                                                               //

                                                                                                               g_ui32Flags = FLAGS_DEVICE_PRESENT;

                                                                                                               break;

                                                                                                   }

                                                               //

                                                               // The connected mass storage device is not reporting ready.

                                                               //

                                                               case STATE_TIMEOUT_DEVICE:

                                                                                                   {

                                                                                                   //

                                                                                                   // If this is the first time in this state then print a

                                                                                                   // message.

                                                                                                   //

                                                                                                               if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0)

                                                                                                                                                   {

                                                                                                                                                               //indicate unknown device is present

                                                                                                                                                   }

     

                                                                                                                                                   //

                                                                                                                                                   // Set the Device Present flag.

                                                                                                                                                   //

                                                                                                                                                   g_ui32Flags = FLAGS_DEVICE_PRESENT;

                                                                                                                                                   break;

                                                                                                   }

     

                                                                                                   //

                                                                                                                           // Something has caused a power fault.

                                                                                                                           //

                                                                case STATE_POWER_FAULT:

                                                                                                    {

                                                                                                   break;

                                                                                                    }

     

                                                               default:

                                                                          {

                                                                                      break;

                                                                          }

                                                               }

                                                   // }

                                       g_eUIState = g_eState;

     

                                        }

                            }

     

     

  • Hello Anupsingh,

    I have marked all 3 of your posts for resolution (require a time to get this working on the EK-TM4C123GXL on account of holidays).

    Regards
    Amit
  • Dear Amit,

    We managed to finally resolve the problem. Our board is now detecting pendrives of 2GB, 4GB and 8GB sizes.

    There were a few errors in the variables given as arguments to MSCCallBack( ) and USBHCDEvents( ). They were removed by carefully comparing our code with the 'usb_host_msc' example for DK-TM4C123GXL provided in TivaWare.

    Thank you everyone for all the support and guidance!

     

  • Hi Krithik, Can you please upload your entire code?

    We are working on the same board (EK- TM4C123GXL) and have managed to detect the USB pen drive on the same. But we are having problems with the FileInit( ) function as CCS says f_mount is an unresolved symbol.

    Please help.

  • Hi,

    I have it on Github (https://github.com/krithik/tiva-usb-host-msc). Hope it helps.

    I do recall having some issues with getting the fatfs library to work correctly, but it was more to do with setting up the project properties correctly rather than the code. Unfortunately, I've don't have the notes on that. You will have to trial and error yourself out of this one.