Hi Chris,
yes, the actual implementation on GitHub (see Processor Expert Component *.PEupd Files on GitHub | MCU on Eclipse) fixes this. It is using a timout component which prevents that the application will hang. The code is as below:
/*
** ===================================================================
** Method : CDC1_SendDataBlock (component FSL_USB_CDC_Device)
**
** Description :
** Sends a USB data block
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
byte CDC1_SendDataBlock(byte *data, word dataSize)
{
TMOUT1_CounterHandle timeout;
uint8_t res = ERR_OK;
transactionOngoing = TRUE;
if (USB_Class_CDC_Interface_DIC_Send_Data(CONTROLLER_ID, data, dataSize)!=USB_OK) {
transactionOngoing = FALSE;
return ERR_FAULT;
}
/* wait for transaction finish */
timeout = TMOUT1_GetCounter(100/TMOUT1_TICK_PERIOD_MS); /* set up timeout counter */
while(transactionOngoing) { /* wait until transaction is finished */
CDC1_RunUsbEngine();
if (TMOUT1_CounterExpired(timeout)) {
res = ERR_FAILED;
break;
}
}
TMOUT1_LeaveCounter(timeout); /* return timeout counter */
return res;
}
/*
** ===================================================================
** Method : CDC1_App_Task (component FSL_USB_CDC_Device)
** Description :
** Application task to be called periodically from the main
** task.
** Parameters :
** NAME - DESCRIPTION
** * txBuf - Pointer to temporary buffer used to
** transmit data over USB. Should be equal or
** greater than the endpoint buffer size. Data
** will be sent in an asynchronous way, so
** make sure the buffer is *not* on the stack.
** This buffer must be available until the
** next transmission.
** txBufSize - Size of the buffer in bytes
** Returns :
** --- - Error code, returns ERR_OK if USB
** enumeration has been finished, error code
** otherwise.
** ===================================================================
*/
byte CDC1_App_Task(byte *txBuf, size_t txBufSize)
{
uint8_t i, res;
/* device is Kinetis L2K */
CDC1_RunUsbEngine();
/* 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++;
}
res = CDC1_SendDataBlock(txBuf, i);
if (res!=ERR_OK) {
return res;
}
#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 */
res = CDC1_SendDataBlock(txBuf, 0);
if (res!=ERR_OK) {
return res;
}
}
#endif
} /* if */
return ERR_OK;
} else {
return ERR_BUSOFF; /* USB bus not available yet */
}
}
How the timeout is used: see this project on GitHub:
mcuoneclipse/Examples/FRDM-KL25Z/Freedom_UsbCdc at master · ErichStyger/mcuoneclipse · GitHub
I hope this helps,
Erich