A GNU Development Environment for the AVR Microcontroller

Rich Neswold

rneswold@earthlink.net

This document attempts to cover the details of the GNU Tools that are specific to the AVR family of processors.

Note: The contents of this document have been updated since the last version. However, there is still a lot that needs to be done. Thank you for being patient. If you would prefer, this document is also available as a PDF or Postscript file.


Acknowledgements

This document tries to tie together the labors of a large group of people. Without these individuals' efforts, we wouldn't have a terrific, free set of tools to develop AVR projects. We all owe thanks to:

Table of Contents
1. Installing the GNU Tools
1.1. GNU Binutils
1.2. AVR-GCC
1.2.1. Downloading the Source
1.2.2. Building the Project
1.2.3. Installing the Tools
1.3. AVR-LIBC
1.3.1. Downloading the Source
1.3.2. Building the Libraries
1.3.3. Installing the Libraries and Header Files
1.4. Programming Your Processor
1.4.1. Using avrprog
1.4.2. Using uisp
2. Using the GNU Tools
2.1. The Project
2.2. Compiling and Linking
2.3. "Map" Files
2.4. Generating .hex Files
2.5. Letting Make Build the Project
3. Application Start-up
4. Standard C Library
4.1. Function Reference
4.1.1. abort
4.1.2. abs
4.1.3. atoi
4.1.4. atol
4.1.5. bsearch
4.1.6. cos
4.1.7. cosh
4.1.8. div
4.1.9. exit
4.1.10. fabs
4.1.11. isalnum, isalpha, isascii, isblank, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit
4.1.12. labs
4.1.13. ldiv
4.1.14. longjmp
4.1.15. qsort
4.1.16. setjmp
4.1.17. sin
4.1.18. sinh
4.1.19. sqrt
4.1.20. tan
4.1.21. toascii
4.1.22. tolower, toupper
5. Memory APIs
5.1. Program Memory
5.2. Function Reference
5.2.1. __ATTR_CONST__, __ATTR_PROGMEM__, __ATTR_PURE__
5.2.2. __elpm_inline
5.2.3. __lpm_inline
5.2.4. memcpy_P
5.2.5. PRG_RDB
5.2.6. PSTR
5.2.7. strcat_P
5.2.8. strcmp_P
5.2.9. strcpy_P
5.2.10. strcasecmp_P
5.2.11. strlen_P
5.2.12. strncasecmp_P
5.2.13. strncmp_P
5.2.14. strncpy_P
5.3. EEPROM
5.4. Function Reference
5.4.1. eeprom_is_ready
5.4.2. eeprom_rb
5.4.3. eeprom_read_block
5.4.4. eeprom_rw
5.4.5. eeprom_wb
6. Interrupt API
6.1. Function Reference
6.1.1. cli
6.1.2. enable_external_int
6.1.3. INTERRUPT
6.1.4. sei
6.1.5. SIGNAL
6.1.6. timer_enable_int
7. I/O API
7.1. I/O Port APIs
7.2. Function Reference
7.2.1. BV
7.2.2. bit_is_clear
7.2.3. bit_is_set
7.2.4. cbi
7.2.5. inp
7.2.6. __inw
7.2.7. __inw_atomic
7.2.8. loop_until_bit_is_clear
7.2.9. loop_until_bit_is_set
7.2.10. outp
7.2.11. __outw
7.2.12. __outw_atomic
7.2.13. parity_even_bit
7.2.14. sbi
7.3. Watchdog API
7.4. Function Reference
7.4.1. wdt_disable
7.4.2. wdt_enable
7.4.3. wdt_reset
A. AVR-GCC Configuration
A.1. avr-as Options
A.2. avr-gcc Options
List of Tables
1-1. Tarball Locations
5-1. Primitive types in program memory
6-1. Signal names
A-1. avr-as Options
A-2. avr-gcc Options
List of Figures
2-1. Schematic of demo project
3-1. Hex file for empty main()
List of Examples
2-1. Demo source code
2-2. Disassembly of Demo Application
2-3. Portion of demo map file
2-4. Makefile for Demo Project
3-1. Code that runs immediately after RESET.
3-2. Configuring the watchdog during reset
5-1. Proper use of EEPROM variables
6-1. Setting up an interrupt handler
6-2. Setting up a signal handler