AVR on linux

From OmgaV Wiki

Jump to: navigation, search

Contents

AVR programming on linux

Code::Blocks

Code::Blocks is an excellent IDE is for AVR programming on linux. http://www.codeblocks.org


Makefile example

For the hardcore hacker only a proper makefile is good enough. The following is an example makefile for compiling, linking, packing and flashing an AVR microcontroller.

Be sure to change the following variables:

* jtagmkII to your programmer (stk500/600 etc)
* MCU Target architecture type for compiling
* MCUSHORT Target type for flashing
* And of course the source list

And read up on avrdude if you need.

###################################
# Makefile, for AVR Programming
 
 
# Target name:
TARGET = output
 
# Target type
MCU=atmega162
F_CPU=4915200UL
 
 
SRC = main.c uart.c
OBJ = $(SRC:.c=.o)
 
 
# Compiler / Linker flags:
CFLAGS = -mmcu=$(MCU) -Wall -Os -std=gnu99 -D F_CPU=$(F_CPU) -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
LDFLAGS = -mmcu=$(MCU) -Wl,-Map=$(TARGET).map
 
 
 
###################################
# Makerules:
 
 
.PHONY: compile flash clean
 
compile: $(TARGET).hex $(TARGET).eep $(TARGET).lss
 
flash: compile
avrdude -c jtagmkII -P usb -p $(MCU) -U flash:w:$(TARGET).hex
# sleep 2
# avrdude -c jtagmkII -P usb -p $(MCU) -U eeprom:w:$(TARGET).eep
 
clean:
rm -f $(OBJ) $(TARGET).{elf,hex,lss,map,eep}
 
 
 
###################################
# Psudorules:
 
%.eep: %.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ihex $< $@
 
%.hex: %.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@
 
%.lss: %.elf
avr-objdump -h -S $< > $@
 
%.elf: $(OBJ)
avr-gcc $^ $(LDFLAGS) -o $@
 
%.o : %.c
avr-gcc $(CFLAGS) -c $< -o $@

Shortcomings

If you need to program on the brand new AVR XMEGA (This is 2010), use AVR-Studio on virtualbox or real windows. It should also be possible to run the winAVR compiler in wine.

Personal tools