Creating a USB (Virtual) COM port
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.
1. If you have not done so, install STMicroelectronics Virtual COM Driver which is available from either
- RapidSTM32 directory (from rapidstm32rootdirectory\st\Virtual COM Port driver e.g. C:\rapidstm32\st\Virtual COM Port driver)
4. Double click on the USB Virtual COM Send Block and configure it as shown below. Take special note that:
- Set Mode to Ascii
- Set printf format to 'Onboard Temperature = %2.1f degC; Potentiometer Voltage = %1.3f\r\n'.
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.
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.
- The correct Virtual COM port can be determined using Device Manager as shown below.
- 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.