Go Down

Topic: Help to upgrade avr-libc to a newer version in the arduino ide (Read 3473 times) previous topic - next topic


Jul 08, 2011, 05:53 pm Last Edit: Jul 08, 2011, 06:01 pm by flyeagle Reason: 1
Hello, this is my first post!!! (take care of this and about my not perfect english) :-)

I have a problem to compile a sketch into the arduino original IDE (under windows).
My problem is very strange and very long because i have tried without success many ways to resolve it!
Let's go...

----- How the problem come out -----
I wrote a sketch for arduino Mega 2560 and the original Ethernet shield.
For the purpose I have found a library that seems to be ok.
It use the micro-SD on the Ethernet shield and like a webserver send all the page requested by a broswer.

I modified the example called "FileUpload" by adding a function and an handler to manage a GET request with parameters (.../example.htm?param1=123).
All things work ok!!!
I receive the parameter from the browser and, in my function, I manage it correctly! (obviously the arduino IDE compile it without problems).

But this webserver freeze in a particular condition!
All the functions in arduino locks: I used a blinking led, in a cooperative task mode, like an heartbeat and it don't blink anymore when the arduino freeze.
Using some debug I found that the cause is a browser request of the file "favicon.ico" (the little icon on the left of the address bar) after a reset of arduino.
More debug shown me that the function, called from the library, that freeze is malloc()!
Malloc() (memory allocation) is called many times but freeze only in that code flow position (the call is made for allocate 8 byte when I have more than 6kB free...)

Google shown me that malloc() in avr-libc 1.6.4 (arduino 0022) have a bug:

Seems that in the avr-libc 1.7.1 (the last update available) these bugs have been corrected so I want to upgrade the arduino libc to this version and compile again.

----- How I tried to solve the problem -----
Arduino ide use winavr to compile.
I have seen that replacing the folder "avr" in the path "...\arduino\hardware\tools\" with the installation path of a newer version of winavr I can upgrade the avr-libc.

At this point the problem is that winavr in not more manteined... (last update is 20100110 / libc 1.6.7 and don't work: arduino freeze) http://arduino.cc/forum/index.php/topic,61093.0.html

So I tried to use MHV tools http://www.makehackvoid.com/group-projects/mhvavrtools or Atmel's toolchain http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4118&category_id=163&family_id=607&subfamily_id=760
that both have the avr-libc 1.7.1 version.

In both cases I substituted the folder "avr" and tried to compile (the avr tools also need an "#include math.h" somewhere...) but I receive from the compiler the same error:

----- The final problem -----

In file included from c:\programmi\arduino\hardware\tools\avr\bin\../lib/gcc/avr/4.5.2/../../../../avr/include/util/delay.h:42:0,
                from c:\programmi\arduino\hardware\tools\avr\bin\../lib/gcc/avr/4.5.2/../../../../avr/include/avr/delay.h:37,
                from C:\Programmi\arduino\hardware\arduino\cores\arduino\/wiring_private.h:30,
                from C:\Programmi\arduino\hardware\arduino\cores\arduino\WInterrupts.c:34:
c:\programmi\arduino\hardware\tools\avr\bin\../lib/gcc/avr/4.5.2/../../../../avr/include/math.h:426:15: error: expected identifier or '(' before 'double'
c:\programmi\arduino\hardware\tools\avr\bin\../lib/gcc/avr/4.5.2/../../../../avr/include/math.h:426:15: error: expected ')' before '>=' token

Seems that there is a problem with the function at row 426 in the file math.h

--- math.h ---
419:    The round() function rounds \a __x to the nearest integer, but rounds
420:    halfway cases away from zero (instead of to the nearest even integer).
421:    Overflow is impossible.
423:    \return The rounded value. If \a __x is an integral or infinite, \a
424:    __x itself is returned. If \a __x is \c NaN, then \c NaN is returned.
425: */
426:extern double round (double __x) __ATTR_CONST__;
427:#define roundf   round      /**< The alias for round().   */

like in this post http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=84750&start=0 seems that somewere the round function is declared as a macro, but I am not able to find where.

I want to find a secure way to upgrade the avr folder and compile (successfully) with the arduino ide and an avr-libc upgraded and this post may be a reference to all the arduino user community.
I prefer to adopt the atmel's toolchains that seems to be more updated

Thank for replies and I wait for someone that can help me to understand what don't work.
Sorry again for the length of the exposition.

Coding Badly

This is what I do to "upgrade" to the latest WinAVR version...


Ok. This is what i have yet done. But arduino freeze in the same manner.
Last winavr version have avr-libc 1.6.7 but i think that i need 1.7.1 version.
But using atmel's toolchain (avr-libc 1.7.1) i have the compiler error, and i don't understand why...

What can i do to find the source of the compiler error?

Coding Badly


Regarding 'round'. You need to disable the macro in 'wiring.h'.


Jul 09, 2011, 12:17 pm Last Edit: Jul 09, 2011, 12:32 pm by flyeagle Reason: 1
@Coding Badly:
  I tried the option Shift + Verify (i didn't know) and i saw all the compiler options plus the files' path compiled... but nothing interesing about my compiler problem.
Thank you anyhow

  I opened the "wiring.h" in arduino core folder and I found the fucked macro that locks the compiling process.
Thank you very much!

Code: [Select]
---- wiring.h ----
78:#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
79:[b]#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))[/b]
80:#define radians(deg) ((deg)*DEG_TO_RAD)

Commenting the row #79 I can compile correctly!!! Finally!!! :-)

Unfortunately Arduino works worst: it receive from the browser a trash request (random characters) :-(

I think that the last hope to run my webserver correctly is to overhaul TinyWebServer code perhaps removing the use of malloc... a long process indeed.

Returning to the topic question now i have partially an answer:
  1- avr-libc can be upgraded with Atmel's tools simply substituting a folder
  2- if I have some macros error I can disable their in the file "wiring.h" simply commenting the right row
  3- is possible that something don't works well... debug!!!

But i don't understand why the macro in "wiring.h" create compiler error with a newer "avr folder" version...
Compiling with the original arduino 0022 "avr" folder the round macro works well;
compiling with the Atmel's "avr" folder the round  macro makes errors...


Jack Christensen

This is what I do to "upgrade" to the latest WinAVR version...

Old thread I know, but just wanted to say thanks. Been meaning to try this for some time, and I would have tried the same approach but always good to find that the trail has already been blazed. Of course I probably would have had to find the part about relocating avrdude.conf the hard way!

All seems well so far, which leads me again to wonder why the latest version isn't included in the IDE, whether there are some known gotchas or whatever.

Coding Badly

Old thread I know, but just wanted to say thanks.

You are welcome!

All seems well so far, which leads me again to wonder why the latest version isn't included in the IDE, whether there are some known gotchas or whatever.

I wonder that too.  After years of using the "new" toolset I have yet to find a reason to switch back to the old version.

Go Up