2017-10-24 11:47 PM
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;}#usb-device #stm32_usb_device_library #usb-implementation #usb-fs #usb-stm32f4Solved! Go to Solution.
2017-10-29 10:07 PM
Hi,
It has been solved while porting I have not added HAL_PCD_EP_Receive in USBD_SetClassConfig function, which as per @ben k initiates data reception.
Thank you
2017-10-28 01:49 AM
The HAL_PCD_EP_Receive() API initiates data reception through an endpoint to the specified RAM location with the maximum length. The HAL_PCD_EP_GetRxCount() API returns the actually received data's size after the completion of the endpoint transfer.
You first have to initiate a reception, then when the DataOutStage is called, you already have the data in your buffer, you only need to determine the actual length to process the data. After it is done, you can initiate another reception.
2017-10-29 10:07 PM
Hi,
It has been solved while porting I have not added HAL_PCD_EP_Receive in USBD_SetClassConfig function, which as per @ben k initiates data reception.
Thank you