Part Number: TM4C123GE6PM
Hello,
I have a USB link up and running with the USB stack (USB ware) as a HID device. I'm seeing that when I plug the USB cable in I get a "USB_EVENT_CONNECTED" event that fires in the ISR. This is great. The problem I see next is upon unplugging the cable. When I unplug the cable I do not get a "USB_EVENT_DISCONNECTED". Instead the "USB_EVENT_DISCONNECTED" fires when I plug the cable back in.
So my sequence of ISR events are basically as follows, upon plugging in a USB cable I get a "USB_EVENT_DISCONNECTED" event first then a "USB_EVENT_CONNECTED". This is an issue because my firmware needs to know when the USB link is plugged in / connected.
My configuration code for the USB driver at power up is as follows:
//
// D+/D- pins (PD4, PD5) Enable initialize
//
GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
//
// Set the USB stack mode to Device mode with VBUS monitoring.
//
USBStackModeSet(0, eUSBModeForceDevice, 0);
//
// Pass our device information to the USB library and place the device
// on the bus.
//
USBDHIDInit(0, &g_sHIDDataPipeDevice);
//IntPrioritySet(INT_USB0, 0x60);
//
// Enable Global processor interrupts
//
IntMasterEnable();
My receive ISR handler code is as follows:
// Receive handler
uint32_t
RXHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgData,
void *pvMsgData)
{
//WTimer0_Set_Counter(/*counter*/ 80000000/10); // Attempt to fix rate problem with deepsleep() mode
// Debug info
static int countRXAvailable=0;
static int countIdleTimeout=0;
static int countGetReportBuffer=0;
static int countGetReport=0;
static int countSetReport=0;
static int countDefault=0;
static int eventListIdx=0;
// End debug vars
uint32_t readPacketSize;
//Debug info
//eventList[eventListIdx++]=ui32Event;
if(eventListIdx==20)
{
eventListIdx=0;
}
switch(ui32Event)
{
case USB_EVENT_CONNECTED:
USBState|=1;
// Change USB priority level so it doesn't interfere with ADC when running
IntPrioritySet(INT_USB0, 0x60);
USB_Enumerated = 1; // Flag showing USB connected or disconnected
break;
case USB_EVENT_DISCONNECTED:
USBState&=0xfe;
USB_Enumerated = 0; // Flag showing USB connected or disconnected
break;
case USB_EVENT_RX_AVAILABLE:
countRXAvailable++;
RXData.state=1;
RXData.size=(uint16_t) (ui32MsgData&0xffff);
USBDHIDPacketRead(&g_sHIDDataPipeDevice, RXData.buffer, RXData.size, true);
_nop();
// Required for now to break out of burst mode locked loop
if(RXData.buffer[1] == 0x03){
BurstMode_Unlock = 1;
}
break;
case USBD_HID_EVENT_IDLE_TIMEOUT:
// Not defining a timeout.
countIdleTimeout++;
break;
case USBD_HID_EVENT_GET_REPORT_BUFFER:
// Return Rx buffer to usb driverlib so
// the report can be stored
countGetReportBuffer++;
readPacketSize=(uint32_t)pvMsgData;
if(readPacketSize>MAX_PACKET_SIZE)
{
_nop(); //Shouldn't happen
}
return((uint32_t)RXData.buffer);
break;
case USBD_HID_EVENT_GET_REPORT:
// Host is requesting a particular report
countGetReport++;
break;
case USBD_HID_EVENT_SET_REPORT:
// Report receive buffer is ready to
// be read.
countSetReport++;
// TODO: check report ID
//set size to let the application know that there is data.
RXData.size=(uint16_t) (ui32MsgData&0xffff);
RXData.state=1;
break;
// sounds like this is required by the new driver
case USB_EVENT_SUSPEND:
break;
// sounds like this is required by the new driver
case USB_EVENT_RESUME:
break;
// added this trying to debug new USB comm bug - 1/15/2018
case USB_EVENT_ERROR:
while(1);
break;
default:
countDefault++;
break;
}
// Pretty sure default return should be 0. Need to verify
return 1;
}
Is there some configuration in the driver that you have to enable to detec plugging and unplugging properly? I'm surprised by this behavior. Any help is greatly appreciated!



