Resolve uploading and major improvements

This commit is contained in:
Valeriy Koval
2015-02-05 20:13:21 +02:00
parent 6fac35fced
commit 7cdb8b0c7d
3 changed files with 89 additions and 58 deletions

View File

@ -5,12 +5,14 @@
Build script for Android Framework (based on Wiring).
"""
from os.path import join
from os import listdir
from os.path import isfile, join
from SCons.Script import Import, Return
env = None
Import("env")
BOARD_BUILDOPTS = env.get("BOARD_OPTIONS", {}).get("build", {})
ARDUINO_VERSION = int(
open(join(env.subst("$PLATFORMFW_DIR"),
@ -18,7 +20,7 @@ ARDUINO_VERSION = int(
# usb flags
ARDUINO_USBDEFINES = []
if "usb_product" in env.subst("${BOARD_OPTIONS['build']}"):
if "usb_product" in BOARD_BUILDOPTS:
ARDUINO_USBDEFINES = [
"USB_VID=${BOARD_OPTIONS['build']['vid']}",
"USB_PID=${BOARD_OPTIONS['build']['pid']}",
@ -26,18 +28,23 @@ if "usb_product" in env.subst("${BOARD_OPTIONS['build']}"):
"${BOARD_OPTIONS['build']['usb_product']}").replace('"', ""))
]
if env.get("BOARD_OPTIONS", {}).get("platform", None) == "teensy":
ARDUINO_USBDEFINES += [
"ARDUINO=106",
"TEENSYDUINO=%d" % ARDUINO_VERSION
]
else:
ARDUINO_USBDEFINES += ["ARDUINO=%d" % ARDUINO_VERSION]
env.Append(
CPPDEFINES=[
"ARDUINO=%d" % ARDUINO_VERSION
] + ARDUINO_USBDEFINES,
CPPDEFINES=ARDUINO_USBDEFINES,
CPPPATH=[
join("$BUILD_DIR", "FrameworkArduino")
]
)
# include board variant
if "variant" in env.get("BOARD_OPTIONS", {}).get("build", {}):
if "variant" in BOARD_BUILDOPTS:
env.VariantDir(
join("$BUILD_DIR", "FrameworkArduinoVariant"),
join("$PLATFORMFW_DIR", "variants",
@ -49,6 +56,26 @@ if "variant" in env.get("BOARD_OPTIONS", {}).get("build", {}):
]
)
if BOARD_BUILDOPTS.get("core", None) == "teensy":
# search relative includes in teensy directories
core_dir = join(env.get("PIOHOME_DIR"), "packages",
"framework-arduinoteensy", "cores", "teensy")
for item in listdir(core_dir):
file_path = join(core_dir, item)
if not isfile(file_path):
continue
content = None
content_changed = False
with open(file_path) as fp:
content = fp.read()
if '#include "../' in content:
content_changed = True
content = content.replace('#include "../', '#include "')
if not content_changed:
continue
with open(file_path, "w") as fp:
fp.write(content)
#
# Target: Build Core Library
#

View File

@ -5,12 +5,11 @@
Builder for Teensy boards
"""
from os.path import join
from os.path import isfile, join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment)
env = DefaultEnvironment()
if env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy":
@ -55,7 +54,7 @@ elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3":
ASFLAGS=[
"-mcpu=cortex-m4",
"-mthumb",
#"-nostdlib"
# "-nostdlib"
],
CXXFLAGS=[
@ -68,7 +67,7 @@ elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3":
"-mthumb",
"-ffunction-sections", # place each function in its own section
"-fdata-sections",
#"-nostdlib"
# "-nostdlib"
],
CPPDEFINES=[
@ -79,29 +78,13 @@ elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3":
"-mcpu=cortex-m4",
"-mthumb",
"-Wl,--gc-sections",
#"-nostartfiles",
#"-nostdlib",
# "-nostartfiles",
# "-nostdlib",
]
)
env.Append(
BUILDERS=dict(
ElfToEep=Builder(
action=" ".join([
"$OBJCOPY",
"-O",
"ihex",
"-j",
".eeprom",
'--set-section-flags=.eeprom="alloc,load"',
"--no-change-warnings",
"--change-section-lma",
".eeprom=0",
"$SOURCES",
"$TARGET"]),
suffix=".eep"
),
ElfToHex=Builder(
action=" ".join([
"$OBJCOPY",
@ -133,13 +116,10 @@ env.Append(
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU",
"USB_VID=null",
"USB_PID=null",
"USB_VID=null",
"TEENSYDUINO=120",
"USB_SERIAL",
"LAYOUT_US_ENGLISH",
"__MK20DX256__"
"LAYOUT_US_ENGLISH"
],
CXXFLAGS=[
@ -149,17 +129,33 @@ env.Append(
LINKFLAGS=[
"-Os"
],
UPLOADER=join(
"$PIOPACKAGES_DIR", "tool-teensy", "teensy_loader_cli"),
UPLOADERFLAGS=[
],
UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS -U flash:w:$SOURCES:i',
UPLOADEEPCMD='"$UPLOADER" $UPLOADERFLAGS -U eeprom:w:$SOURCES:i'
]
)
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'
)
CORELIBS = env.ProcessGeneral()
#
@ -168,13 +164,6 @@ CORELIBS = env.ProcessGeneral()
target_elf = env.BuildFirmware(CORELIBS + ["m"])
#
# Target: Extract EEPROM data (from EEMEM directive) to .eep file
#
target_eep = env.Alias("eep", env.ElfToEep(join("$BUILD_DIR", "firmware"),
target_elf))
#
# Target: Build the .hex file
#
@ -188,16 +177,9 @@ else:
# Target: Upload by default .hex file
#
upload = env.Alias(["upload", "uploadlazy"], target_hex, ("$UPLOADCMD"))
upload = env.Alias(["upload", "uploadlazy"], target_hex, ("$UPLOADHEXCMD"))
AlwaysBuild(upload)
#
# Target: Upload .eep file
#
uploadeep = env.Alias(["uploadeep"], target_eep, ("$UPLOADEEPCMD"))
AlwaysBuild(uploadeep)
#
# Target: Define targets
#

View File

@ -2,6 +2,7 @@
# See LICENSE for details.
from platformio.platforms.base import BasePlatform
from platformio.util import get_boards
class TeensyPlatform(BasePlatform):
@ -13,8 +14,15 @@ class TeensyPlatform(BasePlatform):
PACKAGES = {
"toolchain-atmelavr": {
"default": True
},
"toolchain-gccarmnoneeabi": {
"alias": "toolchain",
"default": True
},
"ldscripts": {
"default": True
},
@ -23,3 +31,17 @@ class TeensyPlatform(BasePlatform):
"default": True
}
}
def run(self, variables, targets):
for v in variables:
if "BOARD=" not in v:
continue
_, board = v.split("=")
bdata = get_boards(board)
if bdata['build']['core'] == "teensy":
tpackage = "toolchain-atmelavr"
else:
tpackage = "toolchain-gccarmnoneeabi"
self.PACKAGES[tpackage]['alias'] = "toolchain"
break
return BasePlatform.run(self, variables, targets)