cancel
Showing results for 
Search instead for 
Did you mean: 

Bug STM32F405 USB HOST CDC

vekli
Associate II

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))

5 REPLIES 5
vekli
Associate II

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.

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
Associate II

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
ST Employee

Hello @vekli​,

I reported this issue internally. 

I will get back to you with more details as soon as possible.

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.