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.

TMS320F28069: How to Reset USB Registers

Part Number: TMS320F28069
Other Parts Discussed in Thread: C2000WARE

Hi,

I'm using the TI USB Library from the C2000 Ware software suite. I have CCS  Version: 9.3.0.00012. I have imported the source files for the USB stack into the project so I can modify it.

The version of the library is written as comments in the source file as follows:

// $TI Release: F2806x Support Library v2.06.00.00 $
// $Release Date: Fri Feb 12 19:15:11 IST 2021 $
// $Copyright:
// Copyright (C) 2009-2021 Texas Instruments Incorporated - http://www.ti.com/

I believe this library was ported from the Stellaris microcontroller family to the C28x family.

I am using the host functions of the USB library to communicate point-to-point with a mass storage device at full speed. On occasion the device fails to respond and I receive a NAKTO (NAK timeout) error in the PipeRead or PipeWrite functions in the usbhostenum.c file. The pipe read/write functions are blocking (i.e., I wait in there until the transaction is completed). I realized there's a while forever loop in these functions that was causing my program to get stuck so I use a timer to exit with a 500ms timeout.

The problem I have is after I exit this function I am not able to restore communication with the device ever except after a DSP reset (using the watchdog). I have tried to reset the USB stack by using the initialization functions in the example project in C2000Ware. This works sometimes but not always. I believe I have seen one time where the TXPKTRDY bit was set and was preventing any other communication to be sent from the host.

My question is what is the best way to reset all the USB registers for a 'fresh' start. I'd rather not have to reset the DSP every time this happens? I believe I'm missing something in the re-initialization which makes a DSP reset via watchdog work but not a software reset of the USB stack.

Also will going non-blocking route work better? How can I implement a non-blocking pipe read/write?

Thanks

  • Hi, 

    There are few bits in the USBPOWER register (RESET and SOFTCONN bits) . You can try setting these bits to reset the USB.

    Best Regards

    Siddharth

  • Thanks Siddharth,

    This hasn't resolved the problem.

    Here's how I'm initializing the USB stack:

    SysCtrlRegs.PCLKCR3.bit.USB0ENCLK = 1; // enable USB peripheral clock

    // register interrupt handler and enable interrupts
    USBGPIOEnable();
    USBIntRegister(USB0_BASE, f28x_USB0HostIntHandler);
    IntMasterEnable();

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

    // register the host class drivers.
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, NUM_CLASS_DRIVERS);

    // Open an instance of the mass storage class driver.
    g_psMSCInstance = USBHMSCDriveOpen(0, (tUSBHMSCCallback)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.
    USBHCDInit(0,g_pHCDPool, HCD_MEMORY_SIZE);

    EALLOW;
    HWREG(USBMODESEL) = USBMODESEL_HOST;
    HWREG(USB0_BASE + USB_O_GPCS) = USBGPCS_HOST;
    EDIS;


    g_eState = STATE_NO_DEVICE;

    And here's how I'm attempting to reconnect to the device after it stalls:

    USBHCDDeviceDisconnected(0, 0);

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

    // register the host class drivers.
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, NUM_CLASS_DRIVERS);

    // Open an instance of the mass storage class driver.
    //g_psMSCInstance = USBHMSCDriveOpen(0, (tUSBHMSCCallback)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.
    USBHCDInit(0,g_pHCDPool, HCD_MEMORY_SIZE);

    EALLOW;
    HWREG(USBMODESEL) = USBMODESEL_HOST;
    HWREG(USB0_BASE + USB_O_GPCS) = USBGPCS_HOST;
    EDIS;


    g_eState = STATE_NO_DEVICE;

    Can you tell if I'm missing any steps?

    What steps are necessary to reset the USB hardware and the USB driver stack.

    Thanks

  • Hi,

    Will take a look at the code and respond in a couple of days.

    Best Regards.

    Siddharth 

  • Ok thanks,

    Few more questions.

    What's the effect of the ERROR flag in the USBCSRL0? In the document it says it has to be cleared by the software. I have seen this bit set sometimes. Could this affect reconnecting to the host in anyway if it isn't cleared?

    Also, I've seen the SOF bit set in the USBIS register sometimes when trying to reconnect to the device. I'm simply reading this register to clear the active interrupt flags. Is there anything more to do in addition to reading this register?

    What are some of the registers that will hold up USB traffic and prevent connection that I need to pay attention to?

  • Hi, 

    Will respond to your query tomorrow. 

    Best Regards

    Siddharth

  • Hi Siddharth,

    Any news from your end?

    I have been trying to debug this for some time now and have some more questions regarding the USBDEVCTL register. It has some read-only flags that are changing and I'd like to know why.

    When everything works correctly (usually after a power reset), this register has a value of 0x5D after enumerating the attached device. This means:

    Bit 1 - session started

    Bit 2 - host mode

    Bit 4-3 - VBus valid

    Bit 6 - full-speed device detected

    Usually when we have communication errors or stalls and try to reconnect to the device we use the logic I shared with you in the earlier post. What I have noticed is that when I use the USBHCDTerm to terminate the session the controller goes to device mode permanently so I don't use this function. But even without it the controller still switches to device mode. This function clears the session flag in the USBDEVCTL register and I'm never able to reconnect to the device as a host. After this call the USBDEVCTL register either reports 0x98 or 0x99 which means it is operating in device mode on the OTG B side of the cable (please confirm if this is right). I can use USBHCDTerm  but comment out this call USBOTGSessionRequest(USB0_BASE, false); to make the controller keep the session flag on. This doesn't help much reconnecting to the device anyway. 

    Can the USB controller clear the session flag by itself? I believe I've seen that happen too?

    What could make the USB controller switch to device mode even though I'm not setting it up as a device? The comments in the API suggest that after using USBHCDTerm a call to USBHCDInit must occur to restart a new session. After doing this the host mode (bit 2) flag is never set and the controller operates in device mode. Only a power reset will bring it out of device mode and enable me to reconnect to the device.

    What is the right way to ensure that the controller always operates as a host? Are we possibly operating in OTG mode without setting it up like this. Does the USB controller default to device mode? If so, how can we reliably change to host mode?

    Also what about the USBGPCS register? I'm setting this to 0x00 but USBDEVCTL is still going into device mode.

    Note that the hardware doesn't use an ID pin because we were not expecting to use OTG USB. Do we have to use this pin anyway. Right now I'm unclear how this pin works and where or even if the F28069 supports this pin.

    Counting on your expert help soon.
    Thanks

  • Hi, 

    Will check on why it is defaulting to device mode and update you. 

    Can you try force the stack to be in host mode by calling the following function after USBHCDTerm

    USBStackModeSet(0, eUSBModeForceHost, ModeCallback);

    Best Regards

    Siddharth

  • Yes,

    I'm calling this function.

    It's also in the code snippet I've shared above.

    Let me know what you find regarding the device mode, session and also the ID pin/OTG mode in my previous post.

    Thanks

  • Hi,

    I wlll debug further and let yuo know. At this point, I am not sure what could be causing this issue.

    Best Regards

    Siddharth

  • Hi Siddharth, were you able to debug further on the above?

  • Hi, 

    There is a dual detect example on F2883x which switches between the device and host modes. I am going through the code to figure out how it is handled . Will keep you posted on my observations.

    Best Regards

    Siddharth

  • Hi Siddharth, thank you for digging into this further. How soon can you provide an update?

  • Hi, 

    I took a look at the source code for the dual detect example on F2838x. 

    To reset the USB registers, it calls the following function 

    SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_USBA);

    Looks like the clock to the USB is disabled to clear all the USB registers.

    Equivalent code for F2806x should be 

    SysCtrlRegs.PCLKCR3.bit.USB0ENCLK = 0;

    Then to reinitialize to Host mode , the following code snippet is used

    USBStackModeSet(0, eUSBModeForceHost, ModeCallback);
    HostStackInit();
    USBHCDInit(0, g_pui8HCDPool, myUSB0_LIB_HCD_MEMORY_SIZE);
    g_eCurrentUSBMode = eUSBModeForceHost;

    Best Regards

    Siddharth

  • Thanks Siddharth.

    I'll try these sequence of function calls and report back if it resolves the issue. I'm already using some of these routines but not in the same order.

    Did you find anything regarding the USBID pin? There isn't much documentation on it for the F28069.

  • Hi, 

    Pls try and let us know if it resolves the issue. 

    F28069 does not support USB ID pin.

    Best Regards

    Siddharth