Next: , Previous: ARM Options, Up: Submodel Options

3.17.3 AVR Options

These options are defined for AVR implementations:

Specify Atmel AVR instruction set architectures (ISA) or MCU type.

For a complete list of mcu values that are supported by avr-gcc, see the compiler output when called with the --help=target command line option. The default for this option is avr2.

avr-gcc supports the following AVR devices and ISAs:

This ISA is implemented by the minimal AVR core and supported for assembler only.
mcu = at90s1200, attiny10, attiny11, attiny12, attiny15, attiny28.
“Classic” devices with up to 8 KiB of program memory.
mcu = at90s2313, attiny26, at90c8534, ...
“Classic” devices with up to 8 KiB of program memory and with the MOVW instruction.
mcu = attiny2313, attiny261, attiny24, ...
“Classic” devices with 16 KiB up to 64 KiB of program memory.
mcu = at43usb355, at76c711.
“Classic” devices with 128 KiB of program memory.
mcu = atmega103, at43usb320.
“Classic” devices with 16 KiB up to 64 KiB of program memory and with the MOVW instruction.
mcu = at90usb162, atmega8u2, attiny167, ...
“Enhanced” devices with up to 8 KiB of program memory.
mcu = atmega8, atmega88, at90pwm81, ...
“Enhanced” devices with 16 KiB up to 64 KiB of program memory.
mcu = atmega16, atmega6490, at90can64, ...
“Enhanced” devices with 128 KiB of program memory.
mcu = atmega128, at90can128, at90usb1287, ...
“Enhanced” devices with 3-byte PC, i.e. with at least 256 KiB of program memory.
mcu = atmega2560, atmega2561.

Accumulate outgoing function arguments and acquire/release the needed stack space for outgoing function arguments once in function prologue/epilogue. Without this option, outgoing arguments are pushed before calling a function and popped afterwards.

Popping the arguments after the function call can be expensive on AVR so that accumulating the stack space might lead to smaller executables because arguments need not to be removed from the stack after such a function call.

This option can lead to reduced code size for functions that perform several calls to functions that get their arguments on the stack like calls to printf-like functions.

Set the branch costs for conditional branch instructions to cost. Reasonable values for cost are small, non-negative integers. The default branch cost is 0.
Functions prologues/epilogues expanded as call to appropriate subroutines. Code size will be smaller.
Assume int to be 8-bit integer. This affects the sizes of all types: a char will be 1 byte, an int will be 1 byte, a long will be 2 bytes and long long will be 4 bytes. Please note that this option does not comply to the C standards, but it will provide you with smaller code size.
Generated code is not compatible with hardware interrupts. Code size will be smaller.
Try to replace CALL resp. JMP instruction by the shorter RCALL resp. RJMP instruction if applicable. Setting -mrelax just adds the --relax option to the linker command line when the linker is called.

Jump relaxing is performed by the linker because jump offsets are not known before code is located. Therefore, the assembler code generated by the compiler will be the same, but the instructions in the executable may differ from instructions in the assembler code.

Use RCALL/RJMP instructions even on devices with 16 KiB or more of program memory, i.e. on devices that have the CALL and JMP instructions. See also the -mrelax command line option.
Use address register X in a way proposed by the hardware. This means that X will only be used in indirect, post-increment or pre-decrement addressing.

Without this option, the X register may be used in the same way as Y or Z which then is emulated by additional instructions. For example, loading a value with X+const addressing with a small non-negative const < 64 to a register Rn will be performed as

          adiw r26, const   ; X += const
          ld   Rn, X        ; Rn = *X
          sbiw r26, const   ; X -= const

Only use the lower 8 bits of the stack pointer and assume that the high byte of SP is always zero. EIND and Devices with more than 128 Ki Bytes of Flash

Pointers in the implementation are 16 bits wide. The address of a function or label is represented as word address so that indirect jumps and calls can target any code address in the range of 64 Ki words.

In order to facilitate indirect jump on devices with more than 128 Ki bytes of program memory space, there is a special function register called EIND that serves as most significant part of the target address when EICALL or EIJMP instructions are used.

Indirect jumps and calls on these devices are handled as follows by the compiler and are subject to some limitations: AVR Built-in Macros

avr-gcc defines several built-in macros so that the user code can test for presence of absence of features. Almost any of the following built-in macros are deduced from device capabilities and thus triggered by the -mmcu= command-line option.

For even more AVR-specific built-in macros see AVR Named Address Spaces and AVR Built-in Functions.

Setting -mmcu=device defines this built-in macro which reflects the device's name. For example, -mmcu=atmega8 will define the built-in macro __AVR_ATmega8__, -mmcu=attiny261a defines __AVR_ATtiny261A__, etc.

The built-in macros' names follow the scheme __AVR_Device__ where Device is the device name as from the AVR user manual. The difference between Device in the built-in macro and device in -mmcu=device is that the latter is always lowercase.

The device has the RAMPZ special function register and thus the ELPM instruction.
The device has the ELPM Rn,Z and ELPM Rn,Z+ instructions.
The device has the MOVW instruction to perform 16-bit register-register moves.
The device has the LPM Rn,Z and LPM Rn,Z+ instructions.
The device has a hardware multiplier.
The device has the JMP and CALL instructions. This is the case for devices with at least 16 KiB of program memory and if -mshort-calls is not set.
The device has the EIJMP and EICALL instructions. This is the case for devices with at least 256 KiB of program memory. This also means that the program counter (PC) is 3 bytes wide.
The program counter (PC) is 2 bytes wide. This is the case for devices with up to 128 KiB of program memory.
The stack pointer (SP) is respectively 8 or 16 bits wide. The definition of these macros is affected by -mtiny-stack.
This macro reflects the -mno-interrupts command line option.
Some AVR devices (AT90S8515, ATmega103) must not skip 32-bit instructions because of a hardware erratum. Skip instructions are SBRS, SBRC, SBIS, SBIC and CPSE. The second macro is only defined if __AVR_HAVE_JMP_CALL__ is also set.
Instructions that can address I/O special function registers directly like IN, OUT, SBI, etc. may use a different address as if addressed by an instruction to access RAM like LD or STS. This offset depends on the device architecture and has to be subtracted from the RAM address in order to get the respective I/O address.