6 years, 7 months ago.

how to print a statement for mbed on Eclips window

Hello Can anyone please tell me how can i use Serial pc(SERIAL_TX, SERIAL_RX); on Eclips using mbed for library offline IDE compiler. Serial gives an error on Eclips and i can't use print statement. If someone knows how can i remove this error then please answer. Im using Nucleo F429 board on Ubuntu. Thank you

1 Answer

6 years, 7 months ago.

Hello Ali,
One simple solution is to use the default serial port which is automatically created by the mbed library. So you do not need to create a serial object (like Serial pc(USBTX, USBRX);). Instead you just call the global printf function as below. In this case also the binary code becomes smaller. The default settings are 9600 bits/s, one start bit, eight data bits, no parity bit, one stop bit. However, make sure that the mbed serial driver for the NUCLEO-F429 is installed on your PC and the mbed board is connected to the PC over a USB cable.

//Serial pc(USBTX, USBRX);
...
void main() {
    ...
    //pc.printf("Hello, World!\r\n);
    printf("Hello, World!\r\n");
    ...
}

Accepted Answer

If the error says something like:

  • error: 'MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE' was not declared in this scope
  • error: call to 'mbed::Serial::Serial(PinName, PinName, const char*, int)' uses the default argument for parameter 4, which is not yet defined

And there is an mbed_config.h file available in your project exported from the online compiler, then one ways how to fix it is adding #include "mbed_config.h" to the device.h header file associated with your target mbed board as below:

device.h

#ifndef MBED_DEVICE_H
#define MBED_DEVICE_H
 
//=======================================
#define DEVICE_ID_LENGTH       24

#include "mbed_config.h" 
#include "objects.h"
 

After such modification you should be able to create instances of the Serial class in your program.

NOTE: For the NUCLEO-F429ZI board you should be able to find the associated device.h file in the mbed/targets/TARGET_STM/TARGET_STM32F4 folder.

posted by Zoltan Hudak 19 Aug 2017