AnsweredAssumed Answered

STM32CubeF0 bugreport (HAL, USB, VCP)

Question asked by porfiryev.denis on Aug 6, 2014
Latest reply on Oct 20, 2014 by Montassar BEN ROMDHANE
Bug 1:

typedef struct
  PCD_TypeDef             *Instance;   /*!< Register base address              */
  PCD_InitTypeDef         Init;       /*!< PCD required parameters            */
  __IO uint8_t            USB_Address; /*!< USB Address            */ 
  PCD_EPTypeDef           IN_ep[5];  /*!< IN endpoint parameters             */
  PCD_EPTypeDef           OUT_ep[5]; /*!< OUT endpoint parameters            */
  HAL_LockTypeDef         Lock;       /*!< PCD peripheral status              */
  __IO PCD_StateTypeDef   State;      /*!< PCD communication state            */
  uint32_t                Setup[12];  /*!< Setup packet buffer                */
  void                    *pData;      /*!< Pointer to upper stack Handler     */   
} PCD_HandleTypeDef;

Here is a typo. Size of IN_ep and OUT_ep must be 15 (or at least not less than hpcd_USB_FS.Init.dev_endpoints).

After I send more than 6-8 bytes per packet at once from or to MCU, PC starts to receive rubbish instead of data sent by MCU.
I've discovered usbd_conf.c/USBD_LL_Init() configures data buffer pointers
HAL_PCDEx_PMAConfig(pdev->pData , 0x00 , PCD_SNG_BUF, 0x18);
HAL_PCDEx_PMAConfig(pdev->pData , 0x80 , PCD_SNG_BUF, 0x58);
but not sets them for CDC_IN_EP (0x81) and CDC_OUT_EP (0x01).
I've replaced this code by the following and that fixed the problem:
HAL_PCDEx_PMAConfig(pdev->pData , 0x00 , PCD_SNG_BUF, 0x18+0*USB_FS_MAX_PACKET_SIZE);
HAL_PCDEx_PMAConfig(pdev->pData , 0x80 , PCD_SNG_BUF, 0x18+1*USB_FS_MAX_PACKET_SIZE);
HAL_PCDEx_PMAConfig(pdev->pData , 0x01 , PCD_SNG_BUF, 0x18+2*USB_FS_MAX_PACKET_SIZE);
HAL_PCDEx_PMAConfig(pdev->pData , 0x81 , PCD_SNG_BUF, 0x18+3*USB_FS_MAX_PACKET_SIZE);

After about 20-30 packets PC receives data it sent instead of data MCU replied with.