How to get console output on mbed studio(from nucleo 64 boards)?

Hello, I’d like to use the console output window that opens up in mbed studio when I connect my nucleof446RE board. I’m porting a library and I need this functionality for very frequent debugging purposes. This doesn’t give any output on the console:

#include "USBSerial.h"
#include <cstdio>

USBSerial pc;

int main(){
    pc.printf("hello");
}

Hello,

it seems, you can not change the COM port of Serial Monitor. The Serial monitor of MbedStudio is probably locked for the VCP of Debug interface (ST-link/DapLink) and so you can not switch it to on-chip USB interface with additional cable (pinout).
So probably must use some external app where also DTR signal is controlled.
I do not know what you mean with “very frequent debugging” but you can try to increase baud rate.

Also keep in mind the printf is very slow.

BR, Jan

What I mean by “frequent debugging” is that I might frequently want to print out variables and messages to check if things work as intended, even though printing them out doesn’t make sense when everything is complete. I think this is a standard practice.
I can get things to print the usual way:

BufferedSerial pc(USBTX, USBRX, 115200);
int main(){
    pc.write("Hello", sizeof("Hello"));    
}

but bufferedserial doesn’t have the handy printf. You can imagine the sheer amount of pain to evaluate floats, integers etc. to strings and then cast them into char* so that in the end I can get them to print on the console. Is there any way to use printf to print out things fast so that I can meaningfully use it? I really need this.
I could have used the debugger for this purpose but because it’s not a complete app yet, most things are calculated, but not being used, so they are ‘optimized away’ and I can’t see their values when I open a debugging session.

  • for debug you can use printf() without an object or function from debug.h
  • you can enable printf also for BufferedSerial

You can read this topic - No member named ‘printf’ in ‘mbed:BufferSerial’ - Online compiler / Help - Arm Mbed OS support forum

BR, Jan

okay the fdopen() method works, but as for using printf() without an object didn’t work for me. It compiles and everything, but I never saw anything on the console. That was the first thing I tried.
Anyway, Thanks for the prompt reply and helping me out. :slight_smile:

The debug printf of default console must work.
You must set Serial monitor to 9600 which is default. Or you must change change the baud rate in mbed_app.json how was menitioned in the shered topic.

BR, Jan

Hi @rajatmo,
have you tried putting a \n in the printf? Like in this comment?

Yes. I tried that. The only thing works is the FILE read/write method. Also The console is a bit finicky. I have to change the baud rate back and forth a few times before it works correctly, when I close and reopen mbed studio. But one method is sufficient for me so I’m not complaining.

Just for sure, I tested my Nucleo-F446RE with MbedOS6.11 and MbedStudio 1.4.1.
The printf works as expected.

BR, Jan