I’m testing a USB CDC example on STM32F407IGH
generated by STM32CubeMX
. The Stm32 device is correctly recognized by the PC system as STMicroelectronics Virtual COM Port
but has warring
This device cannot start. (Code 10)
{Device Timeout}
The specified I/O operation on %hs was not completed before the time-out period expired.
The corresponding serial port also cannot be opened by the Serial Debug Assistant.
What I expected:
My goal is to establish data communication between STM32 and PC through built-in USB port, as a more convenient alternative of UART.
In this program, STM32 should establish communication to Serial Debug Assistant. If I add
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
CDC_Transmit_FS(Buf, *Len); //loopback
...
It’s COM port should echo what I’ve send.
Following are Details:
Environment and drivers:
Windows11-22631.3447
STMicroelectronics Virtual COM Port 1.4.0.0 x64
(I’ve tried using Microsoft’s generic driver, but the result is the same)
Program setting:
All the results in this post are reproduced in a clean MDK-ARM project generated by CubeMX.
USB_OTG_FS
is configured as device_only
mode (default setting: PA11&PA12, 48MHz
clocks).
USB_DEVICE
IP mode for FS is C.D.C.
.
The minimum stack/heap size is expanded to 0x4000
/ 0x2000
.(I’ve tried other scales, didn’t work)
I have supplemented the CDC_SET_LINE_CODING
and CDC_GET_LINE_CODING
in "usbd_cdc_if.c"
.
/* USER CODE BEGIN PRIVATE_VARIABLES */
USBD_CDC_LineCodingTypeDef LineCoding =
{
115200, /* baud rate*/
0x00, /* stop bits-1*/
0x00, /* parity - none*/
0x08 /* nb. of bits 8*/
};
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
.
.
.
case CDC_SET_LINE_CODING:
LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |
(pbuf[2] << 16) | (pbuf[3] << 24));
LineCoding.format = pbuf[4];
LineCoding.paritytype = pbuf[5];
LineCoding.datatype = pbuf[6];
break;
case CDC_GET_LINE_CODING:
pbuf[0] = (uint8_t)(LineCoding.bitrate);
pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8);
pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16);
pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24);
pbuf[4] = LineCoding.format;
pbuf[5] = LineCoding.paritytype;
pbuf[6] = LineCoding.datatype;
break;
code generation is all fine.
reference:stackoverflow
Hardware connection:
STlink debugger to PA13&PA14 and MricoB port on PA11&PA12 connected to PC USB without adapter.
Report captured by USB Device Tree Viewer:
...
----------------- Device Qualifier Descriptor -----------------
Error : ERROR_GEN_FAILURE (because the device has problem code CM_PROB_FAILED_START)
-------------------- String Descriptors -------------------
String descriptors are not available (because the device has problem code CM_PROB_FAILED_START)
puwen H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.