TI E2E Community
Stellaris® ARM® Microcontrollers
Stellaris® ARM® LM3S Microcontrollers Forum
Problem with re-initialization of USB CDC in device mode
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):
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:
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?
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.
Thank you Mr.Eric.
Your suggestion worked here.
By using "USBStackModeSet" function call for device mode, solved my problem.
Thank you again,
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.