Documentation:AVR GCC/AVR GCC Tool Collection

From AVRFreaks Wiki

Jump to: navigation, search

[edit] Components of the AVR-GCC toolchain

Most compilers you have probably used already were all-in one packages with a little button that says 'Build', which you hit to get a binary. Behind the scene there is all sorts of other things going on though.

The tool chain starts generally at the compiler, which in this case is avr-gcc. This will turn your C code into assembly language files. The assembly language files would be as if you wrote the entire program in assembly, something you are probably trying to avoid. However the compiler only knows standard C. It doesn't know anything about the names of registers, the most efficient way to deal with floating point numbers on the AVR, and similar problems. If you only had the C compiler, you would need to refer to each register by its address and not name, you'd need to write the startup code, and much more! Obviously this is something that you don't want to do, and unlike many things you don't want to do you CAN avoid doing it.

For this there is avr-libc, which is the C library for the AVR. This includes all the header files that contain the addresses of port and register names, the floating point library, AVR-specific macros, and AVR start-up code. It also provides a lot of documentation, both on the library items itself as well as on a number of general items on the entire toolchain, including a FAQ.

Once you have the individual assembly files, the Assembler converts them into object files. Object files are a level of code that the AVR itself could run, the only thing is that there is not one file to program. There is as many object files as there is input source files, and things like the start-up code isn't even present. The linker (avr-ld) will take all these files, and cross-references function names between files to create one single object file. As well the linker will take modules from the C library and link them into the single object. Normally this result is in ELF format, so an object copy (with avr-objcopy) is performed to generate a HEX format file. If any assembly sources were used they are usually passed through the C preprocessor first, and then passed on to the assembler (avr-as). Note that these three programs are all contained in the GNU Binutils project, along with a number of other programs. The compiler, assembler, linker, and library form the core of the toolchain. Those programs are interconnected to a great degree, and although they are separate projects they are often developed somewhat together.

Finally now you could use avrdude to download to the target, or avr-gdb in combination with simulavrxx or avarice to simulate or emulate the target device.

Tool Name Tool Description Project
avr-gcc C cross compiler for producing AVR code gcc
avr-as Assembler for producing AVR code binutils
avr-ldLinker to link AVR object modules together binutils
avr-sizeDisplays information such as amount of FLASH or RAM taken by AVR object files binutils
avr-nmExtracts symbol table from an object file, similar to a map file binutils
avr-objdumpDisplays, extracts, or copies information from many AVR object file formats binutils
avr-objcopyCopies or extracts parts of AVR object files, possibly converting formats as well binutils
avr-libcC runtime libraries, header files, and documentation for AVR target avr-libc
avrdude Connects to programming hardware to download code into AVR avrdude
avr-gdb Debugger for the AVR target, needs a backend such as simulator or emulator gdb
avarice Connects to the JTAG-ICE (AVR emulator), and allows it to work with avr-gdb avarice
simulavrProvides a simulator backend for avr-gdb simulavr

[edit] Development automation: the make utility

While not strictly a part of the toolchain, all the tools are often glued together by a utility that is called make. It automates the build process, by verifying existing targets (i.e. files) and their timestamp against the list of preriquisites, as controlled by a Makefile.

Personal tools