cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F USB Firmware (cdc class driver) bug (64 byte transfers from device to host)

mikael239955_stm1
Associate
Posted on March 21, 2013 at 10:46

Hi,

64 byte transfers from my STM32F4 cdc driver to the host side fails. 63 bytes work, as well as 65 bytes.

A quick forum search indicates that this is a bug in the cdc class driver firmware. A 64 byte transfer should be followed by a 0-byte transfer so that the host side (windows) can detect end of transfer. So, this bug is known but I have so far failed to find a fix for it. Does anyone know how to fix it - or is there a firmware library out there somewhere where this is fixed already?

Currently I'm using

''STM32_USB-Host-Device_Lib_V2.1.0'', V1.1.0 / 19-March-2012

Best regards,

Mikael
2 REPLIES 2
tyronexj
Associate II
Posted on March 22, 2013 at 10:04

Hi Mikael,

I am working with USB VCP example recently.

I am not sure whether following modification could fix the bug.

/**

  * @brief  Handle_USBAsynchXfer

  *         Send data to USB

  * @param  pdev: instance

  * @retval None

  */

static void Handle_USBAsynchXfer (void *pdev)

{

  uint16_t USB_Tx_ptr;

  static uint16_t USB_Tx_length = 0;

 

  if(USB_Tx_State != 1)

  {

    if (APP_Rx_ptr_out == APP_RX_DATA_SIZE)

    {

      APP_Rx_ptr_out = 0;

    }

    

    if(APP_Rx_ptr_out == APP_Rx_ptr_in)

    {

      if(USB_Tx_length == CDC_DATA_MAX_PACKET_SIZE)

      {

        USB_Tx_length = 0;

      }

      else

      {

        USB_Tx_length = 0;

        USB_Tx_State = 0;

        return;

      }

    }

    else if(APP_Rx_ptr_out > APP_Rx_ptr_in) /* rollback */

    {

      APP_Rx_length = APP_RX_DATA_SIZE - APP_Rx_ptr_out;

    

    }

    else

    {

      APP_Rx_length = APP_Rx_ptr_in - APP_Rx_ptr_out;

     

    }

#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED

     APP_Rx_length &= ~0x03;

#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */

    if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE)

    {

      USB_Tx_ptr = APP_Rx_ptr_out;

      USB_Tx_length = CDC_DATA_IN_PACKET_SIZE;

      

      APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE;

      APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE;

    }

    else

    {

      USB_Tx_ptr = APP_Rx_ptr_out;

      USB_Tx_length = APP_Rx_length;

      

      APP_Rx_ptr_out += APP_Rx_length;

      APP_Rx_length = 0;

    }

    USB_Tx_State = 1;

    DCD_EP_Tx (pdev,

               CDC_IN_EP,

               (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr],

               USB_Tx_length);

  }

}

Best regards,

Tyrone

tyronexj
Associate II
Posted on March 22, 2013 at 10:58

Sorry,

usbd_cdc_DataIn() also calls DCD_EP_Tx(CDC_IN_EP), then static uint16_t USB_Tx_length = 0 should be seen in the whole file.

Best regards,

Tyrone