Information on how to use the STM32 Nucleo board with mbed
"Hello World!" Creating Console Output¶
Included within the USB interface of the ST Nucleo F401RE board is a Virtual COM port that can be used to send back messages to your PC within your embedded code.
- Connect your ST Nucleo F401RE board to your PC via USB cable
- Determine the STM32 STLink Virtual COM port of your Nucleo board
One method is to select Devices and Printers from your Windows Program Menu:
- Right click on the STM32 STLink icon and select Properties; Click on the Hardware Tab
- Or check Device Manager under Ports (COM & LPT)
You will find an entry for the device called "STMicroelectronics STLink Virtual COM Port (COM##)" where COM## is the serial port enumerated by your Nucleo board USB device. You will want to take note of this number as it will be used further in this tutorial.
Next, program the ST Nucleo F401RE board with a sample program that uses the Virtual COM port interface to display text on your PC's serial console. This information is useful for debugging your mbed program.
- Return to the mbed compiler
If you have exited the compiler you can return to the mbed compiler by returning to the ST Nucleo F401RE platform page and select Open mbed Compiler
- Click the New button to create a new program
The Create new program dialog box will appear.
- Under the Template selection choose: "Display a message on PC using UART"
- Change the Program Name to "STM32F401_Nucleo_printf"
- Click OK
The program will be imported and a new program work space will appear.
- Double click on the main.cpp program and click the Compile button
Upon a successful compilation, a binary image will be created and a dialog box will ask if you want to save it.
- Save the compiled code onto your Nucleo board by saving the newly created binary file to your Nucleo drive
Upon successful download, you should see a change in the blink rate of your Green LED.
You Nucleo board is now ready to communicate to your PC via the virtual serial interface.
- Install or open a terminal emulator for serial communications
You need a terminal emulator installed on your PC to perform serial communications with your Nucleo board. If you do not have a terminal emulation program on your PC we recommend you download and install one of the following terminal emulation programs:
Further information on terminal emulation configuration using mbed can be found here: Terminals. Also included at this site is information for Mac and Linux usage.
For those Microsoft Windows users who are looking for the old HyperTeminal application on a Win 7 or Win 8, please refer to the following Microsoft article: What happened to HyperTerminal?
Here is an example on how to set-up Tera Term to receive messages (I'm using Tera Term v4.83):
- Open Tera Term, select Serial, select the COM port for your Nucleo board, and click OK
- Select the Setup and then Terminal… menu
- Change the New-line Receive: to LF and click OK
- Check the serial port settings by selecting the Setup::Serial Port… menu item
- Check the serial settings, the click OK
A few other useful commands: To clear the screen, select: Edit::Clear Screen To disconnect the terminal, select: File::Disconnect To save the setting as default, select Settings::Save Setup… (default is TERATERM.INI)
Upon a successful serial connection, you should have an output that looks like this:
Feel free to go back to your mbed compiler window, change the printf text, recompile and save the binary to your Nucleo drive.
To start your program from the beginning, push the Black reset button on your Nucleo board.
You now have a method for on-board debugging via printf statements.