MWP

HAL USB CDC/VCP - USBD_CDC_ReceivePacket() BUG

Discussion created by MWP on Oct 26, 2017
Latest reply on Oct 28, 2017 by Ben K

Hi all,

 

I've identified an issue with the HAL USB CDC/VCP library.

STM32Cube_FW_F0_V1.9.0 with a STM32F070.

 

CDC_Receive_FS() is called when a data packet is received.

At the end of this function USBD_CDC_ReceivePacket() is called to setup the endpoint for the next transmission.

USBD_CDC_ReceivePacket() then calls USBD_LL_PrepareReceive().

 

There is no mechanism in USBD_CDC_ReceivePacket() to handle or pass-on the returned sate of USBD_LL_PrepareReceive().

 

If USBD_LL_PrepareReceive() returns BUSY, the endpoint is never setup.

There is no way for the application code in CDC_Receive_FS() to know this has happened.

 

This needs to be fixed.

 

Ive modfied the function to the following:

USBD_StatusTypeDef USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
{
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;

/* Suspend or Resume USB Out process */
if(pdev->pClassData != NULL)
{
if(pdev->dev_speed == USBD_SPEED_HIGH )
{
/* Prepare Out endpoint to receive next packet */
return USBD_LL_PrepareReceive(pdev,
CDC_OUT_EP,
hcdc->RxBuffer,
CDC_DATA_HS_OUT_PACKET_SIZE);
}
else
{
/* Prepare Out endpoint to receive next packet */
return USBD_LL_PrepareReceive(pdev,
CDC_OUT_EP,
hcdc->RxBuffer,
CDC_DATA_FS_OUT_PACKET_SIZE);
}
return USBD_OK;
}
else
{
return USBD_FAIL;
}
}

Outcomes