1 year, 8 months ago.

EFM32 Giant Gecko mbed printf


I cannot get printf to work under MbedOS.

The wikipage states that you dont have to do any configuration if using printf and the virtual com port.

My code looks like this:

  1. include "mbed.h"

int main(){ while(1){ printf("Hei dette er en fint test \n"); wait_ms(100); } }

It does not print anything to the terminal.

My serial settings on the terminal reader program is

115200 8 bits 1 stop bit no parity

What could be wrong?

Question relating to:

Silicon Labs a leading provider of microcontroller, sensing and wireless connectivity solutions for the Internet of Things (IoT).

1 Answer

1 year, 8 months ago.

Hello Thomas,

When using global printf in mbed the bit rate for the serial terminal shall be set to 9600.

Another option is to keep 115200 bps for the serial terminal and create a new serial object for the serial terminal. Change its bit rate to 115200 and instead of the global printf call its printf method:

#include "mbed.h"

Serial pc(USBTX, USBRX);    // create a new serial object for the virtual serial port

int main()
    pc.baud(115200);        // change the bit rate (from 9600) to 115200
    while (1) {
        pc.printf("Hei dette er en fint test \n");  // call the printf method of pc object

ADVISE: To have a more readable code published here (on mbed pages) try to mark it up as below (with <<code>> and <</code>> tags, each on separate line at the begin and end of your code)

text of your code