Forum: Mikrocontroller und Digitale Elektronik C code automatisch in hexfile compilieren


von Sven (Gast)


Lesenswert?

Hallo,

ich würde gerne den Programmcode:
http://www.ulrichradig.de/home/index.php/avr/eth_m32_ex
automatisch compilieren lassen (in ein hexfile unwandeln)


ich habe es schon mit Ubuntu und Eclipse (avrdude) versucht.
leider ohne erfolg, deshalb dachte ich mir, ich könnte es auch mit der 
Konsole versuchen. leider kenne ich den Befehlssatz nicht. Hat jemand 
damit Erfahrung?

vielen Dank

von Timmo H. (masterfx)


Lesenswert?

avr-gcc ist dein Freund!

von Nico (Gast)


Lesenswert?

???

Orakel, orakel ...

Frage Nummero 1:

was verstehst Du unter automatisch compilieren lassen? Mein Compiler 
macht das automatisch, wenn ich in darum bitte.

Sven schrieb:
> leider kenne ich den Befehlssatz nicht.

Befehlssatz von was? Linux?

von Wayne (Gast)


Lesenswert?


von Timmo H. (masterfx)


Lesenswert?


von holger (Gast)


Lesenswert?

>deshalb dachte ich mir, ich könnte es auch mit der
>Konsole versuchen. leider kenne ich den Befehlssatz nicht.

Der Befehl lautet einfach nur make.
Wenn der avrgcc installiert ist tuts dann auch.

von M. K. (sylaina)


Lesenswert?

holger schrieb:
> Der Befehl lautet einfach nur make.
> Wenn der avrgcc installiert ist tuts dann auch.

Stimmt auch nicht so wirklich. Wenn im Makefile nicht angegeben ist, wer 
zum .hex werden soll, macht auch ein make kein .hex.

von Sven (Gast)


Lesenswert?

Hallo Holger,

muss ich in dem verzeichnis sein in dem die main.c klasse ist?
oder in welchen ordner muss ich gehen?

von Sven (Gast)


Lesenswert?

ich glaub, da liegt schon das Problem.
woher bekomm ich denn das makefile ohne AVR Studio?

von M. K. (sylaina)


Lesenswert?

Sven schrieb:
> ich glaub, da liegt schon das Problem.
> woher bekomm ich denn das makefile ohne AVR Studio?

Entweder selber schreiben oder ein Template aus dem Internet besorgen 
und entsprechend anpassen. Weiter oben gibts schon Links wo beschrieben 
ist wie das geht.

von holger (Gast)


Lesenswert?

>ich glaub, da liegt schon das Problem.
>woher bekomm ich denn das makefile ohne AVR Studio?

Also in meinem Verzeichnis ist eins drin.

von holger (Gast)


Lesenswert?

Verdammt, nur für Windows;) Nix Linux.

DIRAVR = c:/winavr

von Sven (Gast)


Lesenswert?

kann ich dann auch mir gcc ein makefile erstellen, bzw gibts da ein 
grafisches programm?

von holger (Gast)


Lesenswert?

>kann ich dann auch mir gcc ein makefile erstellen, bzw gibts da ein
>grafisches programm?

Nein, gcc ist nur die Compilertoolchain.

Eclipse wär unter Linux wohl schon ok.

von M. K. (sylaina)


Lesenswert?

graphisches Programm? Was willst du denn da zeichnen?

von Sven (Gast)


Lesenswert?

kennt jemand den befehl mit dem ich das makefile erstellen kann

von holger (Gast)


Lesenswert?

>kennt jemand den befehl mit dem ich das makefile erstellen kann

Es gibt keinen Befehl mit dem du das makefile erstellen kannst.

von Nico (Gast)


Lesenswert?

Sven schrieb:
> kennt jemand den befehl mit dem ich das makefile erstellen kann

make makefile

von M. K. (sylaina)


Lesenswert?

Sven schrieb:
> kennt jemand den befehl mit dem ich das makefile erstellen kann

das ist ein Textfile, mit einem Texteditor kann man das ganz toll 
machen. Aber mal ganz ehrlich, du musst dich da auch ein wenig mal 
einlesen. Ich hab das Gefühl, dass du dir die Links oben nicht wirklich 
angeschaut hast und das dort geschriebene auch durchgelesen hast. Das 
musst du aber machen, da kann dir niemand hier im Forum bei helfen das 
zu lesen.

von Simon S. (-schumi-)


Lesenswert?

Hier gibt es eine Anleitung, die ein Makefile enthält und auch 
beschreibt wie man es anpassen muss: 
http://wiki.ubuntuusers.de/AVR#Programmierung-in-C

von Sven (Gast)


Lesenswert?

Hallo nochmals,

ich habe mir das ganze nun nochmals angeschaut. Nun klingt vieles 
logisch. Allerdings erhalte ich noch folgende Fehlerrmeldung:

**** Build of configuration Default for project WebServer1 ****

make test.elf

Linking: test.elf
avr-gcc -mmcu=atmega32 -I. -gdwarf-2   -Os -funsigned-char 
-funsigned-bitfields -fpack-struct -fshort-enums -Wall 
-Wstrict-prototypes -Wa,-adhlns=main.o  -std=gnu99 -DF_OSC=20000000 -MD 
-MP -MF .dep/test.elf.d main.o   --output test.elf 
-Wl,-Map=main.map,--cref    -lm
main.o: In function `main':
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:66: undefined 
reference to `usart_init'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:72: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:73: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:74: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:79: undefined 
reference to `stack_init'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:80: undefined 
reference to `httpd_init'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:81: undefined 
reference to `telnetd_init'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:129: undefined 
reference to `myip'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:129: undefined 
reference to `myip'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:129: undefined 
reference to `myip'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:129: undefined 
reference to `myip'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:129: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:130: undefined 
reference to `netmask'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:130: undefined 
reference to `netmask'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:130: undefined 
reference to `netmask'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:130: undefined 
reference to `netmask'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:130: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:131: undefined 
reference to `router_ip'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:131: undefined 
reference to `router_ip'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:131: undefined 
reference to `router_ip'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:131: undefined 
reference to `router_ip'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:131: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:154: undefined 
reference to `ntp_init'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:158: undefined 
reference to `ntp_request'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:160: undefined 
reference to `ntp'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:162: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:166: undefined 
reference to `command_time'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:183: undefined 
reference to `eth_get_data'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:191: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:192: undefined 
reference to `extract_cmd'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:198: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:212: undefined 
reference to `ntp_request'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:243: undefined 
reference to `telnetd_send_data'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:245: undefined 
reference to `ping'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:247: undefined 
reference to `ping'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:247: undefined 
reference to `ping'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:247: undefined 
reference to `ping'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:247: undefined 
reference to `ping'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:247: undefined 
reference to `usart_write_P'
/home/sven/Desktop/ETH_M32_EX_SOFT/newStack1_2_9/main.c:248: undefined 
reference to `ping'
make: *** [test.elf] Fehler 1


mein makefile sieht wie folgt aus:
# Hey Emacs, this is a -*- makefile -*-
#
# WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.
# Released to the Public Domain
# Please read the make user manual!
#
# Additional material for this makefile was submitted by:
#  Tim Henigan
#  Peter Fleury
#  Reiner Patommel
#  Sander Pool
#  Frederik Rouleau
#  Markus Pfaff
#
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or 
VMLAB).
#
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR 
Studio
#                4.07 or greater).
#
# make program = Download the hex file to the device, using avrdude. 
Please
#                customize the avrdude settings below first!
#
# make filename.s = Just compile filename.c into the assembler code only
#
# To rebuild project do "make clean" then "make all".
#

# mth 2004/09
# Differences from WinAVR 20040720 sample:
# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
# - F_OSC Define in CFLAGS and AFLAGS


# MCU name
MCU = atmega32

# Main Oscillator Frequency
# This is only used to define F_OSC in all assembler and c-sources.
F_OSC = 20000000

# Output format. (can be srec, ihex, binary)
FORMAT = ihex

# Target file name (without extension).
TARGET = main


# List C source files here. (C dependencies are automatically 
generated.)
SRC = $(TARGET).c


# List Assembler source files here.
# Make them always end in a capital .S.  Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =



# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s

# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG = dwarf-2

# List any extra directories to look for include files here.
#     Each directory must be seperated by a space.
EXTRAINCDIRS =


# Compiler flag to set the C Standard level.
# c89   - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99   - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
CSTANDARD = -std=gnu99

# Place -D or -U options here
CDEFS =

# Place -I options here
CINCS =


# Compiler flags.
#  -g*:          generate debugging information
#  -O*:          optimization level
#  -f...:        tuning, see GCC manual and avr-libc documentation
#  -Wall...:     warning level
#  -Wa,...:      tell GCC to pass this to the assembler.
#    -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct 
-fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
CFLAGS += -DF_OSC=$(F_OSC)



# Assembler flags.
#  -Wa,...:   tell GCC to pass this to the assembler.
#  -ahlms:    create listing
#  -gstabs:   have the assembler create line number information; note 
that
#             for use in COFF files, additional information about 
filenames
#             and function names needs to be present in the assembler 
source
#             files -- see avr-libc docs [FIXME: not yet described 
there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
ASFLAGS += -DF_OSC=$(F_OSC)


#Additional libraries.

# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min

# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt

PRINTF_LIB =

# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min

# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt

SCANF_LIB =

MATH_LIB = -lm

# External memory options

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = 
-Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff

EXTMEMOPTS =

# Linker flags.
#  -Wl,...:     tell GCC to pass this to linker.
#    -Map:      create map file
#    --cref:    add cross reference to  map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)




# Programming support using avrdude. Settings and variables.

# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = stk500

# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = usb    # programmer connected to serial device

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep


# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y

# Uncomment the following if you do not wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V

# Increase verbosity level.  Please use this when submitting bug
# reports about avrdude. See 
<http://savannah.nongnu.org/projects/avrdude>;
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v

AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)



# 
------------------------------------------------------------------------ 
---

# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib


# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp




# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = --------  end  --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:




# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)

# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)


# Compiler flags to generate dependency files.
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d

# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)





# Default target.
all: begin gccversion sizebefore build sizeafter finished end

build: elf hex eep lss sym

elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym



# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
  @echo
  @echo $(MSG_BEGIN)

finished:
  @echo $(MSG_ERRORS_NONE)

end:
  @echo $(MSG_END)
  @echo


# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
sizebefore:
  @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); 
$(ELFSIZE); echo; fi

sizeafter:
  @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); 
$(ELFSIZE); echo; fi



# Display compiler version information.
gccversion :
  @$(CC) --version



# Program the device.
program: $(TARGET).hex $(TARGET).eep
  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) 
$(AVRDUDE_WRITE_EEPROM)




# Convert ELF to COFF for use in debugging / simulating in AVR Studio or 
VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000


coff: $(TARGET).elf
  @echo
  @echo $(MSG_COFF) $(TARGET).cof
  $(COFFCONVERT) -O coff-avr $< $(TARGET).cof


extcoff: $(TARGET).elf
  @echo
  @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof



# 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) $< $@

# Create extended listing file from ELF output file.
%.lss: %.elf
  @echo
  @echo $(MSG_EXTENDED_LISTING) $@
  $(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
%.sym: %.elf
  @echo
  @echo $(MSG_SYMBOL_TABLE) $@
  $(NM) -n $< > $@



# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
  @echo
  @echo $(MSG_LINKING) $@
  $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)


# Compile: create object files from C source files.
%.o : %.c
  @echo
  @echo $(MSG_COMPILING) $<
  $(CC) -c $(ALL_CFLAGS) $< -o $@


# Compile: create assembler files from C source files.
%.s : %.c
  $(CC) -S $(ALL_CFLAGS) $< -o $@


# Assemble: create object files from assembler source files.
%.o : %.S
  @echo
  @echo $(MSG_ASSEMBLING) $<
  $(CC) -c $(ALL_ASFLAGS) $< -o $@



# Target: clean project.
clean: begin clean_list finished end

clean_list :
  @echo
  @echo $(MSG_CLEANING)
  $(REMOVE) $(TARGET).hex
  $(REMOVE) $(TARGET).eep
  $(REMOVE) $(TARGET).obj
  $(REMOVE) $(TARGET).cof
  $(REMOVE) $(TARGET).elf
  $(REMOVE) $(TARGET).map
  $(REMOVE) $(TARGET).obj
  $(REMOVE) $(TARGET).a90
  $(REMOVE) $(TARGET).sym
  $(REMOVE) $(TARGET).lnk
  $(REMOVE) $(TARGET).lss
  $(REMOVE) $(OBJ)
  $(REMOVE) $(LST)
  $(REMOVE) $(SRC:.c=.s)
  $(REMOVE) $(SRC:.c=.d)
  $(REMOVE) .dep/*



# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)


# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
clean clean_list program# Hey Emacs, this is a -*- makefile -*-
#
# WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.
# Released to the Public Domain
# Please read the make user manual!
#
# Additional material for this makefile was submitted by:
#  Tim Henigan
#  Peter Fleury
#  Reiner Patommel
#  Sander Pool
#  Frederik Rouleau
#  Markus Pfaff
#
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or 
VMLAB).
#
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR 
Studio
#                4.07 or greater).
#
# make program = Download the hex file to the device, using avrdude. 
Please
#                customize the avrdude settings below first!
#
# make filename.s = Just compile filename.c into the assembler code only
#
# To rebuild project do "make clean" then "make all".
#

# mth 2004/09
# Differences from WinAVR 20040720 sample:
# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
# - F_OSC Define in CFLAGS and AFLAGS


# MCU name
MCU = atmega32

# Main Oscillator Frequency
# This is only used to define F_OSC in all assembler and c-sources.
F_OSC = 20000000

# Output format. (can be srec, ihex, binary)
FORMAT = ihex

# Target file name (without extension).
TARGET = main


# List C source files here. (C dependencies are automatically 
generated.)
SRC = $(TARGET).c


# List Assembler source files here.
# Make them always end in a capital .S.  Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =



# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s

# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
#DEBUG = stabs
DEBUG = dwarf-2

# List any extra directories to look for include files here.
#     Each directory must be seperated by a space.
EXTRAINCDIRS =


# Compiler flag to set the C Standard level.
# c89   - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99   - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
CSTANDARD = -std=gnu99

# Place -D or -U options here
CDEFS =

# Place -I options here
CINCS =


# Compiler flags.
#  -g*:          generate debugging information
#  -O*:          optimization level
#  -f...:        tuning, see GCC manual and avr-libc documentation
#  -Wall...:     warning level
#  -Wa,...:      tell GCC to pass this to the assembler.
#    -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct 
-fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
CFLAGS += -DF_OSC=$(F_OSC)



# Assembler flags.
#  -Wa,...:   tell GCC to pass this to the assembler.
#  -ahlms:    create listing
#  -gstabs:   have the assembler create line number information; note 
that
#             for use in COFF files, additional information about 
filenames
#             and function names needs to be present in the assembler 
source
#             files -- see avr-libc docs [FIXME: not yet described 
there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
ASFLAGS += -DF_OSC=$(F_OSC)


#Additional libraries.

# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min

# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt

PRINTF_LIB =

# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min

# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt

SCANF_LIB =

MATH_LIB = -lm

# External memory options

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff

# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = 
-Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff

EXTMEMOPTS =

# Linker flags.
#  -Wl,...:     tell GCC to pass this to linker.
#    -Map:      create map file
#    --cref:    add cross reference to  map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)




# Programming support using avrdude. Settings and variables.

# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = stk500

# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = usb    # programmer connected to serial device

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep


# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y

# Uncomment the following if you do not wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V

# Increase verbosity level.  Please use this when submitting bug
# reports about avrdude. See 
<http://savannah.nongnu.org/projects/avrdude>;
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v

AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)



# 
------------------------------------------------------------------------ 
---

# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib


# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp




# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = --------  end  --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:




# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)

# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)


# Compiler flags to generate dependency files.
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d

# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)





# Default target.
all: begin gccversion sizebefore build sizeafter finished end

build: elf hex eep lss sym

elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym



# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
  @echo
  @echo $(MSG_BEGIN)

finished:
  @echo $(MSG_ERRORS_NONE)

end:
  @echo $(MSG_END)
  @echo


# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
sizebefore:
  @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); 
$(ELFSIZE); echo; fi

sizeafter:
  @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); 
$(ELFSIZE); echo; fi



# Display compiler version information.
gccversion :
  @$(CC) --version



# Program the device.
program: $(TARGET).hex $(TARGET).eep
  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) 
$(AVRDUDE_WRITE_EEPROM)




# Convert ELF to COFF for use in debugging / simulating in AVR Studio or 
VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000


coff: $(TARGET).elf
  @echo
  @echo $(MSG_COFF) $(TARGET).cof
  $(COFFCONVERT) -O coff-avr $< $(TARGET).cof


extcoff: $(TARGET).elf
  @echo
  @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof



# 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) $< $@

# Create extended listing file from ELF output file.
%.lss: %.elf
  @echo
  @echo $(MSG_EXTENDED_LISTING) $@
  $(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
%.sym: %.elf
  @echo
  @echo $(MSG_SYMBOL_TABLE) $@
  $(NM) -n $< > $@



# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
  @echo
  @echo $(MSG_LINKING) $@
  $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)


# Compile: create object files from C source files.
%.o : %.c
  @echo
  @echo $(MSG_COMPILING) $<
  $(CC) -c $(ALL_CFLAGS) $< -o $@


# Compile: create assembler files from C source files.
%.s : %.c
  $(CC) -S $(ALL_CFLAGS) $< -o $@


# Assemble: create object files from assembler source files.
%.o : %.S
  @echo
  @echo $(MSG_ASSEMBLING) $<
  $(CC) -c $(ALL_ASFLAGS) $< -o $@



# Target: clean project.
clean: begin clean_list finished end

clean_list :
  @echo
  @echo $(MSG_CLEANING)
  $(REMOVE) $(TARGET).hex
  $(REMOVE) $(TARGET).eep
  $(REMOVE) $(TARGET).obj
  $(REMOVE) $(TARGET).cof
  $(REMOVE) $(TARGET).elf
  $(REMOVE) $(TARGET).map
  $(REMOVE) $(TARGET).obj
  $(REMOVE) $(TARGET).a90
  $(REMOVE) $(TARGET).sym
  $(REMOVE) $(TARGET).lnk
  $(REMOVE) $(TARGET).lss
  $(REMOVE) $(OBJ)
  $(REMOVE) $(LST)
  $(REMOVE) $(SRC:.c=.s)
  $(REMOVE) $(SRC:.c=.d)
  $(REMOVE) .dep/*



# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)


# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
clean clean_list program



die Ordnerstruktur ist die gleich wie bei dem Projekt von Ulrich Radig:
http://www.ulrichradig.de/home/index.php/avr/eth_m32_ex

Ich benutze Außerdem Eclipse und gcc-avr

kann mir jemand sagen was ich falsch mache?

vielen Dank

von Simon S. (-schumi-)


Lesenswert?

Wenn dein Projekt auf mehrere Dateien aufgeteilt ist, muss du die 
weiteren *.c-Dateien separat im Makefile mit angeben, und zwar hier:
1
# List C source files here. (C dependencies are automatically 
2
generated.)
3
SRC = $(TARGET).c
Das sieht dann so aus (wenn ich mich jetzt nicht vertippt habe):
1
# List C source files here. (C dependencies are automatically 
2
generated.)
3
SRC = $(TARGET).c analog.c artnet.c base64.c cmd.c dhcpc.c dnsc.c httpd.c http_get.c lcd.c ntp.c rtl8019.c sendmail.c stack.c telnetd.c timer.c udp_lcd.c usart.c wol.c

von Sven (Gast)


Lesenswert?

perfekt,
allerdings habe ich noch ein kleines Problem und zwar wie muss ich mein 
target.hex file benennen?
hier nochmals einen Ausdruck aus meinem makefile:
dabei liegt das problem wahrscheinlich an dieser Zeile:
$(TARGET).hex




# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = usb    # programmer connected to serial device

AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep

von Simon S. (-schumi-)


Lesenswert?

Sven schrieb:
> perfekt,
> allerdings habe ich noch ein kleines Problem und zwar wie muss ich mein
> target.hex file benennen?
> hier nochmals einen Ausdruck aus meinem makefile:
> dabei liegt das problem wahrscheinlich an dieser Zeile:
> $(TARGET).hex
Garnicht, $(TARGET) ist eine Variable. Ziemlich am Anfang vom makefile 
steht ja "TARGET = main", d.h. dein Hex-File wird dann heißen: main.hex

Damit wärst du ja dann am Ziel deiner Frage angekommen:
> ich würde gerne den Programmcode:
> http://www.ulrichradig.de/home/index.php/avr/eth_m32_ex
> automatisch compilieren lassen (in ein hexfile unwandeln)



Wenn du jetzt noch mithilfe von dem makefile das Programm auf den AVR 
brennen möchtest, musst du noch folgendes einstellen:
#1: Welchen Programmer du benutzt (z.B. stk500):
AVRDUDE_PROGRAMMER = stk500

#2: Wie der Programmer angeschlossen ist (z.B. usb)
> # com1 = serial port. Use lpt1 to connect to parallel port.
> AVRDUDE_PORT = usb    # programmer connected to serial device

Was du genau einstellen musst weis ich nicht, dazu müsstest du verraten 
welches Programmierwerkzeug zu benutzt. Falls du es selbst hinkriegst 
kannst du anschließend mit "make program" das Programm auf den AVR 
brennen

Damit musst du dich nicht befassen, einfach so lassen wie es ist:
> AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
> #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
(oder musst du das EEPROM im AVR auch beschreiben? Dann das 
Schweinegatter # bei der zweiten Zeile wegmachen)

: Bearbeitet durch User
von Sven (Gast)


Lesenswert?

warum kommt jetzt wieder diese Meldung :-(

**** Build of configuration Default for project WebServer1 ****

make main.hex
make: *** Keine Regel, um »main.hex« zu erstellen.  Schluss.

von holger (Gast)


Lesenswert?

>make main.hex
>make: *** Keine Regel, um »main.hex« zu erstellen.  Schluss.

Gib einfach nur make ein oder make all.
Den Namen der HEX Datei gibst du make nicht.
Das wird im makefile geregelt.

von Sven (Gast)


Lesenswert?

Jetzt kommt folgende Fehlermeldung:

sven@notebook-ch:~/Desktop/ETH_M32_EX_SOFT/newStack1_2_9$ make
-------- begin --------
avr-gcc (GCC) 4.3.4
Copyright (C) 2008 Free Software Foundation, Inc.
Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE 
ZWECKE.

make: *** Keine Regel vorhanden, um das Target »main.hex«,
  benötigt von »hex«, zu erstellen.  Schluss.

Außerdem verwende ich den AVRisp MKII Programmer, der allerdings noch 
nicht angeschlossen ist, was ja aber auch nichts machen dürfte oder?

von Simon S. (-schumi-)


Lesenswert?

Magst du einfach mal deinen Ordner mit dem Sourcecode zusammenpacken 
(zip, tar.gz whatever) und hier hochladen? Dann ist die Diagnose um 
einiges einfacher...

von Sven (Gast)


Angehängte Dateien:

Lesenswert?

Hallo Simon,

gute Idee und schon mal vielen Dank für deine Hilfe

von Simon S. (-schumi-)


Angehängte Dateien:

Lesenswert?

Also bei mir funktioniert das compilieren:
1
╭─simon at localhost in ~/Downloads/Microcontroller_Sven_fixed 
2
╰─○ make all
3
4
[....]
5
6
Size after:
7
Hexfiles/Webserver_MEGA32.elf  :
8
section          size      addr
9
.text           24726         0
10
.data             366   8388704
11
.bss             1055   8389070
12
.stab           43284         0
13
.stabstr        16318         0
14
.comment           34         0
15
.debug_info      1254         0
16
.debug_abbrev    1187         0
17
.debug_line        29         0
18
.debug_str        406         0
19
Total           88659
20
21
22
23
Errors: none
24
-------- end --------
25
26
╭─simon at localhost in ~/Downloads/Microcontroller_Sven_fixed 
27
╰─○


Nur einige Errors nach folgendem Schema hab ich durch ein paar 'const' 
behoben:
1
cmd.c:63:15: error: variable 'helptext' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
2
  PROGMEM char helptext[] = {
3
               ^

Die Hex-Dateien liegen im Ordner Hexfiles

von sven (Gast)


Lesenswert?

Danke nun hat es geklappt. Werde nun schauen warum es gestern nicht 
funktioniert hat

von Sven (Gast)


Lesenswert?

Hallo

Nach diesem Erfolgserlebnis von gestern, wollte ich geich mal die 
config.h anpassen und die IP-Adresse von 192.168.0.99 auf 192.168.0.98 
ändern.
Als ich es wieder compilieren wollte, kam folgende Fehlermeldung:

Compiling: main.c
avr-gcc -c -mmcu=atmega32 -I. -g -Os -funsigned-char 
-funsigned-bitfields -fpack-struct -fshort-enums -Wall 
-Wstrict-prototypes -Wa,-adhlns=main.lst  -std=gnu99 main.c -o main.o
main.c:25:20: fatal error: avr/io.h: No such file or directory
compilation terminated.
make: *** [main.o] Error 1

wie kann sowas sein? auch das zurück ändern auf den ursprünglichen werts 
geht jetzt schief.

vielen Dank im voraus

von Simon S. (-schumi-)


Lesenswert?

Sven schrieb:
> main.c:25:20: fatal error: avr/io.h: No such file or directory

Ist die avr-libc installiert? Stelle sicher dass alle 4 Pakete die hier 
aufgelistet sind installiert sind 
http://wiki.ubuntuusers.de/AVR?flavour=full#Einrichten-einer-Entwicklungsumgebung-2

: Bearbeitet durch User
von Sven (Gast)


Lesenswert?

ja, die sind installiert, funktioniert es bei dir ohne Probleme?

von Simon S. (-schumi-)


Angehängte Dateien:

Lesenswert?

Sven schrieb:
> ja, die sind installiert, funktioniert es bei dir ohne Probleme?

Ja, bei mir gehts ohne Probleme (make_all.txt). Versuche mal:
- make clean
- den versteckten Ordner .dep löschen ( "rm -R .dep" )
- jetzt sollte nur noch der Sourcecode da sein -> make all


Falls es dann immer noch nicht funktioniert probiere mal das 
Minimalbeispiel im Anhang zu compilieren (da weis ich sicher, dass das 
makefile auch auf Ubuntu funktioniert, dein makefile habe ich mangels 
Ubuntu nur auf ArchLinux probiert)

: Bearbeitet durch User
von Sven (Gast)


Lesenswert?

Hallo nochmals,

jetzt funktioniert es.
Ich habe meinen PC neu installiert und die oben genannten Pakete neu 
eingerichtet.
was jetzt das Problem war, kann ich leider nicht sagen. Naja, Hauptsache 
es funktioniert.

vielen Dank

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.