USB CDC Device in STM32F429-Start (VCP)Virtual Com port

  • 380
  • 0

This article use  CubMX and CubeIDE to open VCP very easily ! 
快速開啟你的STM32 VCP功能

First time we start to use STM32, it's obviously that serial port communication is very important and basic step to start every application.

This article will teach you how to enable CDC(Communication Device Class) and start your first com port device!
So the first step we need to know the concept of CDC.
 

CDC is kind of serial Bus defined by USB2.0 so that we can use CDC to establishe the communication connect with a lot of device via USB port easily~ 
BTW, there are so many kind of device type defined in USB2.0:

  • Mass-storage class(MSC)
  • Human interface mouse and keyboard class(HID)
  • Communication device class(CDC)
  • Audio class(AUDIO)
  • Media Transfer protocol class(MTP)
Figure1 Showing the relevance between USB2.0、CDC、PSTN

 

As seen in Figure1  when we want to connect to arm device and transfer/recive some date, CDC is our solution.

Next, the flow chart shows CDC work architecture:

Figure2. Usb device library

 

Figure2 shows cdc_if.c is kind of user interface to implement the CDC connect and there are a lot of lower level library to handle detail connection.
Also, the device core take care the standard enumeration of device connetion/disconnection management and the device class give the API which can be called from an application layer or device core process.

After basic introduction,  let's start our CDC project with cubeIDE (or you can use cubeMX):

Selet your device to start, same with CubeMX:

Setup project, same with CubeMX:

Now we can see the pinout view, same with CubeMX.

To setup CDC connection, you need to enable :

  1. RCC:Device clock, usb data neet the time to Tx/Rx data.
  2. USB_OTG_FS|USB_OTG_HS:USB data sending mode.
  3. USB_DEVICE:USB device type.

RCC:

Choose crystal/Ceramic Resonator when your board have clock, or use BYPASS Clock Source as external clock.

 USB_OTG_FS|USB_OTG_HS:
FS/HS is Full Speed and High Speed, depend on you.

USB_DEVICE:

To communicate with your device, use Communication Device Class(CDC) 

Now, check out to the Clock Configuration:

 

And Gen-code:

Build the project and open DEVMGMT.MSC:

And let us wait….. the com port should pop up….

 

BUT NOTHING HAPPENED!!!!

Why?? I don't know!!???

I study a lot of databrief and videio, they all do the same thinga as I do!

Why me!?

I can't figure out and I start to search others project to see what's the diffrent.

Finally, I find a method …

STM32F429 USB_OTG_HS mode and internal FS Phy select Device_Only can work!!

Why? I still don't know but it works….

 

I stock here 2 weeks and I think this article can help you!
If you have any idea, welcome to contect me!

 

Dean
Senior Software Engineer / Network Security Engineer
Feel free to contact me: t104318516@ntut.org.tw

Interest: Reverse Engineering, Binary Analysis, Network Protocol, Cyber Security, Digital communication.