Avr-gcc 4.5.1, Avr-libc 1.7.1 and delay problems
In order to support more and newer processors in Xmegaduino (especially the new Xmega with integrated USB), we needed to update the avr-gcc package version from 4.3.3.
To do this, we compiled avr-gcc 4.5.1 together with Avr-libc 1.7.1 for Windows, Mac OS X and both 32 and 64-bit Linux. This is the same toolchain that is used in Atmel Studio 5.0, 5.1 and 6.0.
While testing this new toolchain compiling one of our own projects, we got this error:
Turning on the define __DELAY_BACKWARDCOMPATIBLE\_ worked and it compiled as promised. But we use "-ffreestanding" for some of our code (such as the firmware for TWIDisplay) and the above states that in that case we shouldn't need to define __DELAY_BACKWARDCOMPATIBLE\_? Some googling on the issue didn't result in much. Almost everyone with this error message were using _delay_ms() function with a variable and that is no longer allowed in avr-libc 1.7.1. Only a few had like us only _delay_ms() with a constant but no-one seemed to be able to help.
After some debugging and head scratching it became clear that without -ffreestanding the code compiled but why was the statement in the documentation not correct? After 1.7.1 was released there is also a 1.8.0 released. In 1.8.0 it does also check if –ffreestanding is defined and defaults to the same behaviour as __DELAY_BACKWARDCOMPATIBLE\_, this was missing in 1.7.1, and thus you need to specify __DELAY_BACKWARDCOMPATIBLE\_ if you want to use -ffreestanding. The documentation is written for 1.8.0, not for 1.7.1.
In other words __DELAY_BACKWARDCOMPATIBLE\_ is required for 1.7.1, but not in 1.8.0.