5 years, 5 months ago.

How can I get the MBED error output when compiling with PlatformIO?

Hi, I am trying to get the MBED Error output over RTT or Serial, but neither of them works. I read somewhere, that I have to compile the Project with the MBED cli in order to get the error output working.. is that true? and if so, how can i do that on PlatformIO(VSCODE)?

adding to that, I am wondering why Serial output is not working.. I set the serial ports correctly, but I cant use stdout or normal printf for serial... is it maybe due to the fact that I have another Serial Object Instance with the same pins on my main App?

thanks, Jonas

1 Answer

5 years, 5 months ago.

Hi Jonas,

By default, the error output (which is printf()) is re-targeted to Serial port, so if you connect the port well, you should be able to see the output from serial tool(like coolterm or teraterm). I believe it's regardless of the IDE or editor.

I may need the following information from you.

  • Could you attach a simple code snippet for printing some logs you are using? And also the board your are using.
  • The platform you are using
  • How you connect the serial port

Please let me know if you have any questions!

- Desmond, team Mbed

Hi, thanks for the answer, I wrote my own Handler for the MBED error messages (overwritten the WEAK mbed_error() function) and by swapping every printf statement with my own serial function I got it to work. The only thing I still dont get is the Fault handler Register dump, which would be nice too!

code for my RTT prints:

RTT

va_list args;
va_start(args, fmt);
vsprintf(buf,fmt,args);
SEGGER_RTT_WriteString(0,buf);
va_end(args);

code for my Serial prints:

Serial

va_list args;
va_start(args, fmt);
cm.mydevice->vprintf(fmt, args);
va_end(args);

with mydevice being declared as: this->mydevice = new Serial(P0_29, P0_30);

I am using the Nordic NRF52832 chip with NRF52_DK platform. Serial port is connected over the JLink DK serial output, this definitly works (from my own code) I tried it with freopen() but I also could only get my own printfs to print out.

thanks :)

posted by Jonas Woerner 27 Nov 2018

I think the JLink serial should use P0_6 and P0_8 by default, I will suggest you to try to modify TARGET_NRF52_DK/PinNames.h as below

PinName

//RX_PIN_NUMBER  = p8,
//TX_PIN_NUMBER  = p6,

RX_PIN_NUMBER  = P0_30,
TX_PIN_NUMBER = P0_29

And see if the original printf can print through JLink serial output.

In addition, I believe the default baud rate is 9600, make sure you set the correct parameter.

posted by Desmond Chen 28 Nov 2018

Hi, It does not work, I modified the pin names earlier in mbed_app.json, and now in the file you specified, both methods didnt make it work. Also uart_hwfc is set to 0.

posted by Jonas Woerner 28 Nov 2018

How about not using the JLink DK serial output, do you have an extra usb-to-serial cable, and directly connect it by pin-to-pin TX/RX?

If it works, then the problem might be related to the board configuration, if it still doesn't work, then the problem might be the printf retarget.

posted by Desmond Chen 29 Nov 2018

I had it connected to another Serial->usb converter, but it didnt work either...

posted by Jonas Woerner 03 Dec 2018

I tested a little bit and now I think it really has to be an MBED bug..

you can easily reproduce this: create new project with platformIO and MBED framework. use this code:

include the mbed library with this snippet

#include <mbed.h>
//Serial device(P0_29, P0_30, 9600); //tx, rx, <--this


void print_to_serial(const char *fmt, ...) {

    va_list args;
    va_start(args, fmt);
    //device.vprintf(fmt, args); <--this
    va_end(args);
}


int main() {

  // put your setup code here, to run once:

  while(1) {
    printf("test from mbed");
    wait_ms(100);
    print_to_serial("test from main code");
    wait_ms(100);
  }
}

when both lines marked with "this" are uncommented, I get the "test from main code" output. when I comment them, I dont get anything for like 10 seconds and then I get a burst of "test from mbed". It seems like printf writes to a buffer and as soon as it is full, the buffer gets printed.

Ps. the burst contains 1024 characters... could be a hint.

posted by Jonas Woerner 03 Dec 2018