# # Copyright 2010 by Adam Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see # # # HOW TO USE THIS BUILD SCRIPT # # By default, this script will build the firmware for an atmega644p-based motherboard. # The firmware will be built, but not uploaded. # # To build for another platform, pass an explicit platform parameter. For example, # $ scons platform=rrmbv12 # $ scons platform=rrmbv22 # # To upload the firmware, specify the "upload" target. By default, this will use # /dev/ttyUSB0 as the serial connection. # $ scons upload # # If you want to select a port manually, specify it as a parameter: # $ scons port=/dev/ttyUSB3 upload # import os import re from os.path import dirname # Parameters platform = ARGUMENTS.get('platform','rrmbv12') f_cpu='16000000L' default_baud = '19200' mcu='atmega168' has_queue = 0 has_psu = 0 def extract_version(f): regex = re.compile(r"const uint16_t firmware_version = ([0-9]+);") for line in f.get_contents().split('\n'): mo = regex.match(line) if mo: return int(mo.group(1)) return 0 version = extract_version(File('#/src/Motherboard/Version.hh')) if (platform == 'rrmbv12'): default_baud = '38400' mcu='atmega644p' has_queue = 1 has_psu = 1 elif (platform == 'rrmbv22'): default_baud = '57600' mcu='atmega1280' has_queue = 1 has_psu = 0 else: print "Platform "+platform+" is not currently supported.\n" exit() target_name = "MB-"+platform+"-v"+str(version/100)+"."+str(version%100) upload_port = ARGUMENTS.get('port','/dev/ttyUSB0') upload_baud = ARGUMENTS.get('baud',default_baud) upload_prog = ARGUMENTS.get('programmer','stk500v1') srcs = Glob('*.cc') + Glob('lib_sd/*.c') + Glob('boards/%s/*.cc' % platform) + Glob('#/src/shared/*.cc') include_paths = ['#/src/shared', 'boards/%s' % platform, '.'] flags=[ '-DF_CPU='+str(f_cpu), '-mmcu='+mcu, '-g', '-Os', '-w', '-fno-exceptions', '-ffunction-sections', '-fdata-sections'] if (os.environ.has_key('AVR_TOOLS_PATH')): avr_tools_path = os.environ['AVR_TOOLS_PATH'] else: avr_tools_path = dirname(os.popen('/usr/bin/which avr-gcc').readlines()[0]) env=Environment(CC=avr_tools_path+"/avr-g++", CXX=avr_tools_path+"/avr-g++", CPPPATH=include_paths, CCFLAGS=flags) objs = env.Object(srcs) # run_alias = Alias('run', [program], program[0].path) # AlwaysBuild(run_alias) hex_name = target_name + '.hex' elf_name = target_name + '.elf' env.Append(BUILDERS={'Elf':Builder(action=avr_tools_path+"/avr-gcc -mmcu="+mcu+" -Os -Wl,--gc-sections -o $TARGET $SOURCES")}) env.Append(BUILDERS={'Hex':Builder(action=avr_tools_path+"/avr-objcopy -O ihex -R .eeprom $SOURCES $TARGET")}) env.Elf(elf_name, objs) env.Hex(hex_name, elf_name) avrdude = avr_tools_path+"/avrdude" avrdude_flags = "-V -F -p "+mcu.replace("atmega","m") avrdude_flags = avrdude_flags + " -P "+upload_port avrdude_flags = avrdude_flags + " -c "+upload_prog avrdude_flags = avrdude_flags + " -b "+upload_baud avrdude_command = " ".join([avrdude,avrdude_flags,"-U","flash:w:$SOURCES"]) # env.Alias instead of just Alias because of # http://scons.tigris.org/issues/show_bug.cgi?id=2443 upload_alias = env.Alias('upload', hex_name, avrdude_command) AlwaysBuild(upload_alias) avr = Environment() Target="main" mcu="atmega128" F_CPU=16e6 # Add all additional source files to compile src=""" obj/utils.c obj/usart.c obj/usart1.c""" # Add Source Path here cpppath=""" . ../../EP-gcc-lib""" # 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" # Add Additional Compiler Flags flags=""" """ # Add Variant Dirs avr.VariantDir('obj', '../../EP-gcc-lib') # Set Environment Parameters avr['CC'] = "avr-gcc -mmcu=%s" % mcu avr.Append(CPPPATH = Split(cpppath)) avr.Append(CCFLAGS = "-O%s" % opt) avr.Append(CCFLAGS = "-Wall" ) avr.Append(CCFLAGS = "-DF_CPU=%i" % F_CPU) avr.Append(CCFLAGS = Split(flags)) # Execute AVR-GCC avr.Program(Target+".elf", Split(Target+".c " + src)) avr.Command(Target+".hex", Target+".elf", "avr-objcopy -j .text -j .data -O ihex $SOURCE $TARGET") # Show memory usage avr.Command(None, Target+".elf", "avr-size $SOURCE") 또다른 avr 환경설정 env.Append(CPPDEFINES = {'ARCH_AVR' : 1}) env.Append(CCFLAGS = '-mmcu=atmega128') env.Append(LINKFLAGS = '-mmcu=atmega128') env['CC'] = 'avr-gcc' env['RANLIB'] = 'avr-ranlib' env['OBJCOPY'] = 'avr-objcopy' env['ARCH'] = 'avr' ====== section garbage collection ====== gcc -ffunction-sections -fdata-sections ld --gc-sections *[[http://kldp.org/node/94079|kldp 관련글]] *[[http://lwn.net/Articles/249005|위 글에 링크된 글]] ====== vim setting ====== *copy [[http://www.vim.org/scripts/script.php?script_id=2654|arduino.vim]] under ~/.vim/syntax/ *link pde extention to arduino syntax au BufNewFile,BufRead *.pde setl ft=arduino ====== references ====== *[[http://www.scons.org/doc/1.2.0/HTML/scons-user/book1.html|SconsUserGuide]] *[[http://johanneshoff.com/arduino-command-line.html|arduino-command-line]]