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

NRF_LOG print double precision float number

I am on SDK15.3, NRF52840, armgcc, makefile, console

I need to print a double float number in format of "x.xxxxE-xx". I already know that NRF_LOG can only print float with MARKER, so I use sprintf to format the number into a string buffer first, and then I use NRF_LOG to print that string using "%s" format specifier.

    char abuf[40];
    memset(abuf, 0, sizeof(abuf));

    uint8_t len = sprintf(abuf, "%.5E", 3000.8766);
 
    NRF_LOG_DEBUG("[KF] updated K gain: %s, %d\n", abuf, len);
    

However I only get white spaces or unprintable character.

Anyway I can do this properly?

thank you.

/Roland

Parents
  • Hi,

    The Makefiles in the SDK does not include float support for printf in armgcc by default. Please try adding the flags from this post to the LIB_FILES, that seems to print the way you want in my test:

    # Add standard libraries at the very end of the linker input, after all objects
    # that may need symbols provided by these libraries.
    LIB_FILES += -lc -lnosys -lm -lrdimon -u _printf_float

    <info> app: [KF] updated K gain: 3.00088E+03, 11

    Best regards,
    Jørgen

Reply
  • Hi,

    The Makefiles in the SDK does not include float support for printf in armgcc by default. Please try adding the flags from this post to the LIB_FILES, that seems to print the way you want in my test:

    # Add standard libraries at the very end of the linker input, after all objects
    # that may need symbols provided by these libraries.
    LIB_FILES += -lc -lnosys -lm -lrdimon -u _printf_float

    <info> app: [KF] updated K gain: 3.00088E+03, 11

    Best regards,
    Jørgen

Children
Related