Problem with re-initialization of USB CDC in device mode

Hi all,

I am working with lm3s5951 microcontroller which has usb host/device/otg facility in-built.

I could able to invoke USB OTG handler as per "SW-USBL-UG-7611.pdf" specification.

By using usb-id pin in floating to switch from/to host and device modes. In this process, Initialization and termination of Host mode usb drivers are working fine.

But when I invoke usb cdc termination API in device mode, and again initializing the same, my board is not getting configured in device mode properly. What could be the problem? I suspect on that, I am missing some other APIs in process of termination of USB cdc in device mode.

For your reference, below is the code that I am using in my project.

Initialization code of USB Host (MSC class):

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

//
// Initialize the USB stack mode and pass in a mode callback.
//
USBStackModeSet(0, USB_MODE_HOST, ModeCallback);

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

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

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

//
// Initialize the USB controller for OTG operation with a 2ms polling
// rate.
//
//USBOTGModeInit(0, 2000, g_pHCDPool, HCD_MEMORY_SIZE);
USBHCDInit(0,g_pHCDPool, HCD_MEMORY_SIZE);

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

Termination code of USB Host (MSC Class):

fnUSBUnmount();
fnUSBDrvClose();
USBHCDTerm(0);
ROM_USBHostPwrDisable(0);


Initialization of USB Device (CDC class):

//
// Initialize the transmit and receive buffers.
//
USBBufferInit((tUSBBuffer *)&g_sTxBuffer);
USBBufferInit((tUSBBuffer *)&g_sRxBuffer);

pvUSBDevInstance=USBDCDCInit(0, (tUSBDCDCDevice *)&g_sCDCDevice);

Termination code of USB Device (CDC Class):

USBDCDCTerm((tUSBDCDCDevice *)pvUSBDevInstance);         //  "pvUSBDevInstance" is a void pointer variable which holds device instance returned by  

                                                                                                                     //      "USBDCDCInit(0, (tUSBDCDCDevice *)&g_sCDCDevice);"  function.

Schematic of USB Section:


Regards,

Santosh.

  • After a quick look at your code, you set the stack to host mode, but never change it.  Do you have a corresponding call to USBStackModeSet() when you switch to device mode?

  • In reply to Eric Ocasio:

    Hi Eric,

    Thanks for your reply.

    I did not used USBStackModeSet() when I switch to device mode. But my application is working in device mode without 'StackModeSet' function also, when device mode  Initialization function is called for the first time.

    Note: I am using "USB0OTGModeIntHandler" for Host/Device Interrupts.

    I am getting problem in re-initialization of device mode function call. When I am switch from Device mode to Host mode, I am Terminating device mode and Initializing Host mode. And I suspect on termination process of USB CDC in device mode, because when I switch back to Device mode from Host mode, I am terming Host mode and again Initializing Device mode, exactly here USB is not getting configured in device mode properly.

    Anyway, first I will try using 'USBStackModeSet' function when switching to Device mode as per your suggestion.

    Regards,

    Santosh.

  • In reply to Eric Ocasio:

    Thank you Mr.Eric.

    Your suggestion worked here.

    By using "USBStackModeSet" function call for device mode, solved my problem.

    Thank you again,

    Regards,

    Santosh.