STMicroelectronics / STM32CubeF4

STM32Cube MCU Full Package for the STM32F4 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
824 stars 408 forks source link

Sometimes USB transfer data problems occur #141

Closed factoryal closed 1 year ago

factoryal commented 1 year ago

Describe the set-up

Describe the bug I'm testing USB CDC on STM32. The STM32 uses 12Mhz HSE clock, HCLK is 32Mhz. The host PC recognizes the USB device. But sending `"hello world!\n" string repeatedly every about 10ms, the received data by host show message below.

hello world!
hellhello world!
hello world!
hello world!
hello world!
hellhello world!
hello world!
hello world!
hello world!

How To Reproduce

  1. Firmware Package version is 1.27.1 (latest at time)
  2. Only USB and SWD peripherals enabled. (make sure the right clock configuration)
  3. Only this code used on while() loop
    
    #include "usbd_cdc_if.h"
    #include <string.h>

...

while (1) { const char str = "hello world!\n"; CDC_Transmit_FS((unsigned char )str, strlen(str)); HAL_Delay(10); / USER CODE END WHILE /

/* USER CODE BEGIN 3 */

}



**Additional context**
- It also happens when I increase HAL_Delay() to 1000ms.
- It's not a serial terminal error. I tested on Coolterm, Arduino Terminal, node.js serialport package.

**Screenshots**
![image](https://user-images.githubusercontent.com/22570054/188542860-8190d419-2cb4-4975-83af-cc53ed92ef58.png)
![image](https://user-images.githubusercontent.com/22570054/188542869-453f8d70-914f-4bb8-9581-9427c29a4236.png)
factoryal commented 1 year ago

OMG.. I think I resolved this issue. I increased HCLK to 64Mhz and the problem doesn't appears. Why I used 32Mhz is that I first tested on L0 MCU on 32Mhz and it worked well.