




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、WinAVR(GCC)新手入门的makefile范例#这是一个简单makefile,仅用于初学者使用#修改于WINAVR20050214所生成的makefile#简单实验只需更改 单片机类型目标文件名C源文件名系统时钟频率即可#修改好参数后另存到单片机程序所在目录,然后执行make all命令#生成 烧录FLASH的*.hex,烧录EEPROM的*.eep,调试用的*.elf 文件# MCU name # 单片机类型 参考格式是:atmega8 / at90s2313 / attiny15
2、MCU = atmega16 # Processor frequency.# 系统时钟频率(Hz),用于生成延时 _delay_us() _delay_ms() 见delay.h # This will define a symbol, F_CPU, in all source code files equal to the # processor frequency. You can then use this symbol in your source code to # calculate timings. Do NOT tack on a 'UL' at the end
3、, this will be done# automatically to create a 32-bit value in your source code.F_CPU = 1000000# Target file name (without extension).# 目标文件名(即生成的.hex/.eep/.elf的文件名)TARGET = main# List C source files here. (C dependencies are automatically generated.)# C源文件名(不带路径)# 多个文件名间用空格隔开 例如 SRC = file1.c file2
4、.c file3.c# 不需要加上 h头文件SRC = $(TARGET).c #*后面内容基本不需要修改,除非你是老手*# Output format. (can be srec, ihex, binary)# 输出烧录文件格式FORMAT = ihex# 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.
5、)OPT = s# Debugging format.# 输出调试格式# Native formats for AVR-GCC's -g are dwarf-2 default or stabs.# AVR Studio 4.10 requires dwarf-2.# AVR Extended COFF format requires stabs, plus an avr-objcopy run.DEBUG = dwarf-2# List Assembler source files here.# 汇编源文件名(不带路径,但扩展名 .sS 需大写,否则将会被make clean 所误删
6、)# 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 pres
7、erve the spelling of the filenames, and gcc itself does# care about how the name is spelled on its command-line.ASRC = # Hey Emacs, this is a -*- makefile -*-#-# WinAVR Makefile Template written by Eric B. Weddington, J鰎g Wunsch, et al.# Released to the Public Domain# Additional material for this ma
8、kefile was written by:# Peter Fleury# Tim Henigan# Colin O'Flynn# Reiner Patommel# Markus Pfaff# Sander Pool# Frederik Rouleau#-# On command line:# make all = Make software.# make clean = Clean out built project files.# make coff = Convert ELF to AVR COFF.# make extcoff = Convert ELF to AVR Exte
9、nded COFF.# make program = Download the hex file to the device, using avrdude.# Please customize the avrdude settings below first!# make debug = Start either simulavr or avarice as specified for debugging, # with avr-gdb or avr-insight as the front end for debugging.# make filename.s = Just compile
10、filename.c into the assembler code only.# make filename.i = Create a preprocessed source file for use in submitting# bug reports to the GCC project.# To rebuild project do "make clean" then "make all".#-# List any extra directories to look for include files here.# Each directory
11、must be seperated by a space.# Use forward slashes for directory separators.# For a directory that has spaces, enclose it in quotes.EXTRAINCDIRS = # Compiler flag to set the C Standard level.# c89 = "ANSI" C# gnu89 = c89 plus GCC extensions# c99 = ISO C99 standard (not yet fully implemente
12、d)# gnu99 = c99 plus GCC extensionsCSTANDARD = -std=gnu99# Place -D or -U options hereCDEFS = -DF_CPU=$(F_CPU)UL# Place -I options hereCINCS =#- Compiler Options -# -g*: generate debugging information# -O*: optimization level# -f.: tuning, see GCC manual and avr-libc documentation# -Wall.: warning l
13、evel# -Wa,.: tell GCC to pass this to the assembler.# -adhlns.: create assembler listingCFLAGS = -g$(DEBUG)CFLAGS += $(CDEFS) $(CINCS)CFLAGS += -O$(OPT)CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsCFLAGS += -Wall -Wstrict-prototypesCFLAGS += -Wa,-adhlns=$(<:.c=.lst)CF
14、LAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)CFLAGS += $(CSTANDARD)#- Assembler Options -# -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 func
15、tion names needs to be present in the assembler source# files - see avr-libc docs FIXME: not yet described thereASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs #- Library Options -# Minimalistic printf versionPRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min# Floating point printf version (requires MATH_L
16、IB = -lm below)PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt# If this is left blank, then it will use the Standard printf version.PRINTF_LIB = #PRINTF_LIB = $(PRINTF_LIB_MIN)#PRINTF_LIB = $(PRINTF_LIB_FLOAT)# Minimalistic scanf versionSCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min# Floating point + %
17、scanf version (requires MATH_LIB = -lm below)SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt# If this is left blank, then it will use the Standard scanf version.SCANF_LIB = #SCANF_LIB = $(SCANF_LIB_MIN)#SCANF_LIB = $(SCANF_LIB_FLOAT)MATH_LIB = -lm#- External Memory Options -# 64 KB of external RAM, sta
18、rting 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,-defs
19、ym=_heap_end=0x80ffffEXTMEMOPTS =#- Linker Options -# -Wl,.: tell GCC to pass this to linker.# -Map: create map file# -cref: add cross reference to map fileLDFLAGS = -Wl,-Map=$(TARGET).map,-crefLDFLAGS += $(EXTMEMOPTS)LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)#- Programming Options (avrdude)
20、-# 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 = com1 # programmer connected to serial deviceAVRDU
21、DE_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
22、 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 </projects/avrdude> # to submit bug reports.#AVRDUDE_VERBOSE = -v -vAVR
23、DUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)#- Debugging Options -# For simulavr only - target MCU frequency.DEBUG_MFREQ = $(F_CPU)# Set the DEBUG_UI to either gdb o
24、r insight.# DEBUG_UI = gdbDEBUG_UI = insight# Set the debugging back-end to either avarice, simulavr.DEBUG_BACKEND = avarice#DEBUG_BACKEND = simulavr# GDB Init Filename.GDBINIT_FILE = _avr_gdbinit# When using avarice settings for the JTAGJTAG_DEV = /dev/com1# Debugging port used to communicate betwe
25、en GDB / avarice / simulavr.DEBUG_PORT = 4242# Debugging host used to communicate between GDB / avarice / simulavr, normally# just set to localhost unless doing some sort of crazy debugging when # avarice is running on a different computer.DEBUG_HOST = localhost#=# Define programs and commands.SHELL
26、 = shCC = avr-gccOBJCOPY = avr-objcopyOBJDUMP = avr-objdumpSIZE = avr-sizeNM = avr-nmAVRDUDE = avrdudeREMOVE = rm -fCOPY = cpWINSHELL = cmd# Define Messages# EnglishMSG_ERRORS_NONE = Errors: noneMSG_BEGIN = - begin -MSG_END = - end -MSG_SIZE_BEFORE = Size before: MSG_SIZE_AFTER = Size after:MSG_COFF
27、 = 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:
28、MSG_ASSEMBLING = Assembling:MSG_CLEANING = Cleaning project:# Define all object files.OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) # Define all listing files.LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) # Compiler flags to generate dependency files.GENDEPFLAGS = -MD -MP -MF .dep/$(F).d# Combine all necessary flags and
29、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 endbuild: elf hex eep lss symelf: $(TARGET).elfhex: $(TARGET).hexeep:
30、$(TARGET).eeplss: $(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:echoecho $(MSG_BEGIN)end:echo $(MSG_END)echo# Display size of file.HEXSIZE = $(SIZE) -target=$(FORMAT
31、) $(TARGET).hexELFSIZE = $(SIZE) -A $(TARGET).elfAVRMEM = avr-mem.sh $(TARGET).elf $(MCU)sizebefore:if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); $(AVRMEM) 2>/dev/null; echo; fisizeafter:if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); $(AVRMEM)
32、 2>/dev/null; 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)# Generate avr-gdb config/init file which does the following:# define the res
33、et signal, load the target file, connect to target, and set # a breakpoint at main().gdb-config: $(REMOVE) $(GDBINIT_FILE)echo define reset >> $(GDBINIT_FILE)echo SIGNAL SIGHUP >> $(GDBINIT_FILE)echo end >> $(GDBINIT_FILE)echo file $(TARGET).elf >> $(GDBINIT_FILE)echo target
34、remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)ifeq ($(DEBUG_BACKEND),simulavr)echo load >> $(GDBINIT_FILE)endif echo break main >> $(GDBINIT_FILE)debug: gdb-config $(TARGET).elfifeq ($(DEBUG_BACKEND), avarice)echo Starting AVaRICE - Press enter when "waiting to connect&
35、quot; message displays.$(WINSHELL) /c start avarice -jtag $(JTAG_DEV) -erase -program -file $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)$(WINSHELL) /c pauseelse$(WINSHELL) /c start simulavr -gdbserver -device $(MCU) -clock-freq $(DEBUG_MFREQ) -port $(DEBUG_PORT)endif$(WINSHELL) /c start avr-$(DEBUG_UI)
36、 -command=$(GDBINIT_FILE)# 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 cof
37、f: $(TARGET).elfechoecho $(MSG_COFF) $(TARGET).cof$(COFFCONVERT) -O coff-avr $< $(TARGET).cofextcoff: $(TARGET).elfechoecho $(MSG_EXTENDED_COFF) $(TARGET).cof$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof# Create final output files (.hex, .eep) from ELF output file.%.hex: %.elfechoecho $(MSG_
38、FLASH) $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $%.eep: %.elfechoecho $(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: %.elfechoecho $(MSG_EXTENDED_LISTING) $(OBJDUMP) -h -S $< > $# Create a symbol table from ELF output file.%.sym: %.elfechoecho $(MSG_SY
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年海南儋州市城市建设投资有限公司招聘笔试参考题库附带答案详解
- 租空场地合同协议书
- 螺丝加工合同协议书
- 自建自管合同协议书
- 股权合伙激励协议书
- 职工在外住宿协议书
- 药房证照转让协议书
- 股东出资义务协议书
- 试管签订捐赠协议书
- 经营手机合伙协议书
- DB63-T 1004-2011 青海省既有居住建筑节能改造技术规程-(高清现行)
- 班组级教育安全培训记录表
- 评标专家聘用协议范本书
- GB∕T 9125.2-2020 钢制管法兰连接用紧固件 第2部分:Class系列
- ASME QME-1-2002核电厂能动机械设备的鉴定
- 浙江省温州市2021-2022学年高一下学期期末语文试题
- 乙二醇安全技术说明书MSDS
- 一年级数学上册 20以内的减法玩扑克做数学教案 新版冀教版
- 新开模具开发进度表
- 华为性格测试攻略
- 小学二年级下册美术课件-4.13大花瓶-岭南版(9张)ppt课件
评论
0/150
提交评论