7 years, 1 month ago.

Serial.begin(9600); IN MBED

Is it possible to use Arduino like Serial.begin(9600); in mbed to allow Serial.println("abvd!"); for debugging?

1 Answer

7 years, 1 month ago.

Almost the same...This is the sample code "Nucelo_printf"

#include "mbed.h"

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED1);

int main()
{
    int i = 1;
    pc.printf("Hello World !\n");
    while(1) {
        wait(1);
        pc.printf("This program runs since %d seconds.\n", i++);
        myled = !myled;
    }
}

This, only use USBTX and USBRX instead of SERIAL_TX and SERIAL_RX. Those work for STM, but USBTX and USBRX work for every target.

Also in principle you can also just do printf("Hello World\r\n"); without the pc part, by default it will then send it to your PC.

posted by Erik - 23 Feb 2017