2019-01-07 03:30 AM
Hello,
STM32CubeMx for the CDC Host mode, there seems to be a problem in the "static void CDC_ProcessReception (USBH_HandleTypeDef * phost)" function of the "usbh_cdc.c" file if we use the "USBH_CDC_Receive" function (USBH_HandleTypeDef * phost, uint8_t * pbuff , uint32_t length) "with length> wMaxPacketSize (here 64).
Indeed, in the line 36 :
/**
* @brief This function responsible for reception of data from the device
* @param pdev: Selected device
* @retval None
*/
static void CDC_ProcessReception(USBH_HandleTypeDef *phost)
{
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData;
USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
uint32_t length;
switch(CDC_Handle->data_rx_state)
{
case CDC_RECEIVE_DATA:
USBH_BulkReceiveData (phost,
CDC_Handle->pRxData,
CDC_Handle->DataItf.InEpSize,
CDC_Handle->DataItf.InPipe);
CDC_Handle->data_rx_state = CDC_RECEIVE_DATA_WAIT;
break;
case CDC_RECEIVE_DATA_WAIT:
URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.InPipe);
/*Check the status done for reception*/
if(URB_Status == USBH_URB_DONE)
{
length = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe);
if(((CDC_Handle->RxDataLength - length) > 0U) && (length > CDC_Handle->DataItf.InEpSize))
{
CDC_Handle->RxDataLength -= length ;
CDC_Handle->pRxData += length;
CDC_Handle->data_rx_state = CDC_RECEIVE_DATA;
}
else
{
CDC_Handle->data_rx_state = CDC_IDLE;
USBH_CDC_ReceiveCallback(phost);
}
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_CLASS_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL);
#endif
#endif
}
break;
default:
break;
}
}
We see that the test "(length> CDC_Handle-> DataItf.InEpSize)" is never true because "length" is always less than or equal to (actually equal to) "InEpSize" which is initialized with "wMaxPacketSize", here 64 .
It would probably be necessary to change the test for "... && (length == CDC_Handle-> DataItf.InEpSize))" or "... && (length> = CDC_Handle-> DataItf.InEpSize))"
2020-10-21 05:18 AM
Hey I just had a similar thought. Did you confirm this as a problem in the end?
Also I notice that USBH_BulkReceiveData uses CDC_Handle->DataItf.InEpSize as a size but with CDC_Handle->pRxData as buffer so would this require
USBH_CDC_Receive to be called with length a multiple of CDC_Handle->DataItf.InEpSize?