Library 24- Virtual COM Port (VCP) for STM32F4

This library provides Virtual COM port on USB OTG. This means, that you don’t need external USB->UART converter (like FTDI) to communicate with computer. STM32F4xx will be seen to computer like COM port.

Library can be used on all STM32F4xx devices. It has also features to support STM32F4- and STM32F429 Discovery boards.

To use USB with HAL, check my HAL USB library.

Library

Features

  • Enables USB VCP
  • Works in USB FS mode
    • Default for STM32F4-Discovery board
  • Works in USB HS in FS mode
    • Default for STM32F429-Discovery board
  • Version 1.2 – March 08, 2015
    • Added options to detect if user has changed parameters in terminal (baudrate, stop bits, data bits, parity) in case you are doing USB<->UART converter

Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx EXTI
    • MISC
  • TM
    • defines.h
  • USB
    • USB CDC device stack provided by STMicroelectronics (included in library)





Pinout

As 2 options can be used, there are 2 pinouts:

USB FS Mode HS in FS Mode Description
Data + PA12 PB15 USB Data+ line
Data – PA11 PB14 USB Data- line
ID PA10 PB12 USB ID pin
VBUS PA9 PB13 USB activate

Notes:

  • STM32F4-Discovery has micro USB connected to USB FS mode
  • STM32F429-Discovery has micro USB connected to USB HS in FS mode
  • If you have USB->4 wires cable, you can connect both boards in both ways, but then you don’t have fancy connected.
  • Clock for STM32F429 was set down to 168MHz, because you can not get 48MHz for USB with 180MHz core clock

By default, library is set in FS mode, so pins PA11 and PA12 are in use. If you are working with STM32F429 Discovery board and you want to use microUSB connector instead of wires on pinheaders, then open your defines.h file and activate USB HS in FS mode:

You are now working in HS mode.

Default internal buffer size for received data is 128bytes. If you need more, you can set more in defines.h file using specific define:

When you connect board to USB to computer, there will be new COMx seen. For that, you also need USB VCP drivers provided by STMicroelectronics.

Note: In your terminal are options to set baudrate, stop bits, etc. Leave that at it is, these settings don’t care, because everything is configured by USB.

Precompiled versions

Some users has issues with setting project (example below) correctly (don’t know why) and I have precompile long time ago 2 versions of example for F4-Disco and F429-Discovery boards. This is now available here for download.

These examples has positive feedbacks as they work ok.

Download here.

Functions and enumerations

I have written some basic functions to work with data.

Example

USB VCP on STM32F4xx

USB VCP on STM32F4xx

I have used STM32F4-Discovery for this example with default settings, because STM32F4-Discovery has micro USB connected to FS mode (default mode).

View project on Github, download library below.

 

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!