Skip to main content
Associate
April 3, 2025
Question

Correct procedure to receive data using USB Host library.

  • April 3, 2025
  • 1 reply
  • 402 views

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

ST Technical Moderator
April 10, 2025
To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL