Mbed forum

No printf() output on Nucleo-F446RE


(Jack Hsieh) #1

i am new on ST mcu family, got a Nucleo-64 F446RE board, MBED provides useful examples on led and button codes but no luck on printf() function on UART port, no waveform output! check the document it should drive Serial2 as default, tried to use actual pin names instead of Serial_TX and Serial_RX but no difference? On mbed online compiler, i already specified Nucleo F446RE as target.

#include “mbed.h”

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

//Serial pc(SERIAL_TX, SERIAL_RX, 19200 );
Serial pc(PA_2, PA_3 );

DigitalOut myled(LED1);

int main()
{
int i = 1;
pc.printf(“Hello World !\n”);
while(1) {
wait(0.2);
pc.printf(“This program runs since %d seconds.\n”, i++);
myled = !myled;
}
}


(Ralph Fulchiero) #2

Hi Jack,

We ran your example on a similar Nucleo F4 target and we were able to see the printf() just fine using a baud rate of 9600. Are you sure that you are viewing the proper virtual com port (VCP) with your terminal program?

If you run Windows Device Manager are you seeing the ST Link VCP as shown below?

Regards,
Ralph, Team Mbed


(Jack Hsieh) #3

Hi Ralph,

Thanks for providing the answer. I think it is a misunderstanding of how to define the serial output, didn’t realize it uses VCP instead of actual com port! As showed on the code, I also used PA_2 and PA_3 pins as tx and rx but no difference!? Does it supposed to be programmable?

I also has Nucleo-144, with F746ZG MCU on it and it works perfectly out of the box (sample printf(); code from mbed) to define the COM ports as I programmed. So as taking USB as VCP.

Regards,

Jack


(Jay Lin) #4

Hi Jack,

Try declaring PC as follow:

[…]
Serial pc(USBTX, USBRX);
[…]
int main(){
[…]
pc.frequency(19200);
[…]
}

In your case, it should be:

#include “mbed.h”

//Example Code//

Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);

int main(){
int i = 1;
pc.frequency(9600); //This is unnecessary as the default baud rate when initializing serial is 9600, you can change this value to something else; such as the 19200 you wanted.
pc.printf(“Hello World !\r\n\r\n”);
while(1){
wait(0.2);
pc.printf(“This program runs since %d seconds.\n”, i++);
myled = !myled;
}
}

It should print through serial then.