ATmega32 USBasp Notes

USBasp programmer for Atmel AVR microcontrollers

Connect to an ATmega32 with a USBasp programmer and enter terminal mode:

$ avrdude -c usbasp -p m32 -P usb -t

Assemble:

$ avr-as -mmcu=avr5 -o blinken.o blinken.s

Linking without avr-libc:

$ avr-ld blinken.o

Compiling:

$ avr-gcc -c -O2 -mmcu=atmega32 -o blinken.o blinken.c

Linking with avr-libc:

$ avr-gcc -O2 -mmcu=atmega32 -Wl,-Map,blinken.map -o blinken.elf blinken.o

Dumping a listing:

$ avr-objdump -h -S blinken.elf > blinken.lst

Copying the text and data sections to various formats:

$ avr-objcopy -j .text -j .data -O ihex blinken.elf blinken.hex
$ avr-objcopy -j .text -j .data -O binary blinken.elf blinken.bin
$ avr-objcopy -j .text -j .data -O srec blinken.elf blinken.srec

If EEPROM is used:

$ avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex blinken.elf blinken_eeprom.hex
$ avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O binary blinken.elf blinken_eeprom.bin
$ avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O srec blinken.elf blinken_eeprom.srec

Writing to the flash memory:

$ avrdude -c usbasp -p m32 -P usb -U flash:w:blinken.bin:r

Reading from memory:

$ avrdude -c usbasp -p m32 -P usb -U flash:r:blinken_flash.bin:r
$ avrdude -c usbasp -P m32 -P usb -U eeprom:r:blinken_eeprom.bin:r

Compile, Link, Copy, Write:

$ avr-gcc -c -O2 -mmcu=atmega32 -o blinken.o joystick.c 
$ avr-gcc -O2 -mmcu=atmega32 -Wl,-Map,blinken.map -o blinken.elf blinken.o
$ avr-objcopy -j .text -j .data -O ihex blinken.elf blinken.hex
$ avrdude -c usbasp -p atmega32 -P usb -U flash:w:blinken.hex:i

Disable JTAG:

Note: changes hfuse (configuration is default-JTAG)

$ avrdude -c usbasp -p atmega32 -P usb -U hfuse:w:0xD9:m

Reset hfuse to Default:

$ avrdude -c usbasp -p atmega32 -P usb -U hfuse:w:0x99:m

Sections