What is the command line to compile main.c into hex code?
I'm using avrdude and avr-gcc on the Mac with the USBTinyISP. I want to compile for the attiny13.
I'm new to AVR and µControllers. I was working on this last year and put it aside for awhile. I compiled a few programs, downloaded and ran them last year. I trying to pick up where I left off, and I can't seem to remember how to compile my main.c.
avrdude gcc question
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 67
- Joined: Sun Apr 05, 2009 11:29 am
Re: avrdude gcc question
I've been looking over various coding projects for Monochron, and the usual technique appears to be creating an .elf file and then using avr-objcopy to strip out the FLASH and EEPROM segments as Intel Hex files:
That's just a raw cut and paste from a "make -n" of the Multichron makefile, you would doubtless have other preferences for avr-gcc options and such.
Algolosaur
Code: Select all
echo Linking: MultiChron.elf
avr-gcc -mmcu=atmega328p -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -DF_CPU=8000000 -Wa,-adhlns=ratt.o -std=gnu99 ratt.o config.o buttons.o dispatch.o anim_rat.o anim_sev.o anim_int.o anim_xda.o anim_abo.o util.o glcd.o ks0108.o i2c.o rle.o --output MultiChron.elf -Wl,-Map=MultiChron.map,--cref
echo
echo Creating load file for Flash: MultiChron.hex
avr-objcopy -O ihex -R .eeprom MultiChron.elf MultiChron.hex
echo
echo Creating load file for EEPROM: MultiChron.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex MultiChron.elf MultiChron.eep
echo
Algolosaur
- soggybag
- Posts: 35
- Joined: Sat Mar 01, 2008 3:28 am
Re: avrdude gcc question
Thanks for the reply.
I figured the problem out myself this morning. Navigating to the directory where I have Demo.xcodeproj and firmware, I just type make. This seems to compile everything.
Of course I'm not sure why this works. There is a file named MakeFile in the firmware folder. This has all of the settings for my chip, attiny13. Why I don't need to include a path to this file or what options I should be using is a mystery.
I seem to have lost the location of the tutorial I was following last year. I thought it was on this site.
I figured the problem out myself this morning. Navigating to the directory where I have Demo.xcodeproj and firmware, I just type make. This seems to compile everything.
Of course I'm not sure why this works. There is a file named MakeFile in the firmware folder. This has all of the settings for my chip, attiny13. Why I don't need to include a path to this file or what options I should be using is a mystery.
I seem to have lost the location of the tutorial I was following last year. I thought it was on this site.
-
- Posts: 310
- Joined: Sun Mar 21, 2010 6:10 pm
Re: avrdude gcc question
Make looks for a file named makefile in the current directory by default.
If you look at it, you'll see rules for building the code, including all the required command lines.
If you look at it, you'll see rules for building the code, including all the required command lines.
-
- Posts: 67
- Joined: Sun Apr 05, 2009 11:29 am
Re: avrdude gcc question
And lest we forget, "make -n" will list the commands generated by the makefile without executing them, which is very useful for dealing with some of the more creative and elaborate makefiles out there. The lines I cited for "make -n" above correspond in part to the somewhat less informative
Algolosaur
Code: Select all
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
Algolosaur
-
- Posts: 310
- Joined: Sun Mar 21, 2010 6:10 pm
Re: avrdude gcc question
That's pretty simple. Ignoring the echo lines,
just means you turn a .elf file to a .hex file by running objcopy -O format -R .eeprom, and
just means you turn a .elf file to an .eep file by running objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O format, where objcopy and format are defined elsewhere.
Code: Select all
%.hex: %.elf
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
Code: Select all
%.eep: %.elf
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
Please be positive and constructive with your questions and comments.