Sida 1 av 1
Simpel Makefile för AVR?
Postat: 13 februari 2009, 18:37:23
av petterp
Har letat efter en makefile som skapar en hex fil, men har inte lyckats. Dem jag hittar gör en "main.o" fil, eller så gör den allt även programmera.
så min fråga, ifall nån kan förklara för mig hur man gör en makefil som enbart skapar mig en hexfil för avr? varken mer eller mindre.
tack på förhand
// petter
Re: Simpel Makefile för AVR?
Postat: 13 februari 2009, 19:53:54
av eqlazer
Om du nu har en makefile som även flashar, varför inte bara ta bort delen som gör flashningen?
Re: Simpel Makefile för AVR?
Postat: 13 februari 2009, 21:13:38
av SvenW
Som eqlazer säger, kan makefilen ladda ner i hårdvara så den skapar säkert en hexfil på vägen.
Kommandot kan vara 'make hex' eller nånting sådant.
Om inte så finns här ett exempel på makefil:
http://electrons.psychogenic.com/articles/Makefile.tpl
http://electrons.psychogenic.com/module ... sec/1/AVR/
Re: Simpel Makefile för AVR?
Postat: 14 februari 2009, 00:36:45
av petterp
det den säger då jag använder mallen för den makefilen är:
make: *** Ingen regel för att skapa målet "myclass.o", som behövs till "myproject.out". Stannar.
men hur mycket behöver av allt det som står med ifall man bara vill att den ska kompilera en hexfil?
Re: Simpel Makefile för AVR?
Postat: 14 februari 2009, 00:40:51
av speakman
En bra början vore att klistra in din Makefile inom ett par code-taggar?

Re: Simpel Makefile för AVR?
Postat: 14 februari 2009, 17:42:47
av petterp
Jag har säkert missat någon inställning som gör det jag vill jättesimpelt.
jag använder en atmega32
Kod: Markera allt
######### AVR Project Makefile Template #########
###### ######
###### Copyright (C) 2003-2005,Pat Deegan, ######
###### Psychogenic Inc ######
###### All Rights Reserved ######
###### ######
###### You are free to use this code as part ######
###### of your own applications provided ######
###### you keep this copyright notice intact ######
###### and acknowledge its authorship with ######
###### the words: ######
###### ######
###### "Contains software by Pat Deegan of ######
###### Psychogenic Inc (www.psychogenic.com)" ######
###### ######
###### If you use it as part of a web site ######
###### please include a link to our site, ######
###### http://electrons.psychogenic.com or ######
###### http://www.psychogenic.com ######
###### ######
####################################################
##### This Makefile will make compiling Atmel AVR
##### micro controller projects simple with Linux
##### or other Unix workstations and the AVR-GCC
##### tools.
#####
##### It supports C, C++ and Assembly source files.
#####
##### Customize the values as indicated below and :
##### make
##### make disasm
##### make stats
##### make hex
##### make writeflash
##### make gdbinit
##### or make clean
#####
##### See the http://electrons.psychogenic.com/
##### website for detailed instructions
####################################################
##### #####
##### Configuration #####
##### #####
##### Customize the values in this section for #####
##### your project. MCU, PROJECTNAME and #####
##### PRJSRC must be setup for all projects, #####
##### the remaining variables are only #####
##### relevant to those needing additional #####
##### include dirs or libraries and those #####
##### who wish to use the avrdude programmer #####
##### #####
##### See http://electrons.psychogenic.com/ #####
##### for further details. #####
##### #####
####################################################
##### Target Specific Details #####
##### Customize these for your project #####
# Name of target controller
# (e.g. 'at90s8515', see the available avr-gcc mmcu
# options for possible values)
MCU=atmega32
# id to use with programmer
# default: PROGRAMMER_MCU=$(MCU)
# In case the programer used, e.g avrdude, doesn't
# accept the same MCU name as avr-gcc (for example
# for ATmega8s, avr-gcc expects 'atmega8' and
# avrdude requires 'm8')
PROGRAMMER_MCU=m32
# Name of our project
# (use a single word, e.g. 'myproject')
PROJECTNAME=myproject
# Source files
# List C/C++/Assembly source files:
# (list all files to compile, e.g. 'a.c b.cpp as.S'):
# Use .cc, .cpp or .C suffix for C++ files, use .S
# (NOT .s !!!) for assembly source code files.
PRJSRC=main.c myclass.cpp lowlevelstuff.S
# additional includes (e.g. -I/path/to/mydir)
INC=-I/path/to/include
# libraries to link in (e.g. -lmylib)
LIBS=
# Optimization level,
# use s (size opt), 1, 2, 3 or 0 (off)
OPTLEVEL=s
##### AVR Dude 'writeflash' options #####
##### If you are using the avrdude program
##### (http://www.bsdhome.com/avrdude/) to write
##### to the MCU, you can set the following config
##### options and use 'make writeflash' to program
##### the device.
# programmer id--check the avrdude for complete list
# of available opts. These should include stk500,
# avr910, avrisp, bsd, pony and more. Set this to
# one of the valid "-c PROGRAMMER-ID" values
# described in the avrdude info page.
#
AVRDUDE_PROGRAMMERID=avrisp2
# port--serial or parallel port to which your
# hardware programmer is attached
#
AVRDUDE_PORT=usb
####################################################
##### Config Done #####
##### #####
##### You shouldn't need to edit anything #####
##### below to use the makefile but may wish #####
##### to override a few of the flags #####
##### nonetheless #####
##### #####
####################################################
##### Flags ####
# HEXFORMAT -- format for .hex file output
HEXFORMAT=ihex
# compiler
CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wstrict-prototypes \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.c=.lst)))
# c++ specific flags
CPPFLAGS=-fno-exceptions \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.cpp=.lst))\
$(filter %.lst, $(<:.cc=.lst)) \
$(filter %.lst, $(<:.C=.lst)))
# assembler
ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \
-x assembler-with-cpp \
-Wa,-gstabs,-ahlms=$(firstword \
$(<:.S=.lst) $(<.s=.lst))
# linker
LDFLAGS=-Wl,-Map,$(TRG).map -mmcu=$(MCU) \
-lm $(LIBS)
##### executables ####
CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
SIZE=avr-size
AVRDUDE=avrdude
REMOVE=rm -f
##### automatic target names ####
TRG=$(PROJECTNAME).out
DUMPTRG=$(PROJECTNAME).s
HEXROMTRG=$(PROJECTNAME).hex
HEXTRG=$(HEXROMTRG) $(PROJECTNAME).ee.hex
GDBINITFILE=gdbinit-$(PROJECTNAME)
# Define all object files.
# Start by splitting source files by type
# C++
CPPFILES=$(filter %.cpp, $(PRJSRC))
CCFILES=$(filter %.cc, $(PRJSRC))
BIGCFILES=$(filter %.C, $(PRJSRC))
# C
CFILES=$(filter %.c, $(PRJSRC))
# Assembly
ASMFILES=$(filter %.S, $(PRJSRC))
# List all object files we need to create
OBJDEPS=$(CFILES:.c=.o) \
$(CPPFILES:.cpp=.o)\
$(BIGCFILES:.C=.o) \
$(CCFILES:.cc=.o) \
$(ASMFILES:.S=.o)
# Define all lst files.
LST=$(filter %.lst, $(OBJDEPS:.o=.lst))
# All the possible generated assembly
# files (.s files)
GENASMFILES=$(filter %.s, $(OBJDEPS:.o=.s))
.SUFFIXES : .c .cc .cpp .C .o .out .s .S \
.hex .ee.hex .h .hh .hpp
.PHONY: writeflash clean stats gdbinit stats
# Make targets:
# all, disasm, stats, hex, writeflash/install, clean
all: $(TRG)
disasm: $(DUMPTRG) stats
stats: $(TRG)
$(OBJDUMP) -h $(TRG)
$(SIZE) $(TRG)
hex: $(HEXTRG)
writeflash: hex
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(PROGRAMMER_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(HEXROMTRG)
install: writeflash
$(DUMPTRG): $(TRG)
$(OBJDUMP) -S $< > $@
$(TRG): $(OBJDEPS)
$(CC) $(LDFLAGS) -o $(TRG) $(OBJDEPS)
#### Generating assembly ####
# asm from C
%.s: %.c
$(CC) -S $(CFLAGS) $< -o $@
# asm from (hand coded) asm
%.s: %.S
$(CC) -S $(ASMFLAGS) $< > $@
# asm from C++
.cpp.s .cc.s .C.s :
$(CC) -S $(CFLAGS) $(CPPFLAGS) $< -o $@
#### Generating object files ####
# object from C
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# object from C++ (.cc, .cpp, .C files)
.cc.o .cpp.o .C.o :
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# object from asm
.S.o :
$(CC) $(ASMFLAGS) -c $< -o $@
#### Generating hex files ####
# hex files from elf
##### Generating a gdb initialisation file #####
.out.hex:
$(OBJCOPY) -j .text \
-j .data \
-O $(HEXFORMAT) $< $@
.out.ee.hex:
$(OBJCOPY) -j .eeprom \
--change-section-lma .eeprom=0 \
-O $(HEXFORMAT) $< $@
##### Generating a gdb initialisation file #####
##### Use by launching simulavr and avr-gdb: #####
##### avr-gdb -x gdbinit-myproject #####
gdbinit: $(GDBINITFILE)
$(GDBINITFILE): $(TRG)
@echo "file $(TRG)" > $(GDBINITFILE)
@echo "target remote localhost:1212" \
>> $(GDBINITFILE)
@echo "load" >> $(GDBINITFILE)
@echo "break main" >> $(GDBINITFILE)
@echo "continue" >> $(GDBINITFILE)
@echo
@echo "Use 'avr-gdb -x $(GDBINITFILE)'"
#### Cleanup ####
clean:
$(REMOVE) $(TRG) $(TRG).map $(DUMPTRG)
$(REMOVE) $(OBJDEPS)
$(REMOVE) $(LST) $(GDBINITFILE)
$(REMOVE) $(GENASMFILES)
$(REMOVE) $(HEXTRG)
##### EOF #####
Re: Simpel Makefile för AVR?
Postat: 14 februari 2009, 17:59:08
av SvenW
Ja. Du måste i princip konfigurera alla variabler i början på makefilen!
PROJECTNAME=myproject
- Här kan du ha ett eget projektnamn!
PRJSRC=main.c myclass.cpp lowlevelstuff.S
- Detta är dina källkodsfiler. De som du väljer att ta med här måste också finnas. Xxx.cpp och xxx.S behöver inte vara med om man inte gillar att skriva c++ eller assembler.
INC=-I/path/to/include
- Den filkatalogen finns nog inte! Du måste ta reda på var dina includefiler ligger. Kan ev. vara '-I/usr/local/avr/include'
LIBS= -L/usr/local/avr/lib/avr5/
- Kan vara som ovan. Prova med 'locate avr | grep lib', om det kommandot finns.
...
Re: Simpel Makefile för AVR?
Postat: 15 februari 2009, 01:17:21
av speakman
Det var nog den mest bloatade Makefile jag sett. Men den fyllser säkert sin funktion...
Re: Simpel Makefile för AVR?
Postat: 15 februari 2009, 11:12:34
av SvenW
Småpotatis i förhållande till de som Automake genererar!
(Automake finns kanske inte för avr-system)
Re: Simpel Makefile för AVR?
Postat: 15 februari 2009, 11:51:36
av petterp
jag tror det gick nu

jag fick ut en hex fil
fick även ut en ee.hex med men det är väll den .hex som man använder när man programmerar? och i sånna fall går det att ta bort att den skapar en ee.hex eller lägger man bara till så den raderar den i makefilen?
speakman skrev:Det var nog den mest bloatade Makefile jag sett. Men den fyllser säkert sin funktion...
vad var de du menade med detta, gör den massa onödigt eller?
Re: Simpel Makefile för AVR?
Postat: 15 februari 2009, 13:14:49
av Nerre
ee.hex är väl en fil som innehåller data som ska in i EEPROM?
Re: Simpel Makefile för AVR?
Postat: 15 februari 2009, 13:25:04
av MicaelKarlsson
petterp: Om du använder WinAVR så kan du ju testköra MFile som genererar en Makefile som funkar riktigt bra, i alla fall för mig.
Re: Simpel Makefile för AVR?
Postat: 15 februari 2009, 13:26:17
av speakman
SvenW: Eftersom man inte behöver peta i en autogenererad Makefile gör det ju inte så mycket. Makefile.am är ju betydligt renare. Optimal imo.
petterp: Ja alltså det funkar ju men mina egenskrivna Makefiles uppnår inte många rader. Mycket sköter ju Make automatiskt.
Så här ser en gammal ut t.ex.:
Kod: Markera allt
MCU=attiny2313
ISPMCU=t2313
OBJS=avrledtest.o spi.o serial.o pwm.o lcd.o
OUT=sertest
CC=avr-gcc
OBJCOPY=avr-objcopy
CFLAGS=-g -mmcu=$(MCU) -Wall -save-temps -Wstrict-prototypes -Os -mcall-prologues -DF_CPU=8000000UL
all: $(OUT)
$(OUT): $(OBJS)
$(CC) $(CFLAGS) -o $(OUT).out -Wl,-Map,$(OUT).map $(OBJS)
$(OBJCOPY) -R .eeprom -O ihex $(OUT).out $(OUT).hex
load: $(OUT).hex
avrdude -c dapa -p $(ISPMCU) -e -U flash:w:$(OUT).hex -qqq
clean:
rm -f *.o *.map *.out $(OUT)