CDK4AVR HOWTO for Fedora 6
|
This is a HOWTO
detailing my experiences with setting up the AVR cross-compiler tools
under Fedora 6 using the cdk4avr
suite. These tools are available in source form and in binary form for
the i586 architecture. If you have a 64 bit PC then you can still use
most of the tools by installing the binaries. Good luck with
compilation. It is no doubt possible but under Fedora you will need to
do some work. I may add this later if I find some enthusiasm for it.
InstallationWhen installing the rpms, the software is placed in
/opt/cdk4avr. Note that there are no docs or man pages
provided in the basic packages and these must be accessed separately.
Obtain the following i586.rpms through the cdk4avr home page, which has
a description and status given for each package.
Compilation of AVR ProgramsThere is some valuable information given in the Guido
Socher article. Test CompilationTest the installation with a C program from the LinuxFocus site avrm8ledtest.c. For an ATMega8 MCU compile and link with: $ avr-gcc -mmcu atmega8 avrm8ledtest.c -o avrm8ledtest.o This will produce avrm8ledtest.o. avr-gccA simple compile will perform both a compile and link process. The -c option will perform the compilation but will not link. This is necessary if there are additional external files to be linked. Linking is done at the end of the process by taking all the object files as inputs and using avr-gcc again, eg $ avr-gcc -mmcu=atmega8 -o uart.o uart.c $ avr-gcc -mmcu=atmega8 -o acquisition.o acquisition.c $ avr-gcc -mmcu=atmega8 -o acquisition.out uart.o acquisition.o avr-objcopy In order to
produce a file suitable for uploading
to the MCU.
we need to convert it to a
hex format. This command converts the output object file into such a
format. $ avr-objcopy -R .eeprom -O ihex avrm8ledtest.o avrm8ledtest.hex This removes a section .eeprom and outputs in the ihex (Intel Hex) format. MakefileA sample makefile template written by Eric B. Weddington, J. G Wunsch, et al. can be used to compile multiple files. This just needs to be edited to add the MCU type and files to be compiled. Commands are: $ make $ make clean $ make all $ make program The latter will download using avrdude. A make will compile to an object file, and create files for Flash and EPROM memory, so that the only command needed after a make would be to upload. In the makefile template change the following lines for the avr-gcc compiler to suit your system: ----------------------------------------------------------------------------------------------- # Change to whatever MCU you are using (check the avr-gcc
documentation for the appropriate names) MCU = atmega8
# Output format. (can be srec, ihex, binary) FORMAT = ihex
#
Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization. s
gives smallest code. OPT = s
# Target file name (without extension). TARGET = application
# List C source files here. (C dependencies are automatically generated.) SRC = $(TARGET).c ----------------------------------------------------------------------------------------------- Programming the DeviceAvrdude is quite good and is currently being
maintained. In the absence of a commercial programmer, the best
interface to use if you have
access to a parallel port is DAPA which is quite
reliable. Avrdude can use some serial protocols, toggling certain
lines to provide the reset and clock signals. These are DASA (appears
to be unreliable) and DASA3 (unknown reliability). The Guido
Socher article gives information about how to make a DAPA cable. I
made one from an old Centronics printer cable that was passing by on
its way to landfill. If
you use a commercial programmer or cable, quite likely avrdude will
support it. The command line to use for our ATMega8 and DAPA cable is: $ sudo avrdude -p m8 -c dapa -e -v -U flash:w:application.hex:a The relevant command line parameters are:
Note
that access to the parallel port requires root privileges, hence the sudo command. Many websites
recommend changing the privileges on the /dev/parport0 device file but with udev now generating these device
files on boot, such an operation would need to be repeated each time
the PC is booted (unless you can convince udev to do it for you). In the makefile template locate the program: section and modify it by adding the following to allow make program to work:
----------------------------------------------------------------------------------------------- AVRDUDE_PROGRAMMER = dapa AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER) -v -e AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
program: $(TARGET).hex $(TARGET).eep sudo '$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)' ----------------------------------------------------------------------------------------------- Fuse Bits
|