Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

168 lines (142 sloc) 5.136 kB
#
# 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=mb24
# $ scons platform=mb24-2560
#
# 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','mb24')
# fived only applicable for rrmbv12
fived = ARGUMENTS.get('fived','false')
f_cpu='16000000L'
# Profiling flag
profiling = ARGUMENTS.get('profiling','0')
def parse_version(v):
if not v:
return 0
if v.find(".") != -1:
parts = v.split(".")
return (int(parts[0]) * 100) + int(parts[1])
return int(v)
def get_default_version():
regex = re.compile(r"const uint16_t firmware_version = ([0-9]+);")
return parse_version(f.get_contents().strip())
vstr = File('#/current_version.txt').get_contents().strip()
vstr = ARGUMENTS.get('version',vstr)
version = parse_version(vstr)
target_name = "MB-"+platform+"-v"+str(version//100)+"."+str(version%100)
if (platform == 'rrmbv12'):
default_baud = '38400'
default_programmer = 'stk500v1'
mcu='atmega644p'
has_queue = 1
has_psu = 1
elif (platform == 'mb24'):
default_baud = '57600'
default_programmer = 'stk500v1'
mcu='atmega1280'
has_queue = 1
has_psu = 0
elif (platform == 'mb24-2560'):
platform = 'mb24'
default_baud = '115200'
default_programmer = 'stk500v2'
mcu='atmega2560'
has_queue = 1
has_psu = 0
else:
print "Platform "+platform+" is not currently supported. Supported platforms are:"
print "rrmbv12: Gen 3 motherboard"
print "mb24: Gen4 motherboard"
print "mb24-2560: Gen4 motherboard with Mega 2560"
exit()
upload_port = ARGUMENTS.get('port','/dev/ttyUSB0')
upload_baud = ARGUMENTS.get('baud',default_baud)
upload_prog = ARGUMENTS.get('programmer',default_programmer)
srcs = Glob('*.cc') + Glob('Motherboard/*.cc') + Glob('Motherboard/lib_sd/*.c') + Glob('Motherboard/boards/%s/*.cc' % platform) + Glob('shared/*.cc')
include_paths = ['shared', 'Motherboard','Motherboard/boards/%s' % platform, '.']
flags=[
'-DF_CPU='+str(f_cpu),
'-DVERSION='+str(version),
'-mmcu='+mcu,
'-g',
'-Os',
'-w',
'-fno-exceptions',
'-ffunction-sections',
'-fdata-sections']
if (os.environ.has_key('BUILD_NAME')):
flags.append('-DBUILD_NAME=' + os.environ['BUILD_NAME'])
if (profiling == '1'):
flags.append('-DOVERRIDE_DEBUG_LED=1')
profiling = ARGUMENTS.get('profiling','0')
if (os.environ.has_key('AVR_TOOLS_PATH')):
avr_tools_path = os.environ['AVR_TOOLS_PATH']
elif (os.environ.has_key('AVR32_HOME')):
avr_tools_path = os.environ['AVR32_HOME'] + '\\bin'
else:
lines = os.popen('/usr/bin/which avr-gcc').readlines()
if(len(lines) > 0):
avr_tools_path = dirname(lines[0])
else:
print "which gcc failed. avr-gcc path not autodetected"
print "set AVR32_HOME or update 'which' and avr-gcc"
exit()
if (fived == 'true'):
flags.append('-DFOURTH_STEPPER=1')
env=Environment(tools=['g++', 'gcc'],
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'
map_name = target_name + '.map'
env.Append(BUILDERS={'Elf':Builder(action=avr_tools_path+"/avr-gcc -mmcu="+mcu+" -Os -Wl,--gc-sections -Wl,-Map,"+map_name+" -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 = "-F -V -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)
Jump to Line
Something went wrong with that request. Please try again.