2015-02-04 20:39:38 +02:00
|
|
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
|
|
|
# See LICENSE for details.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Builder for Teensy boards
|
|
|
|
"""
|
|
|
|
|
2015-02-05 20:13:21 +02:00
|
|
|
from os.path import isfile, join
|
2015-02-06 18:34:29 +02:00
|
|
|
from random import randint
|
2015-02-04 20:39:38 +02:00
|
|
|
|
|
|
|
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
|
|
|
|
DefaultEnvironment)
|
|
|
|
|
|
|
|
env = DefaultEnvironment()
|
|
|
|
|
|
|
|
if env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy":
|
|
|
|
env.Replace(
|
|
|
|
AR="avr-ar",
|
|
|
|
AS="avr-gcc",
|
|
|
|
CC="avr-gcc",
|
|
|
|
CXX="avr-g++",
|
|
|
|
OBJCOPY="avr-objcopy",
|
|
|
|
RANLIB="avr-ranlib",
|
2015-02-09 19:57:39 +02:00
|
|
|
SIZETOOL="avr-size",
|
2015-02-04 20:39:38 +02:00
|
|
|
|
|
|
|
ARFLAGS=["rcs"],
|
|
|
|
|
|
|
|
CXXFLAGS=[
|
|
|
|
"-std=c++0x"
|
|
|
|
],
|
|
|
|
|
|
|
|
CPPFLAGS=[
|
|
|
|
"-mmcu=$BOARD_MCU"
|
|
|
|
],
|
|
|
|
|
|
|
|
CPPDEFINES=[
|
2015-02-06 18:34:29 +02:00
|
|
|
"SERIALNUM=-%d" % randint(1000000000, 2000000000)
|
2015-02-04 20:39:38 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-mmcu=$BOARD_MCU"
|
2015-02-09 19:57:39 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
SIZEPRINTCMD='"$SIZETOOL" --mcu=$BOARD_MCU -C -d $SOURCES'
|
2015-02-04 20:39:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3":
|
|
|
|
env.Replace(
|
|
|
|
AR="arm-none-eabi-ar",
|
|
|
|
AS="arm-none-eabi-gcc",
|
|
|
|
CC="arm-none-eabi-gcc",
|
|
|
|
CXX="arm-none-eabi-g++",
|
|
|
|
OBJCOPY="arm-none-eabi-objcopy",
|
|
|
|
RANLIB="arm-none-eabi-ranlib",
|
2015-02-09 19:57:39 +02:00
|
|
|
SIZETOOL="arm-none-eabi-size",
|
2015-02-04 20:39:38 +02:00
|
|
|
|
|
|
|
ARFLAGS=["rcs"],
|
|
|
|
|
|
|
|
ASFLAGS=[
|
|
|
|
"-mcpu=cortex-m4",
|
|
|
|
"-mthumb",
|
2015-02-05 20:13:21 +02:00
|
|
|
# "-nostdlib"
|
2015-02-04 20:39:38 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
CXXFLAGS=[
|
|
|
|
"-std=gnu++0x",
|
|
|
|
"-fno-rtti",
|
|
|
|
],
|
|
|
|
|
|
|
|
CPPFLAGS=[
|
|
|
|
"-mcpu=cortex-m4",
|
|
|
|
"-mthumb",
|
|
|
|
"-ffunction-sections", # place each function in its own section
|
|
|
|
"-fdata-sections",
|
2015-02-05 20:13:21 +02:00
|
|
|
# "-nostdlib"
|
2015-02-04 20:39:38 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-mcpu=cortex-m4",
|
|
|
|
"-mthumb",
|
|
|
|
"-Wl,--gc-sections",
|
2015-02-05 20:13:21 +02:00
|
|
|
# "-nostartfiles",
|
|
|
|
# "-nostdlib",
|
2015-02-09 19:57:39 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES'
|
2015-02-04 20:39:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
env.Append(
|
|
|
|
BUILDERS=dict(
|
|
|
|
ElfToHex=Builder(
|
|
|
|
action=" ".join([
|
|
|
|
"$OBJCOPY",
|
|
|
|
"-O",
|
|
|
|
"ihex",
|
|
|
|
"-R",
|
|
|
|
".eeprom",
|
|
|
|
"$SOURCES",
|
|
|
|
"$TARGET"]),
|
|
|
|
suffix=".hex"
|
|
|
|
)
|
|
|
|
),
|
|
|
|
|
|
|
|
ASFLAGS=[
|
|
|
|
"-c",
|
|
|
|
"-g", # include debugging info (so errors include line numbers)
|
|
|
|
"-x", "assembler-with-cpp",
|
|
|
|
"-Wall"
|
|
|
|
],
|
|
|
|
|
|
|
|
CPPFLAGS=[
|
|
|
|
"-g", # include debugging info (so errors include line numbers)
|
|
|
|
"-Os", # optimize for size
|
|
|
|
"-fdata-sections",
|
|
|
|
"-ffunction-sections", # place each function in its own section
|
|
|
|
"-Wall",
|
|
|
|
"-MMD" # output dependancy info
|
|
|
|
],
|
|
|
|
|
|
|
|
CPPDEFINES=[
|
|
|
|
"F_CPU=$BOARD_F_CPU",
|
|
|
|
"USB_PID=null",
|
|
|
|
"USB_VID=null",
|
|
|
|
"USB_SERIAL",
|
2015-02-05 20:13:21 +02:00
|
|
|
"LAYOUT_US_ENGLISH"
|
2015-02-04 20:39:38 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
CXXFLAGS=[
|
|
|
|
"-felide-constructors",
|
|
|
|
"-fno-exceptions"
|
|
|
|
],
|
|
|
|
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-Os"
|
2015-02-05 20:13:21 +02:00
|
|
|
]
|
2015-02-04 20:39:38 +02:00
|
|
|
)
|
|
|
|
|
2015-02-05 20:13:21 +02:00
|
|
|
if isfile(env.subst(join(
|
|
|
|
"$PIOPACKAGES_DIR", "tool-teensy", "teensy_loader_cli"))):
|
|
|
|
env.Append(
|
|
|
|
UPLOADER=join("$PIOPACKAGES_DIR", "tool-teensy", "teensy_loader_cli"),
|
|
|
|
UPLOADERFLAGS=[
|
|
|
|
"-mmcu=$BOARD_MCU",
|
|
|
|
"-w", # wait for device to apear
|
|
|
|
"-r", # hard reboot if device not online
|
|
|
|
"-v" # verbose output
|
|
|
|
],
|
|
|
|
UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
env.Append(
|
|
|
|
UPLOADER=join(
|
|
|
|
"$PIOPACKAGES_DIR", "tool-teensy", "teensy_post_compile"),
|
|
|
|
UPLOADERFLAGS=[
|
|
|
|
"-file=firmware",
|
|
|
|
'-path="$BUILD_DIR"',
|
|
|
|
'-tools="%s"' % join("$PIOPACKAGES_DIR", "tool-teensy")
|
|
|
|
],
|
|
|
|
UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS'
|
|
|
|
)
|
|
|
|
|
2015-02-04 20:39:38 +02:00
|
|
|
CORELIBS = env.ProcessGeneral()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Target: Build executable and linkable firmware
|
|
|
|
#
|
|
|
|
|
|
|
|
target_elf = env.BuildFirmware(CORELIBS + ["m"])
|
|
|
|
|
|
|
|
#
|
|
|
|
# Target: Build the .hex file
|
|
|
|
#
|
|
|
|
|
|
|
|
if "uploadlazy" in COMMAND_LINE_TARGETS:
|
|
|
|
target_hex = join("$BUILD_DIR", "firmware.hex")
|
|
|
|
else:
|
|
|
|
target_hex = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf)
|
|
|
|
|
2015-02-09 19:57:39 +02:00
|
|
|
#
|
|
|
|
# Target: Print binary size
|
|
|
|
#
|
|
|
|
|
|
|
|
target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
|
|
|
|
AlwaysBuild(target_size)
|
|
|
|
|
2015-02-04 20:39:38 +02:00
|
|
|
#
|
|
|
|
# Target: Upload by default .hex file
|
|
|
|
#
|
|
|
|
|
2015-02-05 20:13:21 +02:00
|
|
|
upload = env.Alias(["upload", "uploadlazy"], target_hex, ("$UPLOADHEXCMD"))
|
2015-02-04 20:39:38 +02:00
|
|
|
AlwaysBuild(upload)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Target: Define targets
|
|
|
|
#
|
|
|
|
|
2015-02-09 19:57:39 +02:00
|
|
|
Default([target_hex, target_size])
|