printf float on stm32f4 with toolchain arm-none-eabi-gcc

Hello,

I have a problem to use printf with float arguments - it always outputs 0.00000 for the float arguments. Greping through the code I see this scenario is used in other platforms. If somebody could give me any pointers how to fix this or where to look, I will highly appreciate it.

Best Regards, -Martin

The issue is with the samr21. But you can do math with floats though with bad performance because of no fpu available. The debug or printf does not print anything. You can cast only

I don't know about samr21, I don't use this processor. I would think the issue is with compilation/linking, because I can create a simple project using the Eclipse arm plugin where printf works with float just fine.

-Martin

Hello Martin, Hello Rane, All the stm32f4 boards are build with nano specs, if your toolchain supports them. This means among others, that the printf is very basic (to save flash and RAM during execution) and can’t print types like e.g. floats and long longs. If you do not want this, you have to compile without nano specs with the caveat of a larger memory footprint + more stack consumption of threads that use printf (on current master (695d702) for stm32f4discovery, but for other boards the diff would be similar):

diff --git a/boards/stm32f4discovery/Makefile.include b/boards/stm32f4discovery/Makefile.include index cecaf4c…31869c4 100644 — a/boards/stm32f4discovery/Makefile.include +++ b/boards/stm32f4discovery/Makefile.include @@ -45,10 +45,5 @@ export TERMFLAGS += -p “$(PORT)” export CXXUWFLAGS += export CXXEXFLAGS +=

-# use newLib nano-specs if available -ifeq ($(shell $(LINK) -specs=nano.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) -export LINKFLAGS += -specs=nano.specs -lc -lnosys -endif

export board specific includes to the global includes-listing

export INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include

Hope this was helpful, Martine

With the nano.spec you still have a way to enable the full version of printf by adding "-u _printf_float" to the link command. This works in the Eclipse arm plugin project, but doesn't work in riot-os, I can not figure out why. Also, I tried to compile without the nano.spec , still doesn't work.

-Martin

It looks like this problem is related to thread creation. If I call printf from kernel_init it works fine, but if I call it from separate thread create with thread_create, float args show up as 0.00000 . I've been using riot-os only for about a week, so I don't have too much knowledge about the OS internals. If somebody can help me understand of what is going on and how I can work around this problem (if possible at all) it will be great.

Thanks, -Martin

Important observation you got there. I will check that out as soon as possible.

Hi,

Hi again,

Attached is a simple patch that demonstrates the problem. If main is called directly sprintf works, if it is called from the thread sprintf outputs 0.00000

Thanks, -Martin

sprintf_float_demo.patch (1.38 KB)