cancel
Showing results for 
Search instead for 
Did you mean: 

Correct procedure to receive data using USB Host library.

KetanP
Associate II

I have Nucleo-64 board acting as a USB Host connected to a CDC-ACM device. I am trying to receive data from this device, my method is as follows

while (1)
{
/* USER CODE END WHILE */
MX_USB_HOST_Process();

/* USER CODE BEGIN 3 */

if (Appli_state==APPLICATION_READY){
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) hUsbHostFS.pActiveClass->pData;

memset(USB_Rx_Buffer, 0, USBH_CDC_BUFFER_SIZE);
Status = USBH_CDC_Receive(&hUsbHostFS, USB_Rx_Buffer, USBH_CDC_BUFFER_SIZE);

if (Status == USBH_OK){

URB_Status = USBH_LL_GetURBState(&hUsbHostFS, CDC_Handle->DataItf.InPipe);

if (URB_Status == URB_IDLE){

(void)USBH_BulkReceiveData(&hUsbHostFS,
CDC_Handle->pRxData,
CDC_Handle->DataItf.InEpSize,
CDC_Handle->DataItf.InPipe);

uint16_t length = USBH_CDC_GetLastReceivedDataSize(&hUsbHostFS);
}


if (URB_Status == URB_DONE){

uint16_t length = USBH_CDC_GetLastReceivedDataSize(&hUsbHostFS);
printf("Received Data Size: %d \r\n", length);

}

 

 


}

}


For first couple of frames, I get full 64Bytes, but later on I just get 2 or 5 bytes. I am not receiving complete data.
I've made sure that sensor is transmitting data properly
I would really appreciate if someone could help me resolve this issue.

1 REPLY 1
FBL
ST Employee

Hi @KetanP 

 

Did you check this example? STM32CubeF4/Projects/STM324xG_EVAL/Applications/USB_Host/CDC_Standalone/Src/main.c

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.