Change the world

*** Read the notice at the bottom of this page ***

Often one needs to establish a serial communications link between a microcontroller and an application on a PC via a serial (COM) port.  This could be to simply display values of sensors from the microcontroller or for debug information when a LCD is not available or if it is too much effort to connect the LCD.  The solution would then be to use the microcontroller's UART module for the communication and the to use a COM port monitor program on the PC (see the UART example section).  The only issue with this is that you will require additional hardware on the microcontroller side to shift the input and output voltages to the correct levels.  This method is also further complicated by the fact that most modern PCs do not have physical COM ports, in which case you would have to use a USB-to-COM cable/module.

Fortunately the STM32F3-Discovery has a User USB mini connector which is connected to the STM32F303VCT6's USB 2.0 Full Speed Interface.  The STM32F3-Discovery can then be programmed to emulate a standard serial port - called a Virtual COM Port (VCP).  This requires no additional hardware and only requires an extra mini-USB cable for the communication.  You would then use a COM Port Monitor software application on the PC which will display all messages coming from the microcontroller via the serial link and will also allow you to send data via the serial link to the microcontroller.  A typical layout for the system would then look like this:



First time use instructions

In order to use the examples for the first time, you will need to do the following:

  1. Copy the contents of the VCP file over the existing files in the Demonstration project folder.
  2. Copy the contents of the Examples - file into the Demonstration project folder.
  3. Load the demonstration project in uVision and replace the main.c with ex1_VCP_Halloworld.c
  4. Plug the programming cable into the STM32F3-Discovery board.
  5. Compile the project and program the board.
  6. Plug an additional mini-USB cable into the User USB and an open USB port on the PC.
  7. Press the BLUE button on the F3 board.
  8. Windows will detect that there is new hardware available and will try and get the driver from Windows Update.  Cancel this and manually install the driver in VCP
  9. Once the driver is installed correctly, Windows will go and create a new COM port in the Device Manager.  Remember what port number this is, because this is now the Virtual COM Port (e.g. COM12)


Using COM Port Monitor Software

To see what message are sent from the STM32F3-Discovery, you will need COM Port Monitor Software on the PC.  Termite is a very usefull example of such a program and can be downloaded for free from

  1. Install Termite and run it.
  2. In Settings, select the port number where the VCP was created
  3. Change the Baud rate to 115200
  4. Make sure "Append LF" is ticked.
  5. Leave everything else as is and click OK
  6. Termite will now open the COM port for communication.
  7. Clicking on the COM button in the top left corner will disconnect the communications.
  8. Press reset on the F3-Board.
  9. You will hear the disconnect sound of a USB device and shortly after that the connect sound again.
  10. Click on COM buttion in the top left again and it will connect the communications again.
  11. Press the BLUE button on the F3-board.
  12. The display should now display "Hallo World" and then start counting.


Resetting and Programing the F3 board

There is a slight issue when you reprogram the F3 board with new code or press the reset button while it is connected in Termite.  Because you are resetting the device, it effectively removes the USB COM port.  Termite unfortunately cannot detect this and will hang.  You will then have to close Termite, reset the F3 board, start Termite, press the BLUE button.  To prevent this, follow the following guidelines when doing development work while using the VCP.

  1. If you are about to reset the STM32F3-Discovery board or program it with new source code, then disconnect the COM port in Termite.
  2. Program the F3 board with the new code
  3. Wait for the disconnect sound and connect sound again.
  4. Connect the COM port in Termite again.
  5. Press the BLUE user button on the F3 board.
  6. Repeat steps 1 - 5 everytime you make changes to your code and want to reprogram your device.

In Termite under Settings there is a very usefull option "Stay on top" which could be enabled.  This will keep Termite in the foreground permanantly to easy the disconnected and connecting process.

Also note that the BLUE user button on the STMF3-Discovery board is simply used to allow the user to connect to the COM in Termite first before the actual program in the source is started.  You can take this out of the code if you want to.  See the comments in the source code for more detail.



Use two USB cables when using the Virtual COM Port with the STM32-F3 Discovery board - one for the ST-LINK V2 programmer and the other for the User USB port for the VCP communications.  Make sure the VCP cable is plugged into the User USB port and the PC before you program/reprogram the board.  Failing to do this, Keil uVision will display an "Internal Error" when trying to program/reprogram the board.  The only way to recover from this is to load the ST-Link Utility, connect to the programmer, and then to erase the chip.


The following example programs are available to demonstrate the basic principles of using the Virtual COM Port (VCP):


Example program that uses the STM32F3-Discovery board as a Virtual COM Port (VCP) module to write "Hello World!" serially to a PC's COM port and then display a count from 0 to 255 repeatedly. Run a program called Termite ( to use as a RS-232 terminal on the PC to see what messages are sent to the PC, and to send messages to the STM32F3-Discovery.

* Mini-USB cable from the User USB port on the STM32F3-Discovery to a USB port on a PC



Example program that demonstrates the use of input messages from the PC via a serial link created by a Virtual COM Port.

* Mini-USB cable from the User USB port on the STM32F3-Discovery to a USB port on a PC