AnsweredAssumed Answered

STM32 USB device : First data byte always missing after device initialization and enumeration

Question asked by ritesh unde on Oct 25, 2017
Latest reply on Oct 30, 2017 by ritesh unde

Hi,

I am using STM32F401RE. For my USB device application I used DFU class stack from STM32cube mx.

I have ported stack to my application,It is working fine but I always misses first byte received after initialization of USB device and subsequent enumeration.

 

HAL_PCD_EP_GetRxCount returns correct number bytes but HAL_PCD_EP_Receive gives no data.

 

Following is code snippet of DATA out stage :

 

volatile unsigned char rite_14[68];
volatile unsigned int rite_11=0;

 

USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata)
{
USBD_EndpointTypeDef *pep;

unsigned int rite_12=0;

if(epnum == 0)
{
pep = &pdev->ep_out[0];

if ( pdev->ep0_state == USBD_EP0_DATA_OUT)
{
if(pep->rem_length > pep->maxpacket)
{
pep->rem_length -= pep->maxpacket;

USBD_CtlContinueRx (pdev,
pdata,
MIN(pep->rem_length ,pep->maxpacket));
}
else
{
if((pdev->pClass->EP0_RxReady != NULL)&&
(pdev->dev_state == USBD_STATE_CONFIGURED))
{
pdev->pClass->EP0_RxReady(pdev);
}
USBD_CtlSendStatus(pdev);
}
}
}
else if((pdev->pClass->DataOut != NULL)&&
(pdev->dev_state == USBD_STATE_CONFIGURED))
{
//pdev->pClass->DataOut(pdev, epnum); not requred

if(epnum == 0x02)// My application endpoint number
{


rite_11 = HAL_PCD_EP_GetRxCount(pdev->pData, epnum);

rite_12 = HAL_PCD_EP_Receive(pdev->pData, epnum, rite_14, rite_11);

EP2_Handler(rite_14, rite_11);// appliaction layer processing
}

}
return USBD_OK;
}

Outcomes