User Tools

Site Tools


sconsarduino

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sconsarduino [2009/06/23 09:06] suapapasconsarduino [2013/08/03 05:04] (current) – external edit 127.0.0.1
Line 1: Line 1:
 <code python> <code python>
-"""     SConstruct 
 # #
-      Copyright 2008 Markus Burrer & CJT, cjt@users.sourceforge.net+# Copyright 2010 by Adam Mayer <adam@makerbot.com>
 # #
-      This program is free softwareyou can redistribute it and/or modify +# This program is free softwareyou can redistribute it and/or modify 
-      it under the terms of the GNU General Public License as published by +# it under the terms of the GNU General Public License as published by 
-      the Free Software Foundationeither version of the License, or +# the Free Software Foundationeither version of the License, or 
-      (at your option) any later version. +# (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 +This program is distributed in the hope that it will be useful, 
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# but WITHOUT ANY WARRANTY; without even the implied warranty of 
-      GNU General Public License for more details. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
-      You should have received a copy of the GNU General Public License +# GNU General Public License for more details. 
-      along with this program; if not, write to the Free Software +# 
-      FoundationInc., 51 Franklin StreetFifth FloorBoston+You should have received a copy of the GNU General Public License 
-      MA 02110-1301USA+# along with this program.  If not, see <http://www.gnu.org/licenses/> 
-"""+
 + 
 +
 +# 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) 
 +</code> 
 +<code python>
 avr = Environment() avr = Environment()
    
Line 59: Line 168:
 avr.Command(None, Target+".elf", "avr-size $SOURCE") avr.Command(None, Target+".elf", "avr-size $SOURCE")
 </code> </code>
 +또다른 avr 환경설정
 +<code python>
 +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'
 +</code>
 +====== section garbage collection ======
 +<code>
 +gcc -ffunction-sections -fdata-sections 
 +ld --gc-sections
 +</code>
 +  *[[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
 +<code vi>
 +au BufNewFile,BufRead *.pde setl ft=arduino
 +</code>
 ====== references ====== ====== references ======
-[[http://www.scons.org/doc/1.2.0/HTML/scons-user/book1.html|SconsUserGuide]]+  *[[http://www.scons.org/doc/1.2.0/HTML/scons-user/book1.html|SconsUserGuide]] 
 +  *[[http://johanneshoff.com/arduino-command-line.html|arduino-command-line]]
sconsarduino.1245747979.txt.gz · Last modified: 2013/08/03 05:04 (external edit)