how to add USB serial printf to HelloWorld_IKS01A1 for Nucleo F091RC for Windows7 virtual COM port

11 Aug 2016

I want output of HelloWorld_IKS01A1 printf to go to Windows-7 virtual COM port. COM port already works from mbed Serial using this program below. But when I copy this: Serial pc(USBTX, USBRX); pc.printf("Hello World !\n"); ........to my HelloWorld_IKS01A1 it doesn't work.

Do I need to copy library?

Serial pc(USBTX, USBRX);

DigitalOut myled(LED1);

int main() { int i = 1; pc.printf("Hello World !\n"); while(1) { wait(1); pc.printf("Project printf_test 2016-08-11a: This program runs since %d seconds.\n\r", i++); myled = !myled; } }

11 Aug 2016

I got it working this way. Install mbed virtual COM driver for Windows7. Go to Accel driver top page: https://developer.mbed.org/teams/ST/code/X_NUCLEO_IKS01A1/file/f507d4465c31/Components/lsm6ds3/lsm6ds3_class.h  > HelloWord  > Import to Compiler > Import Replace its main() with:

Serial pc(USBTX, USBRX);

DigitalOut myled(LED1);

int main() { int i = 1; pc.baud(9600); pc.printf("Hello World !\n"); while(1) { wait(1); pc.printf("Project HelloWord IKS: This program runs since %d seconds.\n\r", i++); myled = !myled; } }

Open your Windows terminal program at 9600.

 Compile > Save As > F:

12 Aug 2016

This code also works fine with WinXP. The only thing I am interested in and couldn't find any reference, that can I use both parameters from SerialPC specified and referenced? Meaning, USBTX and USBRX inside the programs code?

15 Aug 2016

Hello Andras,
The USART2 (Serial2) interface available on PA2 and PA3 of the STM32 microcontrollers can be connected to ST-LINK MCU, ST morpho connector or to Arduino connector. The choice can be changed by setting the related solder bridges (located on the back side of NUCLEO board). By default the USART2 communication between the target MCU and ST-LINK MCU is enabled, in order to support Virtual Com Port for mbed (SB13 and SB14 ON, SB62 and SB63 OFF). If the communication between the target MCU PA2 (D1) or PA3 (D0) and shield or extension board is required, SB62 and SB63 should be ON, SB13 and SB14 should be OFF. In such case it is possible to connect another USART to ST-LINK MCU using flying wires between ST morpho connector and CN3. For instance on NUCLEO-F103RB it is possible to use USART3 available on PC10 (TX) and PC11 (RX). Two flying wires need to be connected as follow:

  • PC10 (USART3_TX) available on CN7 pin 1 to CN3 pin RX
  • PC11 (USART3_RX) available on CN7 pin 2 to CN3 pin TX

See the User Manual, chapter 6.8 USART communication.

Pin names USBTX and USBRX are alias names of pin names PA_2 and PA_3 (USBTX = PA_2 and USBRX = PA_3) mainly used when one would like to indicate that the serial port is available as Virtual Com Port on the PC connected over a USB cable. Have a look also at Serial Communication with a PC.