Strange problem with "sprintf"

guix: Yes it does :D

Thanks a lot, it's working! Karma++;

Awesome! Glad I could help.

-- Roger

guix: krupsi, I would like to use your patch on Windows, how to proceed?

What are those commands, and where to find those files?

cp libc.a libc.a.orig
ar -dv libc.a vfprintf_std.o
ar -dv libc.a vfscanf_std.o
ar -xv libprintf_flt.a vfprintf_flt.o
ar -xv libscanf_flt.a vfscanf_flt.o
ar -rv libc.a vfprintf_flt.o
ar -rv libc.a vfscanf_flt.o

Thanks

cp is the "copy" command in unix. It can be found in: {installdir}\hardware\tools\avr\utils\bin\cp.exe

ar is the "archive" command for creating archive files also known as libraries when using compiler tools. It can be found in: {installdir}\hardware\tools\avr\avr\bin\avr.exe

BTW, if you google: man cp man ar you can get information on these commands.

--- bill

bperrybap: BTW, if you google: man cp man ar you can get information on these commands. --- bill

I gave him a copy of the floating point versions of "libc.a" for all the AVR directories, he installed them (on a Windows based system) and they worked.

FYI, I "patched" not only sprintf, but also sscanf since both of the originals were non-floating-point versions.

The AVR libraries themselves are the same in all distributions (Linux, Windows, MacOS), so they can be dropped into any system.

I REALLY wish the IDE had config options for specifying compile, link and AVRDUDE flags instead of having them all hard coded.

I may work on the IDE to add those features and then post the code......

-- Roger

(edit): Added a karma++ for you for the original idea which worked flawlessly. Thanks!

krupski: I REALLY wish the IDE had config options for specifying compile, link and AVRDUDE flags instead of having them all hard coded.

I may work on the IDE to add those features and then post the code......

mpide and Pauls latest Teensy version of the IDE for his Teensy 3.0 support this. But they support it through boards.txt or other configuration files rather than some way from the IDE itself.

Not sure what is happening to the official toolset for DUE support. (Will it be a separate IDE or a combined like mpide or Paul's IDE? still no word on this). If it is a combined IDE, then it might be possible to play with some of the flags.

Another down and dirty way to set some flags is write some small wrapper scripts that set/modify the commmandline options and then call the real command. --- bll

bperrybap:

krupski: I REALLY wish the IDE had config options for specifying compile, link and AVRDUDE flags instead of having them all hard coded.

I may work on the IDE to add those features and then post the code......

mpide and Pauls latest Teensy version of the IDE for his Teensy 3.0 support this. But they support it through boards.txt or other configuration files rather than some way from the IDE itself.

Not sure what is happening to the official toolset for DUE support. (Will it be a separate IDE or a combined like mpide or Paul's IDE? still no word on this). If it is a combined IDE, then it might be possible to play with some of the flags.

Another down and dirty way to set some flags is write some small wrapper scripts that set/modify the commmandline options and then call the real command. --- bll

Well, my idea was to extent "preferences.txt" by adding entries to it, adding corresponding menu items to the GUI and finally support code in the Editor and Compiler classes.

Rather than cryptic options like "-Wl,-u,vfprintf -lprintf_flt -lm", the menu would, for example, say something like "[ # ] Enable floating point? (approx. 1500 bytes larger code)" and then supply the proper options based on the boolean "yes" or "no".

There would also be an "advanced" option where various configs could be added manually so that all in all there would be NO limitations on what a user could do.

It's obvious to me that the IDE was written to support "noobs" and present them limited options (i.e. limited ways to screw up their system), but advanced options SHOULD be available to those who want them.

As far as modifying the command line idea... I tried that. I renamed the AVR-GCC file, then made a little shell script to call the compiler with added command line options. It didn't work (don't know if I screwed up or if it just can't work)... but then your idea of "fixing" libc.a solved the whole problem, so the project dropped off my radar screen.

Oh well... thanks again for all your help!

(btw, you said you had other patches and ideas.. I would LOVE to know what they are).

-- Roger

Hey Folks,

To support floats in xxprintf() family functions, you can recompile the Arduino IDE with a slight change to the linker options. Suffice it to say, it's a pretty straight forward process and I've detailed it here: http://josh.to/silvia/rebuilding-the-arduino-ide-to-support-sprintf-with-floats/

I hope this helps everyone.

Cheers,

Josh.

joshblake:
Hey Folks,

To support floats in xxprintf() family functions, you can recompile the Arduino IDE with a slight change to the linker options. Suffice it to say, it’s a pretty straight forward process and I’ve detailed it here: http://josh.to/silvia/rebuilding-the-arduino-ide-to-support-sprintf-with-floats/

I hope this helps everyone.

Cheers,

Josh.

Awesome! Thanks for that. I had been looking through the “Compiler.java” code to find where to add that line, but wasn’t making any progress.

Now it works… and I also added an option to the “Preferences” to enable or disable floating point.

One good thing about the Arduino 1.5 IDE is that the compiler & linker options are no longer hard coded. You can change them by simply editing the platform.txt and boards.txt files. This allows you to set options all the way down to the specific board type if you want to, which is nice since you won't have to hard code the options to be the same for all builds.

--- bill

bperrybap: One good thing about the Arduino 1.5 IDE is that the compiler & linker options are no longer hard coded. You can change them by simply editing the platform.txt and boards.txt files. This allows you to set options all the way down to the specific board type if you want to, which is nice since you won't have to hard code the options to be the same for all builds.

--- bill

That's nice to know. Have you found the v1.5 IDE to be stable? I am afraid of beta software... especially because I use it at work to develop student project software. I can't afford to have some strange bug ruin a student's project when their grade depends on it.

Krupski: Have you found the v1.5 IDE to be stable?

No. So much software that calls itself "beta" these days is not even close to "beta". Beta used to mean feature freeze and moving toward code freeze and final release. These day's these young kids doing development don't seem to follow much of a development process and seem to call something beta as soon as they push it out of the lab. Then they continue to make feature changes. The IDE seems to be still changing features and tossing in things. Generally all good, but things are still breaking and not fully working especially when mixed environments that have AVR as well as ARM or in some cases just AVR. In their defense, they don't recommend using 1.5 on AVR. I ran into several issues that would not be easy for a novice to deal with and a few versions that would not come up at all if AVR libraries were in your sketchbook. You might want to play with it to get a feel for it, but I definitely don't think it is anywhere close to being ready as a product that can be used for student needs.

Eventually the two IDEs will merge back into one that will claim to work for multiple processors, then maybe a few months or quarters later it will be a stable product that is actually pretty nice. Not sure when that will be.

--- bill

bperrybap:
In their defense, they don’t recommend using 1.5 on AVR.
I ran into several issues that would not be easy for a novice to deal with
and a few versions that would not come up at all if AVR libraries were in your
sketchbook.
You might want to play with it to get a feel for it, but I definitely don’t think
it is anywhere close to being ready as a product that can be used for student needs.

Eventually the two IDEs will merge back into one that will claim to work
for multiple processors, then maybe a few months or quarters later it will be a stable
product that is actually pretty nice. Not sure when that will be.

— bill

Thanks for the assessment. Since my 1.0.3 IDE is up and running nicely, along with my additions (the “Upload, then Monitor” button and the “Floating point enable/disable” option), I’ll stick with it until 1.5.x becomes THE version to have.

I do like the idea of more control over the environment that 1.5 has, but for the sake of stability, I’ll stick with 1.0.3 for now.

Do you know if the AVR library code base has been updated in 1.5? ← I found the answer… the code is exactly the same… checked it with “diff” - they are all the same.

joshblake: Hey Folks,

To support floats in xxprintf() family functions, you can recompile the Arduino IDE with a slight change to the linker options. Suffice it to say, it's a pretty straight forward process and I've detailed it here: http://josh.to/silvia/rebuilding-the-arduino-ide-to-support-sprintf-with-floats/

I hope this helps everyone.

Cheers,

Josh.

Hey, FYI I discovered something interesting (or strange... or worrysome).....

Before I used your modification to make the IDE insert the proper options for floating point support, I had my libc.a files patched (the _min code removed and the _flt code inserted).

Just now I compiled a small test program and noticed this:

  • Stock libc.a, floating point off: 6740 bytes
  • Stock libc.a, floating point on: 10690 bytes
  • Patched libc.a, floating point off: 8286 bytes
  • Patched libc.a, floating point on: 10690 bytes

For some reason, the added command line options for the compiler (via the patched IDE) make the resulting code 10.7K while the patched libc.a (which works exactly the same) results in 8.3K of code.

I wonder what else the command line option is adding that the patched libc.a is not?

I'm stumped on this one.

Krupski:
Awesome! Thanks for that. I had been looking through the “Compiler.java” code to find where to add that line, but wasn’t making any progress.

Now it works… and I also added an option to the “Preferences” to enable or disable floating point.

Bump :slight_smile: How did you do that?

Krupski: along with my additions (the "Upload, then Monitor" button and the "Floating point enable/disable" option)

Those both sound like very useful features - are your additions published anywhere?

WOW thanks a lot, works great.

appreciated.