Skip to main content
vekli
Associate II
June 26, 2022
Question

Bug STM32F405 USB HOST CDC

  • June 26, 2022
  • 5 replies
  • 1560 views

STM32CubeMX v6.5.0 

STM32Cube FW_F4 V1.27.0

USB_FS HOST CDC

usbh_cdc.h

function static void CDC_ProcessReception(USBH_HandleTypeDef *phost)

line 767

 if (((CDC_Handle->RxDataLength - length) > 0U) && (length > CDC_Handle->DataItf.InEpSize))

fix:

 if (((CDC_Handle->RxDataLength - length) > 0U) && (CDC_Handle->RxDataLength > CDC_Handle->DataItf.InEpSize))

This topic has been closed for replies.

5 replies

vekli
vekliAuthor
Associate II
June 26, 2022

Yes. You are right line 754.

Error because length = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe);

and then we compare length > CDC_Handle->DataItf.InEpSize It never happens because max length is InEpSize, readings stops after first read, if you run USBH_CDC_Receive with buffer size bigger then max endpoint packet size then it will read only first packet and then reading will be stopped..

I guess that comparison needed for analyze how many bytes left for read CDC_Handle->RxDataLength

Becasue USB wok on packet basis we will continue reading if number of left bytes bigger then maximum packet size in other case we should stop reading.

Pavel A.
Super User
June 26, 2022

Ah, I see. length is the last received size, and it cannot be > endpoint size.

But it can be less than the EP size, this means a short packet or ZLP, which ends the transfer.

So probably should be:

 if (((CDC_Handle->RxDataLength - length) > 0U) && (length == CDC_Handle->DataItf.InEpSize))
{
 //continue receiving
}
else
{
 // end transfer
}

@Hana Slimi​  what do you think?

vekli
vekliAuthor
Associate II
June 27, 2022

I just shared my experience. In my project bug fixed with if (((CDC_Handle->RxDataLength - length) > 0U) && (CDC_Handle->RxDataLength > CDC_Handle->DataItf.InEpSize))

If you will use length == CDC_Handle->DataItf.InEpSize then you will continue reading even if requested length == InEpSize but reading should be stopped it that case.

KDJEM.1
Technical Moderator
October 21, 2022

Hello @vekli​,

 

I reported this issue internally. 

Thank you for your contribution.

 

Internal ticket number: 137249 (This is an internal tracking number and is not accessible or usable by customers).

 

Kaouthar

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.
KDJEM.1
Technical Moderator
December 10, 2025

Hello;

The fix is:

if (((CDC_Handle->RxDataLength - length) > 0U) && (length == CDC_Handle->DataItf.InEpSize))

This issue is fixed: stm32-mw-usb-host/Class/CDC/Src/usbh_cdc.c at master · STMicroelectronics/stm32-mw-usb-host · GitHub

 

Thank you.

Kaouthar

 

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.