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.
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.
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):
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.
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.
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