AVR WinAVR and avr-gcc Tutorial
using
Free C-Compiler WinAVR based on gnu-gcc (avr-gcc)

 

 

  1. Download and installation instructions for WinAVR

  2. Special installation notes for WinAVR as free C-Compiler for AVR ATmega2560 / ATmega2561

  3. WinAVR C example program, source code available, for
    ATmega128, ATmega1281, ATmega1280

  4. WinAVR C example program, source code available, for ATmega2560, ATmega2561

  5. ISP-programming instructions for code upload to flash of AVR device using avrdude

  6. Special notes for ISP-programming of ATmega2560 / ATmega2561 using avrdude

 



 

  1. Download and installation instructions for WinAVR

    Download WinAVR (here Version WinAVR-20060125) from WinAVR-sourceforge and install program.

     

  2. Special installation notes for WinAVR as free C-Compiler for AVR ATmega2560 / ATmega2561

    ATmega2560 and ATmega2561 are by now not supported in Version 20060125 of WinAVR.
    You need to install a patch to compile source code for ATmega2560 and ATmega2561 devices.
    Download patch (GCC4.1-WINAVR) for WinAVR 20060125.
    Extract the file into your WinAVR installation directory.
     

  3. WinAVR C example program, source code available, for
    ATmega128, ATmega1281, ATmega1280

    The following source code in ATmega256x_demo.zip includes a modified version of the WinAVR example demo.c for ATmega128, ATmega1281, ATmega1280.
     

  4. WinAVR C example program, source code available, for ATmega2560, ATmega2561

    The following source code in ATmega256x_demo.zip includes a modified version of the WinAVR example demo.c for ATmega2560 and ATmega2561.

    The following lines in red have been added to "iocompat.h".

    #elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) || \
    defined(__AVR_ATmega165__) || defined(__AVR_ATmega169__) || \
    defined(__AVR_ATmega325__) || defined(__AVR_ATmega3250__) || \
    defined(__AVR_ATmega645__) || defined(__AVR_ATmega6450__) || \
    defined(__AVR_ATmega329__) || defined(__AVR_ATmega3290__) || \
    defined(__AVR_ATmega649__) || defined(__AVR_ATmega6490__) || \
    defined(__AVR_ATmega640__) || \
    defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || \
    defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)

    The "makefile" have been adopted:
    #MCU_TARGET = atmega1280
    #MCU_TARGET = atmega1281
    MCU_TARGET = atmega2560
    #MCU_TARGET = atmega2561


    For compiling use "make".

    C:\WinAVR\examples\ATmega256xdemo>make clean
    rm -rf *.o demo.elf *.eps *.png *.pdf *.bak
    rm -rf *.lst *.map *.hex *.bin *.srec

    C:\WinAVR\examples\ATmega256xdemo>make
    avr-gcc -g -Wall -O2 -mmcu=atmega2560 -c -o demo.o demo.c
    avr-gcc -g -Wall -O2 -mmcu=atmega2560 -Wl,-Map,demo.map -o demo.elf demo.o
    avr-objdump -h -S demo.elf > demo.lst
    avr-objcopy -j .text -j .data -O ihex demo.elf demo.hex
    avr-objcopy -j .text -j .data -O binary demo.elf demo.bin
    avr-objcopy -j .text -j .data -O srec demo.elf demo.srec
    avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex demo.elf demo_eeprom.hex
    avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O binary demo.elf demo_eeprom.bin
    avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O srec demo.elf demo_eeprom.srec

     

  5. ISP-programming instructions for code upload to flash of AVR device using avrdude

    In this tutorial avrdude is used the program the flash of the ATmega device:

    Note: You now have to use "flashfile.bin" instead of "flashfile.hex" unlike in prior versions (4.x).

    avrdude: Version 5.1

    >avrdude -p atmega128 -c stk200 -P lpt1 -U flash:w:demo.bin:r

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.01s

    avrdude: Device signature = 0x1e9702
    avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
    To disable this feature, specify the -D option.
    avrdude: erasing chip
    avrdude: reading input file "demo.bin"
    avrdude: writing flash (12058 bytes):

    Writing | ################################################## | 100% 8.07s

    avrdude: 12058 bytes of flash written
    avrdude: verifying flash memory against demo.bin:
    avrdude: load data flash data from input file demo.bin:
    avrdude: input file demo.bin contains 12058 bytes
    avrdude: reading on-chip flash data:

    Reading | ################################################## | 100% 7.81s

    avrdude: verifying ...
    avrdude: 12058 bytes of flash verified

    avrdude: safemode: Fuses OK

    avrdude done. Thank you.


     

  6. Special notes for ISP-programming of ATmega2560 / ATmega2561, i.e. upload code to flash, using avrdude

    Because AVR ATmega2560 and ATmega2561 devices are not supported by avrdude by now (Version WinAVR-20060125) use ATmega1280 mode instead:

    C:\WinAVR\examples\ATmega256xdemo>avrdude -p atmega1280 -c stk200 -P lpt1 -U flash:w:demo.bin:r

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.00s

    avrdude: Device signature = 0x1e9801
    avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

    To disable this feature, specify the -D option.
    avrdude: erasing chip
    avrdude: reading input file "demo.bin"
    avrdude: writing flash (486 bytes):

    Writing | ################################################## | 100% 0.17s

    avrdude: 486 bytes of flash written
    avrdude: verifying flash memory against demo.bin:
    avrdude: load data flash data from input file demo.bin:
    avrdude: input file demo.bin contains 486 bytes
    avrdude: reading on-chip flash data:

    Reading | ################################################## | 100% 0.16s

    avrdude: verifying ...
    avrdude: 486 bytes of flash verified

    avrdude: safemode: Fuses OK

    avrdude done. Thank you.

     

 

 

[SIPHEC home]