cancel
Showing results for 
Search instead for 
Did you mean: 

USB issue STM32F0x with CDC

jaimadafaca
Associate II
Posted on January 28, 2015 at 10:38

Hi,

I�m newbie in USB projects with STM32, so I kindly ask your help to find what I�m doing wrong with STM32F072 and CDC USB.

For now, I�m trying to send some chars through USB form microcontroller to USB PC with �CDC_Transmit_FS(string,8);� command.

The problem is that if I send more that 8 bytes at the same time  (same command), then I receive garbage chars on host.

If I send 8 or less, seems to work fine.

Here is my code of �CDC_Transmit_FS� routine:

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)

 

{

 

  uint8_t result = USBD_OK;

 

  /* USER CODE BEGIN 8 */

 

   uint16_t i;

 

  for(i=0;i<Len;i++)

 

  {

 

      UserTxBufferFS[i]=Buf[i];

 

  }

 

  USB_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, Len); 

 

  result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);

 

  /* USER CODE END 8 */

 

  return result;

 

}

I have checked (as far as I know) till :  �HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)� and it seems that pointer of buffer is pointing to right data (no garbage)

Am I doing something wrong?  Something missed?

My  version files of CubeMX are:

* @file           : usbd_conf.c

* @date           : 09/12/2014 10:39:27  

 * @version        : v1.0_Cube

* @file           : USB_DEVICE

* @date           : 09/12/2014 10:39:27 

* @version        : v1.0_Cube

 * @file           : usbd_conf.c

 * @date           : 09/12/2014 10:39:27

 * @version        : v1.0_Cube

 * @file    usbd_cdc.c

* @version V2.2.0

 * @date    13-June-2014

 * @file           : usbd_cdc_if.c

* @version        : V1.1.0

 * @date           : 19-March-2012

 * @file    usbd_core.c

 * @version V2.2.0

 * @date    13-June-2014

Any help will be appreciated.

Thanks in advance,

Best regards.

Jai 

#stm32f0-usb-cdc-library
2 REPLIES 2
tsuneo
Senior
Posted on January 28, 2015 at 16:38

Sound like the same problem - endpoint buffer assignment - as this topic,

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32L0%20USB%20CDC%20VCP%20Transmit%20problems

Manually add these extra lines to usbd_conf.c, USBD_LL_Init()

usbd_conf.c
#include ''usbd_cdc.h'' // <-- add this line for CDC_OUT_EP, CDC_IN_EP, CDC_CMD_EP macros
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
{
...
...
// <-- add these 3 lines
HAL_PCDEx_PMAConfig(pdev->pData , CDC_OUT_EP , PCD_SNG_BUF, 0x100);
HAL_PCDEx_PMAConfig(pdev->pData , CDC_IN_EP , PCD_SNG_BUF, 0x110);
HAL_PCDEx_PMAConfig(pdev->pData , CDC_CMD_EP , PCD_SNG_BUF, 0x150);
return USBD_OK;
}

Hmm, This problem has already fixed on the recent CubeMX v4.60 and FW_F0 V1.2.1 Tsuneo
jaimadafaca
Associate II
Posted on January 29, 2015 at 11:55

Thanks a lot !!   Now seems to work fine.

Regards

Jai