AnsweredAssumed Answered

USB CDC stack can hang on Freedom Board

Question asked by Chris Westervelt on Oct 11, 2013
Latest reply on Nov 21, 2013 by Erich Styger

I have discovered that in certain situations, a variable that needs to be cleared to prevent an endless loop can be left in limbo.  It is part of this routine CDC1_App_Task and is transactionOngoing.  It gets cleared by CDC1_App_Callback.  If however the connection is broken while a transaction is in progress and the application has called CDC1_App_Task, the app can become hung.

 

byte CDC1_App_Task(byte *txBuf, size_t txBufSize)

{

  uint8_t i;

 

 

  /* device is Kinetis L2K */

  /* call the periodic task function */

  USB_Class_CDC_Periodic_Task();

  /* check whether enumeration is complete or not */

  if ((start_app==TRUE) && (start_transactions==TRUE)) {

    if (Tx1_NofElements()!=0) {

      i = 0;

      while(i<txBufSize && Tx1_Get(&txBuf[i])==ERR_OK) {

        i++;

      }

      transactionOngoing = TRUE;

      if (USB_Class_CDC_Interface_DIC_Send_Data(CONTROLLER_ID, txBuf, i)!=USB_OK) {

        transactionOngoing = FALSE;

        return ERR_FAULT;

      }

      while(transactionOngoing){} /* wait until transaction is finished */

#if 1 /* workaround for problem in USB stack v3.1.1: if last block is 8, 16, 32, 40, 48, ... bytes, it does not get out until the next transfer? */

      if ((i%8)==0) {

        /* workaround: sending a dummy block of zero bytes */

        transactionOngoing = TRUE;

        if (USB_Class_CDC_Interface_DIC_Send_Data(CONTROLLER_ID, txBuf, 0)!=USB_OK) {

          transactionOngoing = FALSE;

          return ERR_FAULT;

        }

        while(transactionOngoing){} /* wait until transaction is finished */

      }

#endif

    } /* if */

    return ERR_OK;

  } else {

    return ERR_BUSOFF; /* USB bus not available yet */

  }

}

Outcomes