Creating a USB (Virtual) COM port

From RapidSTM32

Jump to: navigation, search

This example teaches how to use the USB Virtual COM Send Block. A system is set up to read potentiometer voltages on Analog Channel 13 (pin C3) and, subsequently, send the data to a host PC via USB Virtual COM port in Ascii (printf) format. The received data is captured and displayed on standard Hyperterminal software.

A virtual COM port is actually a USB port that is configured such that a PC sees it as a serial (COM/RS232) port. A virtual COM port is very useful in situations where your computer does not have a serial port (which is the case for most notebook nowadays) but your software requires serial port communication. In this case you can program your STM32 target to communicate with a PC using serial protocol via USB hardware.

Important!!! For Windows 7, there is a limitation that a packet to be transmitted must be less than 64 bytes in size. For Windows XP, a packet can have larger size than 64 bytes.

Note: this example requires RapidSTM32 to operate in Full-Feature Mode i.e. you must have a FiO board.

Overall system model


Step-by-Step Guide

1. If you have not done so, install STMicroelectronics Virtual COM Driver which is available from either

2. Create a new model and set it to use RapidSTM32 target.

3. Insert Setup System Clocks & SysTick Block, Compile and Download Control Block, ADC Configuration Block, Convert Onboard AN16 Volts to Temp C Block and USB Virtual COM Send Block as shown below.

Creating a model

4. Double click on the USB Virtual COM Send Block and configure it as shown below. Take special note that:

Configure USB Virtual COM Send Block

5. Connect all blocks and update the diagram twice or until all blocks display correct sample time (in this example this is 0.01 sec or 100Hz) as shown below.

Before simulation

6. Initiate the Build Process by Set FiO Std in USB IAP Mode then Build Model.

7. Set FiO Std in Run Custom User Program Mode to run the target.

8. Open Hyper Terminal Program, configure it to correct COM port to observe the generated data stream as shown below.

Captured data stream from Virtual COM with Hyperterminal

Note:

  • The correct Virtual COM port can be determined using Device Manager as shown below.
Virtual COM port
  • Configure the COM port as shown below. For a virtual COM port, the baud rate is irrelevant and can be set to any rate because the PC will automatically manage communication in the background. In this example, we left it at 2400 bps.
Configure COM Port

Download

  1. virtualcom_demo.7z

Related Examples

  1. Your First Matlab/STM32 Program

Personal tools
Namespaces
Variants
Actions
Main Menu
In other languages
Toolbox