I would like to use newlibc for access to math functions (logf). However, when I enable newlibc I can't get floats or doubles to print with printf when compiling for the nrf52840dk_nrf52840. It does work for native_posix.
My test program:
#include <zephyr.h> #include <stdio.h> void main(void) { int i = 123; double d = (double)i; printf(" i: %d; d: %.3f end\n", i, d); }
prj.conf:
CONFIG_NEWLIB_LIBC=y CONFIG_CBPRINTF_FP_SUPPORT=y
When I build and run as native_posix I get the expeced output:
source ~/ncs/zephyr/zephyr-env.sh west build -d /tmp/build.tp -b native_posix west build -t run -d /tmp/build.tp *** Booting Zephyr OS build v2.6.99-ncs1-1 *** i: 123; d: 123.000 end. ^C
When I build and run as nrf52840dk_nrf52840, printf prints a blank for the double:
source ~/ncs/zephyr/zephyr-env.sh west build -d /tmp/build.t -b nrf52840dk_nrf52840 west flash -d /tmp/build.t *** Booting Zephyr OS build v2.6.99-ncs1-1 *** i: 123; d: end.
If I don't use newlibc, I get the expected output. Is there another way to get the math functions that I haven't discovered?
Tag:
~/ncs/nrf$ git reflog 290c67a38 (HEAD, tag: v1.7.1, origin/v1.7-branch) HEAD@{0}: clone: from https://github.com/nrfconnect/sdk-nrf
Zip file of project:
Thanks,
Jan Erik