Home / Tutorials / STM32 Tutorial / STM32 Nucleo Serial Communication
STM32 Nucleo

STM32 Nucleo Serial Communication

Debugging through the serial port is one of the ways to find errors on your code. In this tutorial, I'll show you how to add serial communication function to your STM32 Nucleo board.

Download the Driver

First thing we'll need is the serial port driver. I thought this was already installed because we are already transferring .bin files to the board but this is not the case!

We will be using Putty to view the messages sent from the board to the computer so you need to download that as well.

Serial Object

For accessing the serial port of the STM32 Nucleo board, we'll be using the Serial object. This object takes in two parameters, the transmit pin and the receive pin. Since we'll be using the USB cable, those pins will be USBTX and USBRX, respectively.

So let's say the serial object is named pc, then this is how the object is initialized:

Then to write a string to the port, the traditional printf() function is used:

pc.printf("Hello World!\n");

Simple Serial Example

I wrote a simple code that will display "Button is pressed!" everytime a button attached to D6 is pressed. Here it is:

Now we have a way to track our code and make debugging easier.

Check Also

STM32 Nucleo

Input and Output with STM32 Nucleo

We managed to blink a LED on the previous tutorial. This time, we will add …