I previously had code using the CDC device library running fine on my DK-TM4C129X dev kit. I have been trying to get OTG implemented, but am not having much luck.
I copied over a bunch of code from the usb_otg_mouse example project and I think I have done all the initialization properly. When I run the code, though, the callback specified in my call to USBStackModeSet() is never getting called.
The weird thing is that the control callback for my CDC device does get called. But every 2 seconds (which just happens to be the time I specified for OTG polling) it gets a disconnect event followed immediately by a connect event. I can actually send and receive characters during the 2 seconds between these events.
Any idea what might cause this behavior? I don't actually use the host mode yet, but I did register a driver (I just copied the example code), although I did not start up anything (e.g., mouse).
I am calling USBOTGMain() every 2 ms from a low priority task.
In case it helps, here is the init code I use:
void UsbCdc::initialize(
void(*processRxCharsFunc)(const U8 *rxChars, U32 numChars),
void(*processConnectionFunc)(bool connectStatus))
{
// initialize class' static variables
currentMode = eUSBModeNone;
newMode = false;
connected = false;
txCompleted = true;
processRxCharsCallback = processRxCharsFunc;
processConnectionCallback = processConnectionFunc;
// the RTOS requires that interrupt service routines be placed in a special
// interrupt vector table by calling the following function.
BSP_IntVectSet(BSP_INT_ID_USB_MAC, &USB0DeviceIntHandler);
// GPIO pin initialization for the USB circuit is done in
// Gpio::initialize()
// configure USB for OTG operation
otgInit();
// initialize host stack
hostInit();
// initialize device stack
deviceInit();
// initialize the USB controller for dual mode operation with a 2ms
// polling rate
USBOTGModeInit(0, OTG_POLLING_RATE_MS, hcdMemoryPool, HCD_MEMORY_SIZE);
}
void UsbCdc::otgInit(void)
{
// enable the USB controller
SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
// 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 PLL frequency
bool ok;
U32 pllRate = PLL_RATE;
ok = USBOTGFeatureSet(0, USBLIB_FEATURE_USBPLL, &pllRate);
assert(ok);
// initialize the USB OTG mode and pass in a mode callback
USBStackModeSet(0, eUSBModeOTG, modeCallback);
// configure low power mode feature
tLPMFeature lpmFeature;
lpmFeature.ui32HIRD = HIRD_US;
lpmFeature.ui32Features = USBLIB_FEATURE_LPM_EN
| USBLIB_FEATURE_LPM_RMT_WAKE;
USBHCDFeatureSet(0, USBLIB_FEATURE_LPM, &lpmFeature);
}
void UsbCdc::hostInit(void)
{
USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);
}
void UsbCdc::deviceInit(void)
{
// initialize the transmit and receive buffers
const tUSBBuffer *buf;
buf = USBBufferInit(&txBuffer);
assert(buf != 0);
buf = USBBufferInit(&rxBuffer);
assert(buf != 0);
// pass our device information to the USB library and place the device
// on the bus
void *p;
p = USBDCDCInit(0, (tUSBDCDCDevice *)&cdcDevice);
assert(p != 0);
}
void UsbCdc::modeCallback(U32 index, tUSBMode mode)
{
currentMode = mode;
newMode = true;
switch(mode)
{
case eUSBModeHost:
break;
case eUSBModeDevice:
break;
case eUSBModeNone:
break;
default:
break;
}
}
Thanks for any insight you can provide.
Regards,
Dave