Report
3 years, 4 months ago.

Printf is not working

I've a couple of NUCLEO-F103RB and NUCLEO-F401RE and similar problem with both - can't receive anything from printf on terminal. Using PuTTY and TeraTerm, 9600 speed, both are the same, nothing happens when board issues printf. I've tried simple printf and pc.printf (initializing with SERAIL_TX, SERIAL_RX). After connecting USB red-green led is blinking for a couple of minutes. During this period main board is not working (user button press do nothing). After that usb led is steady green, nothing is transferred through USB.

using simple code below, led and button are working as designed, but printf is not working. Any ideas?

  1. include "mbed.h"

InterruptIn mybutton(USER_BUTTON); DigitalOut myled(LED1); Serial pc(SERIAL_TX, SERIAL_RX);

float delay = 1.0; 1 sec

void pressed() { if (delay == 1.0) delay = 0.2; 200 ms else delay = delay + 0.2; 1 sec pc.printf("Delay: %f\n", delay); }

int main() { mybutton.fall(&pressed); while (1) { myled = !myled; wait(delay); } }

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F401RET6 microcontroller.
Comment on this question

2 Answers

4 months, 2 weeks ago.

Did you try using Mbed studio or the online IDE?

Edit: Sorry I had a similar issue like you too when I was using VS Code. Laurent Meunier answer is the correct one. I wasn't able to use printf() in VS Code Platform IO. But When I tried Mbed Studio or the online IDE, it worked.

4 months, 2 weeks ago.

Hello

printf() is not allowed from an interrupt context, so you can't use it in callback.

Can you try to use printf from the main itself:

int main() { mybutton.fall(&pressed); while (1) { myled = !myled; wait(delay); printf("My test is running \r\n) } }


You need to log in to post a question