5 years, 6 months ago.

Printf does not work on nrf platform

Hello,

I am trying to run the following simple program on an nRF51 board

#include "mbed.h"

// define the Serial object
Serial pc(USBTX, USBRX);

DigitalOut led1(LED1);

// main() runs in its own thread in the OS
int main() {
    
    mbed_error_status_t status = MBED_SUCCESS;
    
    while (true) {
        led1 = !led1;

        // Print something over the serial connection
        pc.printf("Blink! LED is now %d\r\n", led1.read());

        wait(0.5);
    }
}

I use the online compiler, no specific Compile macro. When I load the hex file on a nRF51 dk, the program crashes. It is enough to comment the pc.printf() line for getting the program to run correctly.

What am I doing wrong. This program is the one from the "Debugging" tutorial and is a very simple extension of the blinky program.

Thank you in advance for your help.

Regards,

Serge

Hi Serge,

Which specific nrf51 platform are you using?

- Jenny, team Mbed

posted by Jenny Plunkett 03 Oct 2018

Hi Jenny, I am using the nrf51 dk, board PCA 10028, V1.1.0. The nRF51 is running softdevice S130, version 2.0.1. Please let me know if you need further information. Regards, Serge

posted by Serge Ayer 04 Oct 2018

1 Answer

5 years, 6 months ago.

Hi Serge, I tried your code on NRF51_DK (PCA10028) board with DAPLINK firmware installed. (https://armmbed.github.io/DAPLink/)

I see it work as expected on mbed-os 5.9.7 release commit: https://github.com/ARMmbed/mbed-os/commit/949cb49ab and mbed-os 5.10 release commit: https://github.com/ARMmbed/mbed-os/commit/610e35ddc.

I used command line compiler. Can you please let me know what environment did you use? Can you please try the above mentioned releases and see if you observe the same?

Thanks, Naveen

Team mbed.

Accepted Answer

Hi Serge,

I also tried with online compiler (mbed 5.10) based build on a NRF51 device with DAPLINK firmware and it worked as expected.

To enable the auto reset mode on DAPLink interface, please copy an empty file named auto_rst.cfg while holding the reset button on the board. By default, auto reset is off.

https://github.com/ARMmbed/DAPLink/blob/master/docs/MSD_COMMANDS.md Thanks,

Naveen

Team mbed.

posted by Naveen Kaje 04 Oct 2018

Hi Naveen, I did install the DAPLINK firmware as documented on your link and it now works as expected. The only stange thing is that I have to power cycle the board each time I load a new hex application. Thank you for your help. Serge

posted by Serge Ayer 08 Oct 2018