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.

L138 read/write USB 2.0 endpoint FIFO

Other Parts Discussed in Thread: OMAPL138

Hi,

Any document or sample code that show how to read/write the USB endpoint FIFO ?

For example, do I need to always check the COUT0 register and flush the FIFO if there is leftover ?

As FIFO register is 4-byte wide, what if I need to read a data which length is less than 4-byte ?

rgds,

kc Wong

  • I think I figure that out by studying the implementation in Linux.

    Basically, I have 3 helper functions as listed below.  To read the 8-byte setup data from endpoint 0 FIFO, I can do as below.

            USB_ReadRegLong((const void *) &(USB_OTG->FIFO0), buf, 1);        /* read 4 bytes from FIFO */
            USB_ReadRegShort((const void *) &(USB_OTG->FIFO0), buf+4, 1);   /* read 2 bytes from FIFO */
            USB_ReadRegByte((const void *) &(USB_OTG->FIFO0), buf+6, 2);     /* read another 2 bytes from FIFO */

    It is working on Logic PD eXperimenter Kit (OMAP L138).  Just put here for sharing and comment also.

    But, I not sure if the 3 helper functions can actually be generalized to all the registers, or only applicable to the FIFO registers ? Hopefully anyone can comment on this ...

    But, that will still be nice to know if there is any documentation. Thanks.

    rgds,

    kc Wong

    void USB_ReadRegByte(const void *addr, const void *buf, UINT32 length)
    {
        UINT32 index;
        UINT8 *tmp = (UINT8 *) buf;

        for (index = 0; index < length; index++)
        {
            tmp[index] = *((UINT8 *) addr);
        }
    }

    void USB_ReadRegShort(const void *addr, const void *buf, UINT32 length)
    {
        UINT32 index;
        UINT16 *tmp = (UINT16 *) buf;

        for (index = 0; index < length; index++)
        {
            tmp[index] = *((UINT16 *) addr);
        }
    }

    void USB_ReadRegLong(const void *addr, const void *buf, UINT32 length)
    {
        UINT32 index;
        UINT32 *tmp = (UINT32 *) buf;

        for (index = 0; index < length; index++)
        {
            tmp[index] = *((UINT32 *) addr);
        }
    }

     

  • Thank you for posting how you resolved the issue. It helped me a lot! (saved me a lot of time).

  • KC -

    Kiung Chung Wong said:
    For example, do I need to always check the COUT0 register and flush the FIFO if there is leftover ?

    COUNT0 Register is used for OUT Packets to determine how many bytes were received from the Host for each interrupt received.

    This register should be read to determine how many bytes to unload from the Endpoint 0 FIFO.

     

    Kiung Chung Wong said:
    As FIFO register is 4-byte wide, what if I need to read a data which length is less than 4-byte ?

    The FIF0 is smart enough to return the specified value that you request with a pointer. For instance if you point to the buffer with an char, it will read one byte at a time. If you point to the buffer with a int, it will return 4 bytes (1 32 bit word) at a time. This action cannot be assumed for other registers.

     

  • Thanks, Drew.

    Especially the second part about the FIFO special behaviour, I think it will be helpful to include that information in SPRUFM9H to differentiate FIFOs with other registers.

    I got to figure that out by reading the Linux code. It definitely saves me time if it is documented.

    rgds,

    kc Wong

  • Hello,

    Is it possible to read/write USB without Linux.

    I find three functions in logicPd BSL,

    - USB_init()

    -USB_getHostRevision()

    -USB_OTG_init();

    But want to know how to read/write into external USB device.

    Regards,

    Prat

  • Yes, you can read/write USB without Linux.

    I think those 3 functions in logicPd BSL show you how to read/write to the registers in on-chip USB controller.

    If USB device is not on-chip, then it depends on how the external USB device is connected. If it is connected to the external memory controller, then just read/write it as the memory location.

    rgds,

    kc Wong

  • Hello Kc Wong,

    Any external USB devise connected to Connectors with  IDs-J6 and J21 on the baseboard of the omapL138 EV can be read/write as normal memory location?

    Regards,

    Prat

  • Hi Prat,

    Are they connected to EMIFA of OMAP L138 ? Is the external USB device has address lines and data lines ?

    If yes, most probably you can.

    rgds,

    kc Wong