Skip to main content
Visitor 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

    vekliAuthor
    Visitor 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.

    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?

    vekliAuthor
    Visitor 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.

    Technical Moderator
    October 21, 2022

    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

    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