Linux下的avr系列的编译烧录调试方法

Linux下的MCU开发之AVR系列1

-avr系列的编译烧录调试方法

Galaxy2416

联系方式:sunxiao.gin@gmail.com

附件内容: 程序源码,Makefile模板,相关文档。

http://download.csdn.net/detail/galaxy_blue/4277134附件网址~

系列说明:LINUX下程序开发具有一定的成熟性,包括大部分的MCU,FPGA,DSP甚至PCB制图等都是可行的。本系列将针对AVR系列的MCU,而后的系列将会对Linux下的其他方面内容进行探讨。

本文环境如下:

OS系统:ubuntu 12.04(原为10.04最近升级了)

编译器 :avr-gcc

烧录软件 :avrdude

调试软件:avarice ,GDB和ddd (可视界面)

开发板:

1.  xplain(xmega128a1)无法调试,只能烧录,因为官方没有公开其调试的协议。

2.  Mega16开发板。

仿真器or烧录器:dragon和usbasp(使用较多)

程序编写:Vim(升级版的记事本,很好用,很推荐)

 

关于使用前的准备和说明

  至于为什么要使用linux下开发avr,原因主要是因为比较有趣。其次便是win下的环境用起来其实并不是很方便。IAR是付费软件(但是的确好用),Avr-studio虽然是免费版,不过优缺点是太过庞大,并且是以vc2010为基础开发,这个也就算不上真正的免费了。至于win-avr其实蛮不错的。win下也可以搭建如下环境。

准备:

软件安装,软件安装建议使用ubuntu的软件中心,比较方便。需要avr-gcc,avrdude,avarice,gdb,ddd即可了。文本编辑什么都行。可以集成在codeblocks和eclipse里面。Codeblocks如此做用起来感觉不错,eclipse需要配置,但原理都是一样的。

对于命令行可以如下安装

[plain] view plain copy
  1. sudo apt-get install gcc-avrbinuilts-avr avr-libc  
  2. sudo apt-get installvim  
  3. sudo apt-get installavrdude  

强烈建议顺便安上手册

[plain] view plain copy
  1. sudo apt-get installavrdude-doc  
  2. sudo apt-get installavarice  
  3. sudo apt-get installgdb  
  4. sudo apt-get installddd  

然后就都安装完毕了。下一步就可以开始了。

开始之前需要先写一个.c的程序

代码会在文章最后和附件里提出。这是一个很简单让一个led亮的程序。

之后介绍一个makefile的东西,此物是简化操作流程的一个东西。让敲好多行命令才能完成的只需简单的一句话就行了。附件里会包含一个makefile的模板,是winavr下模板改的可用版。具体的内容是如何实现的,可以翻阅官方makefile手册和百度,谷歌。

简单介绍Makefile里面的几个命令,有过经验可以无视

[plain] view plain copy
  1. AVRDUDE_PROGRAMMER = usbasp  
  2. #dragon_jtag  
  3. AVRDUDE_PORT = usb   # programmer connected to serial device  
  4. AVRDUDE_WRITE_FLASH = -Uflash:w:$(TARGET).hex  
  5. AVRDUDE_FLAGS = -p $(MCU) -P$(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)  
  6. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)  
  7. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)  
  8. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)  

上面这些都是定义变量,makefile里的

[plain] view plain copy
  1. program: $(TARGET).hex $(TARGET).eep  
  2.      $(AVRDUDE)$(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)  

当我们输入make program时就会执行上面这句之前的都不用关心了。翻译过来就变成了(如果叫main.hex)

[plain] view plain copy
  1. avrdude -P usb -p m16 -c usbasp -U flash:w:main.hex  

就是说用usb下的usbasp烧录m16的flash,内容为main.hex

如果用dragon的话一般用jtag就是-c dragon_jtag。具体可以查看avrdude手册。

了解之后先打开终端,找到.c文件目录下。Makefile文件放在同一目录下

根据需要更改其内容

输入make

便会输出一些信息,最后会有提示编译成功

之后就可以烧录了

烧录之前看一下烧录器是否在

输入lsusb

显然,usbasp存在。那么输入sudo make program

会在很快的时间内烧录成功,比win快的多。最后提示你烧录成功

至于debug,usbasp没有这个功能。需要用dragon的jtag。

住:Debug其实不是很推荐使用,虽然比较高效,建议利用串口的信息输入输出(以后会介绍),这是因为在进入系统的嵌入后,常规的debug经常会无法使用。

实际的命令会是

[plain] view plain copy
  1. avarice -g -j usb --erase --program --filemain.hex :4242  

不过如果makefile里已经写好的话直接输入sudo make debug就可以了

下面为命令的结果

现在属于等待GDB,可视化的话就是DDD的状态中了

比如在gdb.conf中添加

 

file main.elf

target remotelocalhost:4242

启动DDD

ddd–-debugger “avr-gdb -x gdb.conf”

也可以手起动,然后配置,ui界面比较友好。

还有一句话。makefile里面已经把上步骤都做好了~当然会根据需求要求更改的。尤其是debug的时候。

总结:本文所说有些简略了,Linux开发的困难主要在于搭建环境,因此需要多看一下相关的官方手册。

 

测试代码:

main.c

  1. // avr-gcc application builder : 2011-11-1   
  2. // Target : M16  
  3. // Crystal: 12.000Mhz  
  4.   
  5. #include <avr/io.h>  
  6. #include <util/delay.h>  
  7. #define SET(a,b) a|(1<<b)  
  8. #define CLR(a,b) a &~(1<<b)  
  9. void port_init(void)  
  10. {  
  11.  DDRA  = 0xff;//将PA0定义为输出  
  12.  PORTA = 0xff;  
  13.  PORTB = 0x00;  
  14.  DDRB  = 0x00;  
  15.  PORTC = 0x00; //m103 output only  
  16.  DDRC  = 0x00;  
  17.  PORTD = 0x00;  
  18.  DDRD  = 0x00;  
  19. }  
  20.   
  21. //call this routine to initialize all peripherals  
  22. void init_devices(void)  
  23. {  
  24.  //stop errant interrupts until set up  
  25.  //CLI(); //disable all interrupts  
  26.  port_init();  
  27.  MCUCR = 0x00;  
  28.  GICR  = 0x00;  
  29.  TIMSK = 0x00; //timer interrupt sources  
  30. // SEI(); //re-enable interrupts  
  31.  //all peripherals are now initialized  
  32. }  
  33.   
  34. //  
  35. void main(void)  
  36. {  
  37.  init_devices();  
  38.  //insert your functional code here...  
  39.  PORTA = CLR(PORTA,3);  
  40.  while(1);  //程序挂起        
  41. }  

Makefile:

 

[plain] view plain copy
  1. # Hey Emacs, this is a -*- makefile -*-  
  2. #----------------------------------------------------------------------------  
  3. # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.  
  4. # Linux GCC using is changed by Galaxy2416  
  5. # Released to the Public Domain  
  6. #  
  7. # Additional material for this makefile was written by:  
  8. # Peter Fleury  
  9. # Tim Henigan  
  10. # Colin O'Flynn  
  11. # Reiner Patommel  
  12. # Markus Pfaff  
  13. # Sander Pool  
  14. # Frederik Rouleau  
  15. # Carlos Lamas  
  16. #  
  17. #----------------------------------------------------------------------------  
  18. # On command line:  
  19. #  
  20. # make all = Make software.  
  21. #  
  22. # make clean = Clean out built project files.  
  23. #  
  24. # make coff = Convert ELF to AVR COFF.  
  25. #  
  26. # make extcoff = Convert ELF to AVR Extended COFF.  
  27. #  
  28. # make program = Download the hex file to the device, using avrdude.  
  29. #                Please customize the avrdude settings below first!  
  30. #  
  31. # make debug = Start either simulavr or avarice as specified for debugging,   
  32. #              with avr-gdb or avr-insight as the front end for debugging.  
  33. #  
  34. # make filename.s = Just compile filename.c into the assembler code only.  
  35. #  
  36. # make filename.i = Create a preprocessed source file for use in submitting  
  37. #                   bug reports to the GCC project.  
  38. #  
  39. # To rebuild project do "make clean" then "make all".  
  40. #----------------------------------------------------------------------------  
  41.   
  42.   
  43. # MCU name  
  44. MCU = atmega16  
  45. #atxmega128a1  
  46.   
  47.   
  48. # Processor frequency.  
  49. #     This will define a symbol, F_CPU, in all source code files equal to the   
  50. #     processor frequency. You can then use this symbol in your source code to   
  51. #     calculate timings. Do NOT tack on a 'UL' at the end, this will be done  
  52. #     automatically to create a 32-bit value in your source code.  
  53. #     Typical values are:  
  54. #         F_CPU =  1000000  
  55. #         F_CPU =  1843200  
  56. #         F_CPU =  2000000  
  57. #         F_CPU =  3686400  
  58. #         F_CPU =  4000000  
  59. #         F_CPU =  7372800  
  60. #         F_CPU =  8000000  
  61. #         F_CPU = 11059200  
  62. #         F_CPU = 14745600  
  63. #         F_CPU = 16000000  
  64. #         F_CPU = 18432000  
  65. #         F_CPU = 20000000  
  66. F_CPU = 8000000  
  67.   
  68.   
  69. # Output format. (can be srec, ihex, binary)  
  70. FORMAT = ihex  
  71.   
  72.   
  73. # Target file name (without extension).  
  74. TARGET = main  
  75.   
  76.   
  77. # Object files directory  
  78. #     To put object files in current directory, use a dot (.), do NOT make  
  79. #     this an empty or blank macro!  
  80. OBJDIR = .  
  81.   
  82.   
  83. # List C source files here. (C dependencies are automatically generated.)  
  84. SRC = $(TARGET).c   
  85.   
  86. # List C++ source files here. (C dependencies are automatically generated.)  
  87. CPPSRC =   
  88.   
  89.   
  90. # List Assembler source files here.  
  91. #     Make them always end in a capital .S.  Files ending in a lowercase .s  
  92. #     will not be considered source files but generated files (assembler  
  93. #     output from the compiler), and will be deleted upon "make clean"!  
  94. #     Even though the DOS/Win* filesystem matches both .s and .S the same,  
  95. #     it will preserve the spelling of the filenames, and gcc itself does  
  96. #     care about how the name is spelled on its command-line.  
  97. ASRC =  
  98.   
  99.   
  100. # Optimization level, can be [0, 1, 2, 3, s].   
  101. #     0 = turn off optimization. s = optimize for size.  
  102. #     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)  
  103. OPT = s  
  104.   
  105.   
  106. # Debugging format.  
  107. #     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.  
  108. #     AVR Studio 4.10 requires dwarf-2.  
  109. #     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.  
  110. DEBUG = dwarf-2  
  111.   
  112.   
  113. # List any extra directories to look for include files here.  
  114. #     Each directory must be seperated by a space.  
  115. #     Use forward slashes for directory separators.  
  116. #     For a directory that has spaces, enclose it in quotes.  
  117. EXTRAINCDIRS =   
  118.   
  119.   
  120. # Compiler flag to set the C Standard level.  
  121. #     c89   = "ANSI" C  
  122. #     gnu89 = c89 plus GCC extensions  
  123. #     c99   = ISO C99 standard (not yet fully implemented)  
  124. #     gnu99 = c99 plus GCC extensions  
  125. CSTANDARD = -std=gnu99  
  126.   
  127.   
  128. # Place -D or -U options here for C sources  
  129. CDEFS = -DF_CPU=$(F_CPU)UL  
  130.   
  131.   
  132. # Place -D or -U options here for ASM sources  
  133. ADEFS = -DF_CPU=$(F_CPU)  
  134.   
  135.   
  136. # Place -D or -U options here for C++ sources  
  137. CPPDEFS = -DF_CPU=$(F_CPU)UL  
  138. #CPPDEFS += -D__STDC_LIMIT_MACROS  
  139. #CPPDEFS += -D__STDC_CONSTANT_MACROS  
  140.   
  141.   
  142.   
  143. #---------------- Compiler Options C ----------------  
  144. #  -g*:          generate debugging information  
  145. #  -O*:          optimization level  
  146. #  -f...:        tuning, see GCC manual and avr-libc documentation  
  147. #  -Wall...:     warning level  
  148. #  -Wa,...:      tell GCC to pass this to the assembler.  
  149. #    -adhlns...: create assembler listing  
  150. CFLAGS = -g$(DEBUG)  
  151. CFLAGS += $(CDEFS)  
  152. CFLAGS += -O$(OPT)  
  153. CFLAGS += -funsigned-char  
  154. CFLAGS += -funsigned-bitfields  
  155. CFLAGS += -fpack-struct  
  156. CFLAGS += -fshort-enums  
  157. CFLAGS += -Wall  
  158. CFLAGS += -Wstrict-prototypes  
  159. #CFLAGS += -mshort-calls  
  160. #CFLAGS += -fno-unit-at-a-time  
  161. #CFLAGS += -Wundef  
  162. #CFLAGS += -Wunreachable-code  
  163. #CFLAGS += -Wsign-compare  
  164. CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)  
  165. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))  
  166. CFLAGS += $(CSTANDARD)  
  167.   
  168.   
  169. #---------------- Compiler Options C++ ----------------  
  170. #  -g*:          generate debugging information  
  171. #  -O*:          optimization level  
  172. #  -f...:        tuning, see GCC manual and avr-libc documentation  
  173. #  -Wall...:     warning level  
  174. #  -Wa,...:      tell GCC to pass this to the assembler.  
  175. #    -adhlns...: create assembler listing  
  176. CPPFLAGS = -g$(DEBUG)  
  177. CPPFLAGS += $(CPPDEFS)  
  178. CPPFLAGS += -O$(OPT)  
  179. CPPFLAGS += -funsigned-char  
  180. CPPFLAGS += -funsigned-bitfields  
  181. CPPFLAGS += -fpack-struct  
  182. CPPFLAGS += -fshort-enums  
  183. CPPFLAGS += -fno-exceptions  
  184. CPPFLAGS += -Wall  
  185. CPPFLAGS += -Wundef  
  186. #CPPFLAGS += -mshort-calls  
  187. #CPPFLAGS += -fno-unit-at-a-time  
  188. #CPPFLAGS += -Wstrict-prototypes  
  189. #CPPFLAGS += -Wunreachable-code  
  190. #CPPFLAGS += -Wsign-compare  
  191. CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)  
  192. CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))  
  193. #CPPFLAGS += $(CSTANDARD)  
  194.   
  195.   
  196. #---------------- Assembler Options ----------------  
  197. #  -Wa,...:   tell GCC to pass this to the assembler.  
  198. #  -adhlns:   create listing  
  199. #  -gstabs:   have the assembler create line number information; note that  
  200. #             for use in COFF files, additional information about filenames  
  201. #             and function names needs to be present in the assembler source  
  202. #             files -- see avr-libc docs [FIXME: not yet described there]  
  203. #  -listing-cont-lines: Sets the maximum number of continuation lines of hex   
  204. #       dump that will be displayed for a given single line of source input.  
  205. ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100  
  206.   
  207.   
  208. #---------------- Library Options ----------------  
  209. # Minimalistic printf version  
  210. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min  
  211.   
  212. # Floating point printf version (requires MATH_LIB = -lm below)  
  213. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt  
  214.   
  215. # If this is left blank, then it will use the Standard printf version.  
  216. PRINTF_LIB =   
  217. #PRINTF_LIB = $(PRINTF_LIB_MIN)  
  218. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)  
  219.   
  220.   
  221. # Minimalistic scanf version  
  222. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min  
  223.   
  224. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)  
  225. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt  
  226.   
  227. # If this is left blank, then it will use the Standard scanf version.  
  228. SCANF_LIB =   
  229. #SCANF_LIB = $(SCANF_LIB_MIN)  
  230. #SCANF_LIB = $(SCANF_LIB_FLOAT)  
  231.   
  232.   
  233. MATH_LIB = -lm  
  234.   
  235.   
  236. # List any extra directories to look for libraries here.  
  237. #     Each directory must be seperated by a space.  
  238. #     Use forward slashes for directory separators.  
  239. #     For a directory that has spaces, enclose it in quotes.  
  240. EXTRALIBDIRS =   
  241.   
  242.   
  243.   
  244. #---------------- External Memory Options ----------------  
  245.   
  246. # 64 KB of external RAM, starting after internal RAM (ATmega128!),  
  247. # used for variables (.data/.bss) and heap (malloc()).  
  248. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff  
  249.   
  250. # 64 KB of external RAM, starting after internal RAM (ATmega128!),  
  251. # only used for heap (malloc()).  
  252. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff  
  253.   
  254. EXTMEMOPTS =  
  255.   
  256.   
  257.   
  258.   
  259. #---------------- Linker Options ----------------  
  260. #  -Wl,...:     tell GCC to pass this to linker.  
  261. #    -Map:      create map file  
  262. #    --cref:    add cross reference to  map file  
  263. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref  
  264. LDFLAGS += $(EXTMEMOPTS)  
  265. LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))  
  266. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)  
  267. #LDFLAGS += -T linker_script.x  
  268.   
  269.   
  270.   
  271. #---------------- Programming Options (avrdude) ----------------  
  272.   
  273. # Programming hardware  
  274. # Type: avrdude -c ?  
  275. # to get a full listing.  
  276. #  
  277. AVRDUDE_PROGRAMMER = usbasp  
  278. #dragon_jtag  
  279.   
  280. # com1 = serial port. Use lpt1 to connect to parallel port.  
  281. AVRDUDE_PORT = usb   # programmer connected to serial device  
  282.   
  283. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex  
  284. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep  
  285.   
  286.   
  287. # Uncomment the following if you want avrdude's erase cycle counter.  
  288. # Note that this counter needs to be initialized first using -Yn,  
  289. # see avrdude manual.  
  290. #AVRDUDE_ERASE_COUNTER = -y  
  291.   
  292. # Uncomment the following if you do /not/ wish a verification to be  
  293. # performed after programming the device.  
  294. #AVRDUDE_NO_VERIFY = -V  
  295.   
  296. # Increase verbosity level.  Please use this when submitting bug  
  297. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>   
  298. # to submit bug reports.  
  299. #AVRDUDE_VERBOSE = -v -v  
  300.   
  301. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)  
  302. #AVRDUDE_FLAGS = -p m16 -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)  
  303. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)  
  304. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)  
  305. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)  
  306.   
  307.   
  308.   
  309. #---------------- Debugging Options ----------------  
  310.   
  311. # For simulavr only - target MCU frequency.  
  312. DEBUG_MFREQ = $(F_CPU)  
  313.   
  314. # Set the DEBUG_UI to either gdb or insight.  
  315. # DEBUG_UI = gdb  
  316. DEBUG_UI = gdb  
  317.   
  318. # Set the debugging back-end to either avarice, simulavr.  
  319. DEBUG_BACKEND = avarice  
  320. #DEBUG_BACKEND = simulavr  
  321.   
  322. # GDB Init Filename.  
  323. GDBINIT_FILE = __avr_gdbinit  
  324.   
  325. # When using avarice settings for the JTAG  
  326. JTAG_DEV = usb  
  327.   
  328. # Debugging port used to communicate between GDB / avarice / simulavr.  
  329. DEBUG_PORT = 4242  
  330.   
  331. # Debugging host used to communicate between GDB / avarice / simulavr, normally  
  332. #     just set to localhost unless doing some sort of crazy debugging when   
  333. #     avarice is running on a different computer.  
  334. DEBUG_HOST = localhost  
  335.   
  336.   
  337.   
  338. #============================================================================  
  339.   
  340.   
  341. # Define programs and commands.  
  342. SHELL = sh  
  343. CC = avr-gcc  
  344. OBJCOPY = avr-objcopy  
  345. OBJDUMP = avr-objdump  
  346. SIZE = avr-size  
  347. AR = avr-ar rcs  
  348. NM = avr-nm  
  349. AVRDUDE = avrdude  
  350. REMOVE = rm -f  
  351. REMOVEDIR = rm -rf  
  352. COPY = cp  
  353. WINSHELL =   
  354.   
  355. # Define Messages  
  356. # English  
  357. MSG_ERRORS_NONE = Errors: none  
  358. MSG_BEGIN = -------- begin --------  
  359. MSG_END = --------  end  --------  
  360. MSG_SIZE_BEFORE = Size before:   
  361. MSG_SIZE_AFTER = Size after:  
  362. MSG_COFF = Converting to AVR COFF:  
  363. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:  
  364. MSG_FLASH = Creating load file for Flash:  
  365. MSG_EEPROM = Creating load file for EEPROM:  
  366. MSG_EXTENDED_LISTING = Creating Extended Listing:  
  367. MSG_SYMBOL_TABLE = Creating Symbol Table:  
  368. MSG_LINKING = Linking:  
  369. MSG_COMPILING = Compiling C:  
  370. MSG_COMPILING_CPP = Compiling C++:  
  371. MSG_ASSEMBLING = Assembling:  
  372. MSG_CLEANING = Cleaning project:  
  373. MSG_CREATING_LIBRARY = Creating library:  
  374.   
  375.   
  376.   
  377.   
  378. # Define all object files.  
  379. OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)   
  380.   
  381. # Define all listing files.  
  382. LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)   
  383.   
  384.   
  385. # Compiler flags to generate dependency files.  
  386. GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d  
  387.   
  388.   
  389. # Combine all necessary flags and optional flags.  
  390. # Add target processor to flags.  
  391. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)  
  392. ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)  
  393. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)  
  394.   
  395.   
  396.   
  397.   
  398.   
  399. # Default target.  
  400. all: begin gccversion sizebefore build sizeafter end  
  401.   
  402. # Change the build target to build a HEX file or a library.  
  403. build: elf hex eep lss sym  
  404. #build: lib  
  405.   
  406.   
  407. elf: $(TARGET).elf  
  408. hex: $(TARGET).hex  
  409. eep: $(TARGET).eep  
  410. lss: $(TARGET).lss  
  411. sym: $(TARGET).sym  
  412. LIBNAME=lib$(TARGET).a  
  413. lib: $(LIBNAME)  
  414.   
  415.   
  416.   
  417. # Eye candy.  
  418. # AVR Studio 3.x does not check make's exit code but relies on  
  419. # the following magic strings to be generated by the compile job.  
  420. begin:  
  421.     @echo  
  422.     @echo $(MSG_BEGIN)  
  423.   
  424. end:  
  425.     @echo $(MSG_END)  
  426.     @echo  
  427.   
  428.   
  429. # Display size of file.  
  430. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex  
  431. ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf  
  432.   
  433. sizebefore:  
  434.     @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \  
  435.     2>/dev/null; echo; fi  
  436.   
  437. sizeafter:  
  438.     @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \  
  439.     2>/dev/null; echo; fi  
  440.   
  441.   
  442.   
  443. # Display compiler version information.  
  444. gccversion :   
  445.     @$(CC) --version  
  446.   
  447.   
  448.   
  449. # Program the device.    
  450. program: $(TARGET).hex $(TARGET).eep  
  451.     $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)  
  452.   
  453.   
  454. # Generate avr-gdb config/init file which does the following:  
  455. #     define the reset signal, load the target file, connect to target, and set   
  456. #     a breakpoint at main().  
  457. gdb-config:   
  458.     @$(REMOVE) $(GDBINIT_FILE)  
  459.     @echo define reset >> $(GDBINIT_FILE)  
  460.     @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)  
  461.     @echo end >> $(GDBINIT_FILE)  
  462.     @echo file $(TARGET).elf >> $(GDBINIT_FILE)  
  463.     @echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)  
  464. ifeq ($(DEBUG_BACKEND),simulavr)  
  465.     @echo load  >> $(GDBINIT_FILE)  
  466. endif  
  467.     @echo break main >> $(GDBINIT_FILE)  
  468.   
  469. debug: gdb-config $(TARGET).elf  
  470. ifeq ($(DEBUG_BACKEND), avarice)  
  471.     @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.  
  472.     #@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \  
  473.     #$(TARGET).hex $(DEBUG_HOST):$(DEBUG_PORT)  
  474.     #@$(WINSHELL) /c pause  
  475.     @$(WINSHELL)  avarice --xmega -g --jtag $(JTAG_DEV) --erase --program --file   \  
  476.     $(TARGET).elf:$(DEBUG_PORT)  
  477.     #@$(WINSHELL)  pause  
  478.   
  479. else  
  480.     @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \  
  481.     $(DEBUG_MFREQ) --port $(DEBUG_PORT)  
  482. endif  
  483.     #@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)  
  484.     @$(WINSHELL)  $(DEBUG_UI)  
  485.   
  486.   
  487.   
  488.   
  489. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.  
  490. COFFCONVERT = $(OBJCOPY) --debugging  
  491. COFFCONVERT += --change-section-address .data-0x800000  
  492. COFFCONVERT += --change-section-address .bss-0x800000  
  493. COFFCONVERT += --change-section-address .noinit-0x800000  
  494. COFFCONVERT += --change-section-address .eeprom-0x810000  
  495.   
  496.   
  497.   
  498. coff: $(TARGET).elf  
  499.     @echo  
  500.     @echo $(MSG_COFF) $(TARGET).cof  
  501.     $(COFFCONVERT) -O coff-avr $< $(TARGET).cof  
  502.   
  503.   
  504. extcoff: $(TARGET).elf  
  505.     @echo  
  506.     @echo $(MSG_EXTENDED_COFF) $(TARGET).cof  
  507.     $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof  
  508.   
  509.   
  510.   
  511. # Create final output files (.hex, .eep) from ELF output file.  
  512. %.hex: %.elf  
  513.     @echo  
  514.     @echo $(MSG_FLASH) $@  
  515.     $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@  
  516.   
  517. %.eep: %.elf  
  518.     @echo  
  519.     @echo $(MSG_EEPROM) $@  
  520.     -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \  
  521.     --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0  
  522.   
  523. # Create extended listing file from ELF output file.  
  524. %.lss: %.elf  
  525.     @echo  
  526.     @echo $(MSG_EXTENDED_LISTING) $@  
  527.     $(OBJDUMP) -h -S -z $< > $@  
  528.   
  529. # Create a symbol table from ELF output file.  
  530. %.sym: %.elf  
  531.     @echo  
  532.     @echo $(MSG_SYMBOL_TABLE) $@  
  533.     $(NM) -n $< > $@  
  534.   
  535.   
  536.   
  537. # Create library from object files.  
  538. .SECONDARY : $(TARGET).a  
  539. .PRECIOUS : $(OBJ)  
  540. %.a: $(OBJ)  
  541.     @echo  
  542.     @echo $(MSG_CREATING_LIBRARY) $@  
  543.     $(AR) $@ $(OBJ)  
  544.   
  545.   
  546. # Link: create ELF output file from object files.  
  547. .SECONDARY : $(TARGET).elf  
  548. .PRECIOUS : $(OBJ)  
  549. %.elf: $(OBJ)  
  550.     @echo  
  551.     @echo $(MSG_LINKING) $@  
  552.     $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)  
  553.   
  554.   
  555. # Compile: create object files from C source files.  
  556. $(OBJDIR)/%.o : %.c  
  557.     @echo  
  558.     @echo $(MSG_COMPILING) $<  
  559.     $(CC) -c $(ALL_CFLAGS) $< -o $@   
  560.   
  561.   
  562. # Compile: create object files from C++ source files.  
  563. $(OBJDIR)/%.o : %.cpp  
  564.     @echo  
  565.     @echo $(MSG_COMPILING_CPP) $<  
  566.     $(CC) -c $(ALL_CPPFLAGS) $< -o $@   
  567.   
  568.   
  569.   
  570. # Compile: create assembler files from C source files.  
  571. %.s : %.c  
  572.     $(CC) -S $(ALL_CFLAGS) $< -o $@  
  573.   
  574.   
  575. # Compile: create assembler files from C++ source files.  
  576. %.s : %.cpp  
  577.     $(CC) -S $(ALL_CPPFLAGS) $< -o $@  
  578.   
  579.   
  580. # Assemble: create object files from assembler source files.  
  581. $(OBJDIR)/%.o : %.S  
  582.     @echo  
  583.     @echo $(MSG_ASSEMBLING) $<  
  584.     $(CC) -c $(ALL_ASFLAGS) $< -o $@  
  585.   
  586.   
  587. # Create preprocessed source for use in sending a bug report.  
  588. %.i : %.c  
  589.     $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@   
  590.   
  591.   
  592. # Target: clean project.  
  593. clean: begin clean_list end  
  594.   
  595. clean_list :  
  596.     @echo  
  597.     @echo $(MSG_CLEANING)  
  598.     $(REMOVE) $(TARGET).hex  
  599.     $(REMOVE) $(TARGET).eep  
  600.     $(REMOVE) $(TARGET).cof  
  601.     $(REMOVE) $(TARGET).elf  
  602.     $(REMOVE) $(TARGET).map  
  603.     $(REMOVE) $(TARGET).sym  
  604.     $(REMOVE) $(TARGET).lss  
  605.     $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)  
  606.     $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)  
  607.     $(REMOVE) $(SRC:.c=.s)  
  608.     $(REMOVE) $(SRC:.c=.d)  
  609.     $(REMOVE) $(SRC:.c=.i)  
  610.     $(REMOVEDIR) .dep  
  611.   
  612.   
  613. # Create object files directory  
  614. $(shell mkdir $(OBJDIR) 2>/dev/null)  
  615.   
  616.   
  617. # Include the dependency files.  
  618. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)  
  619.   
  620.   
  621. # Listing of phony targets.  
  622. .PHONY : all begin finish end sizebefore sizeafter gccversion \  
  623. build elf hex eep lss sym coff extcoff \  
  624. clean clean_list program debug gdb-config 
原文地址http://blog.csdn.net/galaxy_blue/article/details/7536197
深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值