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 [2010/05/24 01:30] suapapasconsarduino [2013/08/03 05:04] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +<code python>
 +#
 +# Copyright 2010 by Adam Mayer <adam@makerbot.com>
 +#
 +# 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 <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> <code python>
 avr = Environment() avr = Environment()
Line 53: Line 179:
 env['ARCH'] = 'avr' env['ARCH'] = 'avr'
 </code> </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 ====== ====== vim setting ======
   *copy [[http://www.vim.org/scripts/script.php?script_id=2654|arduino.vim]] under ~/.vim/syntax/   *copy [[http://www.vim.org/scripts/script.php?script_id=2654|arduino.vim]] under ~/.vim/syntax/
sconsarduino.1274664636.txt.gz · Last modified: 2013/08/03 05:04 (external edit)