Change the world

Control Software

Being able to display value of counter, sensors and other debugging information is an important part of embedded software development.  Writing software for PCs is much easier in this regard as there is already a monitor to print values to.  For embedded systems the obvious solution is to use a LCD connected to the microcontroller's port pins and with the use of the proper LCD library one can then print values to it.  This does however increase the development cost if your hardware platform does not already contain a LCD and usually also requires additional interfacing circuitry.

The USB interface on the NUCLEO-F446RE board provides a solution.  Appart from being used to program the STM32-F446RE device on the board, it also creates a Virtual Com Port on the PC.  This allows one to send a stream of serial characters (typically using the printf statement) from the STM32-F446RE to the PC.  On the PC you can then use a Terminal program (such as Termite) to display this stream of characters.

 

A few simple steps can be followed to implement this:

  • Connect the NUCLEO-F446RE board to a USB port on the PC
  • Determine the COM port number that was created by the NUCLEO_F446RE Virtual Com Port.  This can be checked in Windows Device Manager under Ports (COM & LPT):

  • Open the Terminal program, e.g. Termite, and go to Settings:

  • Change the port number to correspond with the NUCLEO_F446RE Virtual Com Port and select 9600 as the baud rate.  Click Ok.  The Terminal program is now ready to receive characters from the microcontroller's serial port.
  • Create a Serial object in your program and use the printf statement to send characters to the PC.  Use the following example as a reference:
#include "mbed.h"
 
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------
 
Serial pc(SERIAL_TX, SERIAL_RX);
 
DigitalOut myled(LED1);
 
int main() {
  int i = 1;
  pc.printf("Hello World !\n");
  while(1) { 
      wait(1);
      pc.printf("This program runs since %d seconds.\n", i++);
      myled = !myled;
  }
}

With the NUCLEO-F446RE the TX signal is on pin PA2 and RX on pin PA3.  The ARMmbed library creates two constants, SERIAL_TX and SERIAL_RX, which can be used which points to these two pins.

  • Run the program and see the results of the printf statements in the Terminal program:

 

The Virtual COM Port and Terminal program can also be used to provide input to the NUCLEO-F446RE device via the serial link.  The following link will provide more detail on this:

https://developer.mbed.org/handbook/SerialPC

The examples in the link uses USB_TX and USB_RX, but you can just replace that with SERIAL_TX and SERIAL_RX.