This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to print floating numbers with nRF Connect SDK?

Hello, guys.

I am using nRF Connect SDK, version 1.4.2 and nRF52840DK. I wonder what would be the way to print floating numbers during debug phase?

According to this thread, all we need is to include the following line into prj.conf file:

CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

as well as to use printf() instead of printk().

When I do the same and try to print a simple floating number with:

printf("Floating number: %3.2f\n", tmp);

Nothing is printed in my Segger Debug Terminal.

Is there anything I am missing here?

Thanks in advance for your time and efforts.

Sincerely,

Bojan.

Parents
  • , I think what meant was that "Segger Debug Terminal" only shows logs/prints from RTT interface, while the printf function is normally redirected to the UART serial terminal.

    If nothing is printed at all, this does not sound like an issue with printing floats, but rather how you read the logs/prints in general.

    I tried adding your printf-line to the BLE UART peripheral sample in NCS v1.4.2, and it prints the float over UART without any added Kconfigs:

    float tmp = 123.456;
    printf("Floating number: %3.2f\n", tmp);

    Output in serial terminal:

    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    Floating number: 123.46
    Starting Nordic UART service example

Reply
  • , I think what meant was that "Segger Debug Terminal" only shows logs/prints from RTT interface, while the printf function is normally redirected to the UART serial terminal.

    If nothing is printed at all, this does not sound like an issue with printing floats, but rather how you read the logs/prints in general.

    I tried adding your printf-line to the BLE UART peripheral sample in NCS v1.4.2, and it prints the float over UART without any added Kconfigs:

    float tmp = 123.456;
    printf("Floating number: %3.2f\n", tmp);

    Output in serial terminal:

    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    Floating number: 123.46
    Starting Nordic UART service example

Children
Related