Hello again,
I've been trying to handle this issue for the past month unsuccessfully, so at the end I decided to ask if you guys could help.
The brief description of the problem is that after a USB stick is reattached to the hub the controller does not register it at all. On the older version of the project I am working on, the USB could be somtimes recognised, but in the majority of cases the controller was not able to find a device descriptor and the function USBHMSCDriveReady( g_psMSCInstance ) used to always return -1 because psMSCInstance->psDevice was always 0. psMSCInstance is the structure containing the instance of a USB host driver and the psDevice is the structure containing the device information. Without any changes made to the USB part in the new project, the program does not output properly from the USBOTGMain function, as it always gives eUSBModeNone as output. I cannot put breakpoints in the mode.c file and cannot change anything in it so I am not quite sure what exactly is the root of the issue.
This is how the USB is initialised in the code:
void TIVA_Init_USB0( void )
{
// Enable the USB peripheral
MAP_SysCtlPeripheralEnable( SYSCTL_PERIPH_USB0 );
// Initialize the USB stack mode and pass in a mode callback.
USBStackModeSet( 0, eUSBModeOTG, ModeCallback );
// Initialize the stack to be used with USB stick.
USBStickInit();
// TODO Initialize the stack to be used as a serial device.
USBOTGModeInit( 0, 40, g_pui8HCDPool, HCD_MEMORY_SIZE ); // STM (Originally 40ms Polling rate)
usbInit = true; // STM
// TODO Test
IntPrioritySet( INT_USB0, 0x0 );
}
void USBStickInit( void )
{
//
// Enable the uDMA controller and set up the control table base.
// The uDMA controller is used by the USB library.
//
MAP_SysCtlPeripheralEnable( SYSCTL_PERIPH_UDMA );
MAP_uDMAEnable();
MAP_uDMAControlBaseSet( g_psDMAControlTable );
//
// Initially wait for device connection.
//
g_iState = eSTATE_NO_DEVICE;
//
// 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 );
USBHCDPowerConfigInit( 0, USBHCD_VBUS_AUTO_LOW | USBHCD_VBUS_FILTER );
//
// Run initial pass through USB host stack.
//
USBHCDMain();
//
// Initialize the file system.
//
FileInit();
}
This is the function, called periodically from an event based interrupt, to operate the USB data logging:
void usb_go( void )
{
USBOTGMain( GetTickms() );
if( g_iCurrentUSBMode == eUSBModeHost )
{
USBStickRun();
}
}
void USBStickRun( void )
{
//
// Call the USB stack to keep it running.
//
USBHCDMain();
//
// Take action based on the application state.
//
switch( g_iState )
{
//
// A device has enumerated.
//
case eSTATE_DEVICE_ENUM:
{
//
// Check to see if the device is ready. If not then stay
// in this state and we will check it again on the next pass.
//
if( USBHMSCDriveReady( g_psMSCInstance ) != 0 )
{
//
// Wait about 500ms before attempting to check if the
// device is ready again.
//
MAP_SysCtlDelay( MAP_SysCtlClockGet() / 15 );
break;
}
//
// If there were no errors reported, we are ready for
// MSC operation.
//
g_iState = eSTATE_DEVICE_READY;
break;
}
//
// If there is no device then just wait for one.
//
case eSTATE_NO_DEVICE:
{
break;
}
//
// An unknown device was connected.
//
case eSTATE_UNKNOWN_DEVICE:
{
break;
}
//
// The device is ready and in use.
//
case eSTATE_DEVICE_READY:
{
break;
}
//
// Something has caused a power fault.
//
case eSTATE_POWER_FAULT:
{
break;
}
//
// Unexpected USB state. Set back to default.
//
default:
{
g_iState = eSTATE_NO_DEVICE;
break;
}
}
}
And that's the Modecall, essentially does not do anything:
void ModeCallback( uint32_t ui32Index, tUSBMode iMode )
{
//
// Save the new mode.
//
g_iCurrentUSBMode = iMode;
// Mode-specific handling code could go here.
switch( iMode )
{
case eUSBModeHost:
{
if( usbInit == false ) // STM
{
MAP_SysCtlPeripheralDisable( SYSCTL_PERIPH_USB0 );
MAP_SysCtlPeripheralEnable( SYSCTL_PERIPH_USB0 );
MAP_SysCtlPeripheralReset( SYSCTL_PERIPH_USB0 );
TIVA_Init_USB0();
USBStickInit();
usbInit = true;
}
break; // STM Reset peripheral and initialize USB stick
}
case eUSBModeDevice:
{
break;
}
case eUSBModeOTG:
{
break;
}
case eUSBModeNone:
{
break;
}
case eUSBModeForceHost:
{
break;
}
case eUSBModeForceDevice:
{
break;
}
default:
{
break;
}
}
}
Should I change the modecallback or the OTG mode call from the initialisation or should look for the problem somewhere else?
Thank you!