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.

TM4C123GH6PM: USB Connection not start after Replug

Part Number: TM4C123GH6PM

Hi All,

I wrote a code on TM4C123GH6PM which is USB host and I plug barcode reader and read like hid keyboard. Much barcode reader working very well. 

But some barcode readers:

1. When I start the system with the barcode reader attached, the system receives the barcode reader as connected but does not recognize it when I remove it and plug it back in.

2. When I start the system when the barcode reader is not inserted, the same barcode reader can not detect it again.


This is my USB init code:

void initUsb(void){

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
    MAP_SysCtlUSBPLLEnable();

    MAP_SysCtlPeripheralEnable(PERIPH_GPIO_USB0ID);
    MAP_GPIOPinTypeUSBAnalog(BASE_GPIO_USB0ID, PIN_GPIO_USB0ID);

    MAP_SysCtlPeripheralEnable(PERIPH_GPIO_USB0VBUS);
    MAP_GPIOPinTypeUSBAnalog(BASE_GPIO_USB0VBUS, PIN_GPIO_USB0VBUS);

    MAP_SysCtlPeripheralEnable(PERIPH_GPIO_USB0DM);
    MAP_GPIOPinTypeUSBAnalog(BASE_GPIO_USB0DM, PIN_GPIO_USB0DM);

    MAP_SysCtlPeripheralEnable(PERIPH_GPIO_USB0DP);
    MAP_GPIOPinTypeUSBAnalog(BASE_GPIO_USB0DP, PIN_GPIO_USB0DP);

    MAP_GPIOPinConfigure(CONF_GPIO_USB0FLT);
    MAP_GPIOPinTypeUSBDigital(GPIO_PORTD_BASE, PIN_GPIO_USB0FLT);

    MAP_GPIOPinConfigure(CONF_GPIO_USB0EPEN);
    MAP_GPIOPinTypeUSBDigital(BASE_GPIO_USB0EPEN, PIN_GPIO_USB0EPEN);


    USBStackModeSet(0, eUSBModeForceHost, ModeCallback);
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);
    g_psKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pui8Buffer, KEYBOARD_MEMORY_SIZE);

    USBHCDPowerConfigInit(0, USBHCD_VBUS_HIGH | USBHCD_FAULT_VBUS_FILTER );

    USBHCDInit(0, memPoolHCD, HCDMEMORYPOOLSIZE);

}

  • Hi Metin,

     Have you had a chance to try the TivaWare  usb_host_keyboard example? I just tried it and plug->unplug->plug the keyboard and the host is able to detect when plug or unplug happened. Please see below. I hope the example will be a good reference for your bardcode reader application.

  • Hi Charles,

    I used the same example. Many barcode readers work as smoothly as you do, but one of them creates a problem as I mentioned above.
  • Hi Metin,
    Are all the bardcode readers the same (same make, model)? If you reset the host will it start to detect the reader again?
  • Hi Charles,

    Barcode readers are not same brand. I restart USB with this function but not succesful!

    void initUsb(void){
    
    
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
    
        MAP_SysCtlUSBPLLEnable();
    
    
        MAP_SysCtlPeripheralEnable(PERIPH_GPIO_USB0ID);
    
        MAP_GPIOPinTypeUSBAnalog(BASE_GPIO_USB0ID, PIN_GPIO_USB0ID);
    
    
        MAP_SysCtlPeripheralEnable(PERIPH_GPIO_USB0VBUS);
    
        MAP_GPIOPinTypeUSBAnalog(BASE_GPIO_USB0VBUS, PIN_GPIO_USB0VBUS);
    
    
        MAP_SysCtlPeripheralEnable(PERIPH_GPIO_USB0DM);
    
        MAP_GPIOPinTypeUSBAnalog(BASE_GPIO_USB0DM, PIN_GPIO_USB0DM);
    
    
        MAP_SysCtlPeripheralEnable(PERIPH_GPIO_USB0DP);
    
        MAP_GPIOPinTypeUSBAnalog(BASE_GPIO_USB0DP, PIN_GPIO_USB0DP);
    
    
        MAP_GPIOPinConfigure(CONF_GPIO_USB0FLT);
    
        MAP_GPIOPinTypeUSBDigital(GPIO_PORTD_BASE, PIN_GPIO_USB0FLT);
    
    
        MAP_GPIOPinConfigure(CONF_GPIO_USB0EPEN);
    
        MAP_GPIOPinTypeUSBDigital(BASE_GPIO_USB0EPEN, PIN_GPIO_USB0EPEN);
    
    
    
        USBStackModeSet(0, eUSBModeForceHost, ModeCallback);
    
        USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);
    
        g_psKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pui8Buffer, KEYBOARD_MEMORY_SIZE);
    
    
        USBHCDPowerConfigInit(0, USBHCD_VBUS_HIGH | USBHCD_FAULT_VBUS_FILTER );
    
    
        USBHCDInit(0, memPoolHCD, HCDMEMORYPOOLSIZE);
    
    
    }
    
    void restartUsb(void){
    
        USBHCDReset(0);
        initUsb();
    }

  • Hi Metin,

    Perhaps try some other host mode USB library commands to see if they help. Perhaps the VBUS pin is latching up for some reason or the disconnect interrupt flag is not being set. You can debug USB0 in CCS and watch PWR control register VBUS flag, disconnect interrupt and many others.

                 /* Set the USB0 host status receives power from Host */
                 USBDCDPowerStatusSet(0, USB_STATUS_BUS_PWR); //USB_STATUS_SELF_PWR
    
                 /* Specify the type of hostmode (USB0EPEN) VBUS mode and PWR fault condition handling */
                 USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER |
                                              USBHCD_FAULT_LOW | USBHCD_FAULT_VBUS_DIS);