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.

How to initialize the usb controller to be Host mode?

Other Parts Discussed in Thread: OMAPL138, OMAP-L138

Hi,

I have an omapl138, and want to implement the function which can communicate with a Mass storage class (eg a flash driver).

First, I initialize the controller according to usb_init() in example 1(page 81) of SPRUFM9F. Since OMAP should serve as a host, I change the last part to 

    usb0.POWER = USB0_POWER_HSEN; // a high speed host

    usb0.DEVCTL |= USB0_DEVCTRL_SESSION; // let the host in session

 

But when I put a flash driver into it, I can not receive any interrupts. I am wondering what else I need to do to receive the interrupts for host mode.

More issues need to be clarified. 

1) in the usb_init(), after I set usb0.DEVCTL |= USB0_DEVCTRL_SESSION and usb0_ID is gounded down, the usb controller would be in host mode.

2) After the usb controller is in host mode, what else need to be done such that I can receive the host interrupts?

3) And if a flash driver is plugged in, what kinds of interrupts I should receive?

4)Can someone explain the detail of RESET_BABBLE?

5) Can TI provide more sample code about OTG progamming?

Thanks,

Sheng

 

 

  • you can refer uboot musb code for this at,

    http://git.denx.de/?p=u-boot.git;a=tree;f=drivers/usb/musb;h=7a7e14812e6712a2da2b13c0d5b88bd4afba7e74;hb=19b54a701811220221fc4d5089a2bb18892018ca

     

    Please also male sure to enable relevant clocks and pinmux.

    Regards,Ajay

  • Hi,

    Thanks for your response.

    Can you clarify the procedure of how the usb controller determine his role?  The scenario is  I want my omap to be a mass storage device (like a common usb flash driver) when it connects to a PC; when a usb flash driver connects to it, it can serve as a host, such that the flash driver can download data from omap.

    So when the omap is powered up,  the usb controller does not know its role unless a peripheral or a host is connected to the port. Under this situation, how should I initialize the usb controller?

    Here I avoid to use "otg mode" here, and usb controller means the usb module  (hardware) in the omap.

     

    Thanks,

    Sheng

     

  • The role of either host or device would be decided based on the ID pin on the connector. If we want to make it as usb device connected to PC then use mini-B plug on board side.If it has to act as host then use mini-A plug to connect any external use device to it. When either the mini-A or mini-B plug is inserted and then DEVCTL.SESSION(D0) bit is set then musb  controller will sense the id pin and take up the appropriate roles.

    Ajay

  • Hi Ajay,

    I appreciate your reply.

    Can you specify the details of pinmux?

    I have checked the datasheet of omapl138, USB0_ID, USB0_DP, USB_DM, USB0_DRVVBUS do not have mux options.

    Can you tell me which pins need to be muxed? or give me an example, that would be also appreciated.

     

    Another problem is during the initialisation, I have set SESSION bit =1, but after that when I check the DEVCTL register, it is still be 0. Is that possible because the USB0_ID pin is left floated, such at the hardware automatically reset this SESSION bit?

     

    Thanks,

    Sheng

     

  • Sheng, The PINMUX is part of the top level chip configuration that can be found in the OMAP-L138 System Reference Guide
  • I just want to clarify that if I use the internal clock for OMAPL138 USB0 port, I do not need to do any pinmux. Is that correct? I have check the pin assignment, the only pin that could be multipluxed is USB_REFCLKIN. Another questions is that when the firmware set SESSION bit in DEVCTL and USB0_ID is LOW, the HOSTMODE bit in DEVCTL will be set to 1 by the hardware, right? And when I plug a flash driver in to this USB0 port, I should observe the CONN interrupt, right? Thanks, sheng
  • Sheng Hu said:
    I just want to clarify that if I use the internal clock for OMAPL138 USB0 port, I do not need to do any pinmux.

    If you are not using the pin, then you don't have to change the PINMUX.

     

    I'm not sure about the other questions. Are you observing some thing that doesn't seem right?

  • Hi,

    thanks for your reply first.

    Right now I can detect the CONN and DISCON interrupts when I plug my flash driver in/out to my OMAP which is in a host mode.

    Another question is that what is the difference between FIFO0~FIFO4 (add from 420h to 430h) and RXFIFOADDR/TXFIFOADDR(464h-465h and 466h-467h). It seems that they are all supposed to assign the addresses to the endpoint FIFOs. 

     

    Thanks,

    sheng

     

  • Sheng,

     

    Sheng Hu said:
    FIFO0~FIFO4 (add from 420h to 430h)

    These registers are used to read data off the FIFO, or push data onto the FIFO.

     

    Sheng Hu said:
    RXFIFOADDR/TXFIFOADDR(464h-465h and 466h-467h)

    These registers are used to set the starting address of the FIFO in the 4K RAM.  More information about the Dynamic FIFO sizing can be found in section 2.6 of the USB20 user guide (http://focus.ti.com/lit/ug/sprufm9h/sprufm9h.pdf).

     

    --Christina

  • Thanks for your reply.

    Let me clarify the following:

     

          usb0.INDEX      = 1;

          usb0.RXFIFOSZ   = 7;

          usb0.RXFIFOADDR = 8;

          usb0.TXFIFOSZ   = 7;

          usb0.TXFIFOADDR = 136;

    that is 

     

    __________________________

    |  64Byte | 1024Byte | 1024Byte |

    ---------------------------------------------

    EP0            EP1_RX  EP1_TX

    so if I have data which is in data[40]

    how can I load the data to the FIFO of ep0?

    /*----------------------------------

    for(int i=0;i<40;i++)

       usb0.FIFO[0] = data[i];

    /*---------------------------------

    Is this piece of code correct?

    and how about data[2000] to the FIFO of ep1_TX?

    Can you give me some sample code?

     

    Another question is about MaxPacketSize

    who will determine the value of MaxPacketSize?

    My guess is the host. eg. Suppose the host assign the value of MaxPacketSize = 0x40,

    If the length of data from the device is greater than 0x40byte, such as 0x50byte,

    the device will send these 0x50 byte data within two packets, one is 0x40byte and another one is 0x10byte.

    Thanks,

    sheng

     

     

     

     

  • Sheng,

    Sheng Hu said:

    Another question is about MaxPacketSize

    who will determine the value of MaxPacketSize?

     

     

       I believe this is specified in the USB 2.0 Specification based upon the type of USB Transfer as well as the speed of the host/hub. If you need a good tutorial other than the spec, I have found one here: USB In a Nutshell

     

    Sheng Hu said:

    If the length of data from the device is greater than 0x40byte, such as 0x50byte,

    the device will send these 0x50 byte data within two packets, one is 0x40byte and another one is 0x10byte.

       Correct, you would have to send two packets of the length is over the max packet size. You also may have to pad the rest of the 2nd packet.

     

  • Sheng Hu said:

    /*----------------------------------

    for(int i=0;i<40;i++)

       usb0.FIFO[0] = data[i];

    /*---------------------------------

    Is this piece of code correct?

    That is correct.  You'll keep on writing to the FIFOx register to the corresponding EPx with the data you want to send.

     

    Sheng Hu said:

    Another question is about MaxPacketSize

    who will determine the value of MaxPacketSize?

    The Host will ask the Device for its DESCRIPTOR.  The Device will then reply with a DESCRIPTOR that will specify the max packet size it can handle. 

    Please see the USB 2.0 official specs (http://www.usb.org/developers/docs/) for more detail. After you download the USB2.0 Specification zip file, look at the usb_20.pdf file.  In Section 5.8.3, it will talk about the Bulk Transfer Packet Size.  The pdf also has additional information about packet size if you are using another protocol (control, isochronous, or interrupt).

     

    --Christina