Cant print floating values %f in my project

Hi All,

I am trying to print out floating values for my NRF5340 v2.4.1 SDK project. But, I am not able to print out the floating values. I tried the setting the following configuration but still failure:


CONFIG_PWM=y
CONFIG_LED=y
CONFIG_LED_PWM=y
CONFIG_PM=n
CONFIG_LOG=y
CONFIG_COLLABORATIVE=y
CONFIG_NEWLIB_LIBC=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
# CONFIG_LOG_PRINTK=y
# CONFIG_PRINTF_FLOAT=y

CONFIG_COLAB_ACTIVE_LOW_LEDS=y

void set_voltage(float voltage)
{

uint32_t pulse_width_ns = (voltage / 10.0f) * PWM_PERIOD_NSEC;

int ret = pwm_set_dt(&pwm_output_analog_out, PWM_PERIOD_NSEC, pulse_width_ns);

if (ret)
{
LOG_ERR("Failed to set PWM voltage: %d", ret);
}
else
{
LOG_INF("Set PWM voltage to: %f V", (float)voltage);
}
}

But I am always getting:
I: Set PWM voltage to: %f V
I: Set PWM voltage to: %f V
I: Set PWM voltage to: %f V

with no floating point value printing out.

Any help or recommendation is appreciated. Thank you.

  • I'm using a later SDK, but "CONFIG_CBPRINTF_FP_SUPPORT=y" was all I had to add.   I think there is inconsistent advice around about this, which is probably a sign that it's changed from one SDK version to another.

  • Hi Jacky,

    The information that willdean gives is correct. A change was made in a logging overhaul in this pull request and was included in nRF Connect SDK v1.6.0 so it is included in v2.4.1 as well as the later version that willdean is using.

    I attempted to reproduce the wrong printout on an nRF5340 DK by adding

    CONFIG_CBPRINTF_FP_SUPPORT=y
    CONFIG_LOG=y
    CONFIG_LOG_MODE_MINIMAL=y

    to prj.conf for zephyr/samples/hello_world and replacing the contents of main.c with

    /*
     * Copyright (c) 2012-2014 Wind River Systems, Inc.
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr/kernel.h>
    #include <zephyr/logging/log.h>
    
    LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
    float num = 4.2;
    
    void print_log(float num)
    {
    	LOG_INF("My float: %f",(float)num);
    }
    
    
    int main(void)
    {
    	printk("Hello World! %s\n", CONFIG_BOARD);
    	print_log(num);
    	return 0;
    }
    

    I built with nrf5340dk_nrf5340_cpuapp as the target and the float was printed as expected:

    I assume that you are building the code for the application core, have you set the Kconfig symbols in the configuration file for the application core? You can find out if  CONFIG_CBPRINTF_FP_SUPPORT is set by searching for the symbol in build/zephyr/.config for your project.

    Best regards,

    Maria

  • Hi   and  ,

    I tried with simple hello-world and blinky sample project and the floating point with logging module is working fine as expected. I think the issue is with my actual project[larger one] maybe something is being overwritten somewhere. I will have a look. 

    Thank you and to the community members for giving their time. Have a great day!.

  • Thanks for coming back to us. Yes it mostly looks like a configuration overwritten issue somewhere. I hope you find it.

Related