Skip to main content
love21cz
Associate
May 5, 2010
Question

BUG? (USB_OTG_LIB)

  • May 5, 2010
  • 2 replies
  • 2020 views
Posted on May 05, 2010 at 18:25

BUG? (USB_OTG_LIB)

    This topic has been closed for replies.

    2 replies

    saimaddy123
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:50

    Hi Thomas,

    May I know if you are using this for Virtual COM port and trying to transfer stdio data over USB?

    Thanks,

    Sai

    thomasbretgeld9
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:50

    Hi,

    I had the same problem with the current library V3.2.1. I am using a CL device and the problem seems to be a bug in the library: Whenever you start a transfer and the last USB frame is pending, the TX Empty Fifo Interrupt is constantly asserted and the library keeps jumping into the interrupt routine until all data is read by the usb host, which usually blocks everything else. This is especially a problem if you send a packet of less then 64bytes (Max ep size in my case) and the host doesn't read it. There is nothing to reload into the fifo and the interrupt keeps triggering forever.

    I found the problem in the ot_fs_int.c file in function ''static uint32_t PCD_WriteEmptyTxFifo(uint32_t epnum)''

    I modified this function, which solves the problem for the moment:

    static uint32_t PCD_WriteEmptyTxFifo(uint32_t epnum)

    {

      USB_OTG_DTXFSTS_TypeDef txstatus;

      USB_OTG_EP *ep;

      uint32_t len = 0;

      uint32_t dwords = 0;

     

      txstatus.d32 = 0;

     

      ep = PCD_GetInEP(epnum);

     

      len = ep->xfer_len - ep->xfer_count;

      if (len > ep->maxpacket)

      {

        len = ep->maxpacket;

      }

      //Begin Modified by Thomas Bretgeld

      if ((ep->xfer_len > 0) && (ep->xfer_count == ep->xfer_len))

      {

        //Disable the Tx FIFO Empty Interrupt for this EP

        uint32_t fifoemptymsk = 0;

        fifoemptymsk = 1 << ep->num;

        USB_OTG_MODIFY_REG32(&USB_OTG_FS_regs.DEV->DIEPEMPMSK, fifoemptymsk, 0);

      }

      else

      {

        dwords = (len + 3) / 4;

        txstatus.d32 = USB_OTG_READ_REG32( &USB_OTG_FS_regs.DINEPS[epnum]->DTXFSTSx);

       

        while  ((txstatus.b.txfspcavail > dwords) &&

                (ep->xfer_count < ep->xfer_len) &&

                (ep->xfer_len) != 0)

        {

          len = ep->xfer_len - ep->xfer_count;

          if (len > ep->maxpacket)

          {

            len = ep->maxpacket;

          }

          dwords = (len + 3) / 4;

          OTGD_FS_WritePacket(ep->xfer_buff, epnum, len);   

         

          ep->xfer_count += len;

          ep->xfer_buff += len;

          txstatus.d32 = USB_OTG_READ_REG32(&USB_OTG_FS_regs.DINEPS[epnum]->DTXFSTSx);  

        }

      }

      //End Modified by Thomas Bretgeld

     

      return 1;

    }