Example 2:
PuTTY and the Virtual Comm Port

In the first example we created a small program that allowed us to make some LEDs blink.  As exciting as that is, four LEDs do now give a whole lot of feedback as to what is happening.  To get more detailed information, I turn to the humble Serial Terminal.

One nice feature of the ST32F4-DISCOVERY is the USB port located on the board.  This is a classified as a USB-OTG or USB On-The-Go port.  The OTG function has the ability to be either a host (as in you can connect peripherals to it, such as a mouse, keyboard, USB drive) or a client (the board itself becomes the peripheral).  The function we are interested in is the VCP or Virtual Comm Port function.  This feature allows us to link the board to a computer as a serial port allowing us to easily send streams of data.  In this example we will send a continuous stream of text, “Hello World!”, to the computer.

Before we get started, you will need two extra things:  a Micro-USB cable (the type most cell phones use) and a Serial Terminal application.  Most people have MIcro-USB cables laying around, so we won’t bother with that too much.  As for a Serial Terminal, I use a free program called “PuTTY”.

INSTALLING PUTTY

PuTTY is a free application that allows you to connect with other devices/computers via Telenet, SSH and Serial Ports.  It is the last one we are concerned with.  If you need a copy of PuTTY, you can down load it from this website.

PuTTY Download

PuTTY does not need to be installed and can be run from almost anywhere on your computer.  I save the “putty.exe” file directly on my desktop and run it from there.  PuTTY also requires some configuration to make work properly but we currently don’t have the necessary information yet.  We will configure PuTTY after we program the ST32F4-DISCOVERY board.  (The PuTTY configuration instructions will be at the bottom of this article.)

CREATING A VIRTUAL COMM PORT

The first thing you need to do is connect your STM32F4-DISCOVERY board to you computer.. Again, this connection is via the programming Mini-USB port located at the top of the board.

Startup the Arduino application and verify that the board and port options are correctly set.

Enter the following code into the Ardunio window.

/*
 * STM32F4-DISCOVERY
 * Example 2:  Virtual Comm Port
 */

// Declare the USB connection.
USBSerial USB;

void setup() {
  // put your setup code here, to run once:

  // Initialize the USB port and speed.
  // I am using a slow speed so that the text is displayed at a manageable rate.
  USB.begin(1200);
}

void loop() {
  // put your main code here, to run repeatedly:

  // Send the text through the USB via a VCP port.
  USB.print("Hello World.....");

  // Wait a little so that we don't overfill the transmit buffer.
  delay(250);
}

Now save, verify and upload the code to your board.

Your board is now repeatedly trying to transmit the “Hello World…..” string over the USB-OTG port.  In order to see this we must now connect the USB-OTG port (located at the bottom of the board) to the computer and configure PuTTY to receive the data.
STM32F4-DISCOVERY USB-OTG Port

NOTE:  When I plugged in the boards USB-OTG port to my computer, Windows 7 needeD to DOWNLOAD a driver.  THIS OCCURRED automatically BUT took a few minutes.  (But I have a really slow Internet connection.)

 

CONFIGURING PUTTY

In order for PuTTY to communicate with the STM32F4-DISCOVERY board, we need to configure it with specific settings.  These setting will be different on each persons computer so a little preliminary research must be done in order to have the necessary information.

First, we need to determine which Virtual Comm Port number has been assign to the board.  In order to do this we need to go to the Windows Device Manager and look under the “Ports (COM & LPT)” section for an entry called “STmicroelectrionics Virtual COM Port (COM??)”.  The ending “(COM??)” tells us which port number has been assigned.  (In my case, it was COM13.)
STM32F4-DISCOVERY VCP DeviceManager

Next, start the PuTTY application.  On the right, click on the “Serial” radio button.  Now enter COM and you port number (all run together, no spaces), as found above, under “Serial line” and 1200 under “Speed”.  (If you wish to recall these setting later, you may save them by giving them a name under “Saved Sessions” and then click the “Save” button.)
PuTTY Serial Configuration

One the changes have been made to PuTTY, click on the “Open” button at the bottom.  You should now see the text “Hello World…” being repeatedly displayed in the PuTTY terminal.
STM32F4-DISCOVERY PuTTY HelloWorld Display