9 years, 1 month ago.

Strange result with printf and pc.printf on Nucleo F411RE

Dear all, This is my first attempt at Mbed and my hello world was to blink LED later I added printf function to test VCP. It works but TeraTerm hang after over about 100 lines or so. I later tried to use "pc.printf" the LED just blink once and stopped no output at terminal. In my exasperation I tried to import a sample pc.printf project and changed it to my earlier program and it work! Why does same code only works when in different project? (By the way the hanging of TeraTerm still persisted). Here are the code:

#include "mbed.h"              

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

int main(void) {
    int nr=0;
    while (1){
    myled = 1; // LED is ON
    wait(0.25); // 250 ms
    myled = 0; // LED is OFF
    wait(0.25); // 250 ms   
//  printf("was previously printf %u\r\n",nr++);
    pc.printf("HelloLine %u\r\n",nr++);
    }
}

Appreciate if anyone can help on this. Thanks!

Can you add your code inside <<code>> and <</code>> (on seperate lines), then it is properly formatted.

posted by Erik - 06 Oct 2015

2 Answers

9 years, 1 month ago.

I don't see why Teraterm is hanging, I'll see if I can have a look at it later.

Why your new project could be different is that you have a newer/older version of the mbed lib. If you right click, update, on the mbed lib you have the latest version (which to be fair is not always the best version).

9 years, 1 month ago.

The terminal may be hanging because you flood the communication pipe. The formatted string is transmitted in a loop at the default baudrate of 9600 baud. Try a faster baudrate.

There is a total wait of 500ms between transmissions though.

posted by Erik - 06 Oct 2015