cancel
Showing results for 
Search instead for 
Did you mean: 

Is there anyone succeeded in float printf using CodeSourcery or Ride7?

choies1
Associate
Posted on November 13, 2010 at 03:46

I am using STM32VL-Discovery to test float printf using codesoucery or ride7.

Is there anyone succeeded in float printf using gcc or ride7?

I can do int printf using the small_printf.a. However I can't do float printf.

Namely,

printf(''Test int: %d \n\r'', int_a);  // <== It works well.

printf('' Test float: %f \n\r'', float_a); // <== It does NOT work well.

If someone knows how I can do float printf using codesoucery or ride7, please let me know it.

If you attach your working codes (including c code and startup code and link script) for this, it will be very helpful.

#floating-point #gcc-printf-float-codesourcery-ride7 #fpu
2 REPLIES 2
Andrew Neil
Evangelist III
Posted on November 13, 2010 at 07:57

Floating point takes a lot of code - especially on a processor with no hardware floating point unit (FPU).

And, in most cases, it is unnecessary - just use appropriately-scaled integers.

Therefore, many (most?) embedded compilers will disable floating point by default.

If you really need floating point support, you are going to have to read the compiler manuals to determine how to enable it.

You may well also have to add extra/different libraries to your project...

Posted on November 13, 2010 at 13:30

I'll echo much of what Andy says, I've been using floating and fixed point arithmetic in math intensive embedded applications for a very long time. The trick is to know when each method is appropriate, and the dynamic range of the numbers being handled. And the algorithm, and goals, for that matter. Floating point is often used as a crutch. printf/scanf also fall into this category, they are easy, but have a drastic impact on speed,size,stack in the embedded world. I understand they are convenient for human interface, but look at alternatives.

Significant speed to can be gained by eliminating as much floating point math, and as many steps as possible. Passing them to the host system in their native binary form also makes a lot of sense.

Also even using floating point, very few people need the scope of scanf/printf. These are typically replaced by functions addressing the particular input/output formats you actually need. The foot print for scanf/printf is very large. The addition of floating point support compounds this.

Pull in the libraries you need, buy a compiler that supports your speed and output requirements, or write some functions to output some decimals, the math/code isn't that hard. Or go find some C runtime source on the net and compile it in.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..