Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

avrdude gcc question
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

avrdude gcc question

by soggybag on Sat Aug 21, 2010 2:36 am

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.

soggybag
 
Posts: 35
Joined: Sat Mar 01, 2008 3:28 am

Re: avrdude gcc question

by Algolosaur on Sat Aug 21, 2010 10:26 am

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:


Code: Select all | TOGGLE FULL SIZE
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


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
Veritas Vos Fugere Facet
Algolosaur
 
Posts: 67
Joined: Sun Apr 05, 2009 11:29 am
Location: Butler PA

Re: avrdude gcc question

by soggybag on Sat Aug 21, 2010 11:34 am

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.

soggybag
 
Posts: 35
Joined: Sat Mar 01, 2008 3:28 am

Re: avrdude gcc question

by pstemari on Sat Aug 21, 2010 4:45 pm

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.
--Paul

A wholly owned subsidiary of:
Persephone: DL R+W+B C 7 X L W C++ I++ T+ A E H++ S+ V-- F+ Q P B PA+ PL
Aldebaran: DM Rt H 5 Y L- W+ C+ I++ T++ A+++ E H++ S+ V+ F++ Q+ P B++ PA- PL--
User avatar
pstemari
 
Posts: 310
Joined: Sun Mar 21, 2010 6:10 pm
Location: Seattle, WA

Re: avrdude gcc question

by Algolosaur on Sat Aug 21, 2010 5:05 pm

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

Code: Select all | TOGGLE FULL SIZE
# 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
Veritas Vos Fugere Facet
Algolosaur
 
Posts: 67
Joined: Sun Apr 05, 2009 11:29 am
Location: Butler PA

Re: avrdude gcc question

by pstemari on Sat Aug 21, 2010 11:36 pm

That's pretty simple. Ignoring the echo lines,

Code: Select all | TOGGLE FULL SIZE
%.hex: %.elf
        $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@


just means you turn a .elf file to a .hex file by running objcopy -O format -R .eeprom, and

Code: Select all | TOGGLE FULL SIZE
%.eep: %.elf
        -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
        --change-section-lma .eeprom=0 -O $(FORMAT) $< $@


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.
--Paul

A wholly owned subsidiary of:
Persephone: DL R+W+B C 7 X L W C++ I++ T+ A E H++ S+ V-- F+ Q P B PA+ PL
Aldebaran: DM Rt H 5 Y L- W+ C+ I++ T++ A+++ E H++ S+ V+ F++ Q+ P B++ PA- PL--
User avatar
pstemari
 
Posts: 310
Joined: Sun Mar 21, 2010 6:10 pm
Location: Seattle, WA

Please be positive and constructive with your questions and comments.