Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

c - STM32 USB VCP (Virtual Com Port)

I generated a code for "stm32f103c8t6" with CubeMX for USB VCP, when I add "CDC_Transmit_FS" command to send data, the port isn't recognized by windows10! what should I do? Here is the code which is compiled without error:

#include "stm32f1xx_hal.h"
#include "usb_device.h"
#include "usbd_cdc_if.h"

int main(void)
{
  uint8_t Text[] = "Hello
";
  while (1)
  {
    CDC_Transmit_FS(Text,6); /*when commented the port is recognized*/
        HAL_Delay(1000);
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are three things you need to check in my experience:

  1. startup_stm32f405xx.s --> Increase the Heap size. I use heap size 800 and stack size 800 as well.
  2. usbd_cdc_if.c --> APP_RX_DATA_SIZE 64 and APP_TX_DATA_SIZE 64
  3. usbd_cdc_if.c --> add below code to the CDC_Control_FS() function

Code:

case CDC_SET_LINE_CODING:
  tempbuf[0]=pbuf[0];
  tempbuf[1]=pbuf[1];
  tempbuf[2]=pbuf[2];
  tempbuf[3]=pbuf[3];
  tempbuf[4]=pbuf[4];
  tempbuf[5]=pbuf[5];
  tempbuf[6]=pbuf[6];
  break;
case CDC_GET_LINE_CODING:
  pbuf[0]=tempbuf[0];
  pbuf[1]=tempbuf[1];
  pbuf[2]=tempbuf[2];
  pbuf[3]=tempbuf[3];
  pbuf[4]=tempbuf[4];
  pbuf[5]=tempbuf[5];
  pbuf[6]=tempbuf[6];
  break;

and define the uint8_t tempbuf[7]; in the user private_variables section.

Without the increased heap size, Windows does not react at all. Without the point 3, Windows will send the baud rate information and then read the baud rate, expecting to get back the same values. Since you do not return any values, the virtual com port remains as driver-not-loaded.

If you do all of that, the Windows 10 out-of-the-box VCP driver can be used. No need to install the very old ST VCP driver on your system.

PS: I read somewhere turning on VSense makes problems, too. Don't know, I have not configured it and all works like a charm.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...