4 years, 5 months ago.

printf not working , while serial printf is (KEIL + GNU ARM)?

Hello, I was able to fly the demo code on xDot .

  1. include "mbed.h"

Serial pc(USBTX, USBRX); tx, rx

int main() { printf("Not printing \r\n"); /*This is not printed*/ pc.printf("Printing\n\r");/*This is printed*/ while(1) { } } To me it seems there is something wrong with the retarget of printf. Any ideas?

1 Answer

4 years, 5 months ago.

Hi Muhammad,

printf() should use pc. Also pc.printf() should work. Without going deeper in Mbed OS I would say that if you have several Serial instances like Serial pc(USBTX, USBRX); tx, rx Serial uart2(Ptx, Prx); then pc.printf() uart2.printf() Here is more information about printf: https://os.mbed.com/docs/mbed-os/v5.10/tutorials/debugging-using-printf-statements.html

Regards, Pekka

Accepted Answer

Thanks for ur reponse Pekka. I solved the problem and I actually had to go deeper in Mbed OS. It was the fact that the default file descriptor that is passed to the _write re-targeted function was different in case of pc.printf and the normal printf.

posted by Muhammad Tharwat 15 Nov 2019