0
votes

I try to implement USB CDC FS on the discovery Board from STM. But it is really frustrating.

I created a project via Cube MX with the HAL libraries. At the end I want a data rate near 500 kByte/s. Till now I can see my device in the device manager but really often I cannot open the com port in Hterm. Hterm is only not responding.

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */
      CDC_Transmit_FS(buf, 300);
      HAL_Delay(1);
  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}

I initialise the clocks correctly. Maybe the virtual com port driver cannot buffer the high amount of data they are comeing from the MCU?! If I increase the delay time in the while loop, sometimes I can open the com port and get the data. The highest data rate I got were about 70 kByte/s. Too less:(

Are there any known bugs in the software? I already increased the heap and stack sizes, but it didn't fix the problem.

Thanks for help,

1

1 Answers

0
votes
  1. Check the following two points,

    1) Set "wMaxPacketSize" to 64 from 2 (or any value) in USB CDC device Configuration Descriptor for Endpoint IN Descriptor in usbd_cdc.c file. The maximum endpoint size for Full speed usb is 64 bytes.

    2) Increase the HCLK and you should see higher data rate.

    CDC speed depends on many factors unlike HID where you have guaranteed data rate. CDC is the fastest if and only if bus is free with theoretical speed of 1.5 MB/s. I have used STM32F7 disco board and managed to achieve 500+ KB/s data rate with HCLK 120MHz just a week ago.

    NOTE: Do check the USB clock frequency is set to 48MHz else its difficult to get it work.

Wish you good luck.

Regards,

Jagadeep.