1- To compile a AVR code, you need to install three packages which are avr-binutils, avr-gcc, and avr-libc. They are simply available through Synaptic Pakage Manager.
To compile a C code for ATmega128, avr-gcc first creates .elf file using this command:
avr-gcc -mmcu=atmega128 filename.c -o filename.elf
elf extension is not the right one for flash memory programming. Then I used the following command to make .hex file which is suitable to download to the flash memory:
avr-objcopy -j .text -j .data -O ihex filename.elf filename.hex
In both command, there are few more options you need for different reason that I ignore at the moment since I don't need them now :)2- Avrdude is the next command that I need to download the .hex file and it is also available in Synaptic Package Manager. It has also few useful options while I just used two of them that I need to erase the memory and write to the memory:
avrdude -c avrispv2 -p m128 -P usb -e
The above command says that programmer or connector (-c) is a AVR ISP MKII (avrispv2), the device or part number (-p) is ATmega128, connecting port (-P) is through usb, and -e erase the memory.
Up to usb is explained in last command. -U updates the memory and its syntax is:r|w|v:[:format] which in my case I am writing to ATmega128 (a flash memory), it may be an EEPROM or etc. w stands for write, r for read, v for verification, and declare your filename at the end.
avrdude -c avrispv2 -p m128 -P usb -U flash:w:filename.hex
Up to usb is explained in last command. -U updates the memory and its syntax is
No comments:
Post a Comment