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). 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 from SCons.Script import Import, Return
env = None env = None
Import("env") Import("env")
BOARD_BUILDOPTS = env.get("BOARD_OPTIONS", {}).get("build", {})
ARDUINO_VERSION = int( ARDUINO_VERSION = int(
open(join(env.subst("$PLATFORMFW_DIR"), open(join(env.subst("$PLATFORMFW_DIR"),
@ -18,7 +20,7 @@ ARDUINO_VERSION = int(
# usb flags # usb flags
ARDUINO_USBDEFINES = [] ARDUINO_USBDEFINES = []
if "usb_product" in env.subst("${BOARD_OPTIONS['build']}"): if "usb_product" in BOARD_BUILDOPTS:
ARDUINO_USBDEFINES = [ ARDUINO_USBDEFINES = [
"USB_VID=${BOARD_OPTIONS['build']['vid']}", "USB_VID=${BOARD_OPTIONS['build']['vid']}",
"USB_PID=${BOARD_OPTIONS['build']['pid']}", "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('"', "")) "${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( env.Append(
CPPDEFINES=[ CPPDEFINES=ARDUINO_USBDEFINES,
"ARDUINO=%d" % ARDUINO_VERSION
] + ARDUINO_USBDEFINES,
CPPPATH=[ CPPPATH=[
join("$BUILD_DIR", "FrameworkArduino") join("$BUILD_DIR", "FrameworkArduino")
] ]
) )
# include board variant if "variant" in BOARD_BUILDOPTS:
if "variant" in env.get("BOARD_OPTIONS", {}).get("build", {}):
env.VariantDir( env.VariantDir(
join("$BUILD_DIR", "FrameworkArduinoVariant"), join("$BUILD_DIR", "FrameworkArduinoVariant"),
join("$PLATFORMFW_DIR", "variants", 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 # Target: Build Core Library
# #

View File

@ -5,12 +5,11 @@
Builder for Teensy boards 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, from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment) DefaultEnvironment)
env = DefaultEnvironment() env = DefaultEnvironment()
if env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy": 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=[ ASFLAGS=[
"-mcpu=cortex-m4", "-mcpu=cortex-m4",
"-mthumb", "-mthumb",
#"-nostdlib" # "-nostdlib"
], ],
CXXFLAGS=[ CXXFLAGS=[
@ -68,7 +67,7 @@ elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3":
"-mthumb", "-mthumb",
"-ffunction-sections", # place each function in its own section "-ffunction-sections", # place each function in its own section
"-fdata-sections", "-fdata-sections",
#"-nostdlib" # "-nostdlib"
], ],
CPPDEFINES=[ CPPDEFINES=[
@ -79,29 +78,13 @@ elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3":
"-mcpu=cortex-m4", "-mcpu=cortex-m4",
"-mthumb", "-mthumb",
"-Wl,--gc-sections", "-Wl,--gc-sections",
#"-nostartfiles", # "-nostartfiles",
#"-nostdlib", # "-nostdlib",
] ]
) )
env.Append( env.Append(
BUILDERS=dict( 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( ElfToHex=Builder(
action=" ".join([ action=" ".join([
"$OBJCOPY", "$OBJCOPY",
@ -133,13 +116,10 @@ env.Append(
CPPDEFINES=[ CPPDEFINES=[
"F_CPU=$BOARD_F_CPU", "F_CPU=$BOARD_F_CPU",
"USB_VID=null",
"USB_PID=null", "USB_PID=null",
"USB_VID=null", "USB_VID=null",
"TEENSYDUINO=120",
"USB_SERIAL", "USB_SERIAL",
"LAYOUT_US_ENGLISH", "LAYOUT_US_ENGLISH"
"__MK20DX256__"
], ],
CXXFLAGS=[ CXXFLAGS=[
@ -149,17 +129,33 @@ env.Append(
LINKFLAGS=[ LINKFLAGS=[
"-Os" "-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() CORELIBS = env.ProcessGeneral()
# #
@ -168,13 +164,6 @@ CORELIBS = env.ProcessGeneral()
target_elf = env.BuildFirmware(CORELIBS + ["m"]) 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 # Target: Build the .hex file
# #
@ -188,16 +177,9 @@ else:
# Target: Upload by default .hex file # Target: Upload by default .hex file
# #
upload = env.Alias(["upload", "uploadlazy"], target_hex, ("$UPLOADCMD")) upload = env.Alias(["upload", "uploadlazy"], target_hex, ("$UPLOADHEXCMD"))
AlwaysBuild(upload) AlwaysBuild(upload)
#
# Target: Upload .eep file
#
uploadeep = env.Alias(["uploadeep"], target_eep, ("$UPLOADEEPCMD"))
AlwaysBuild(uploadeep)
# #
# Target: Define targets # Target: Define targets
# #

View File

@ -2,6 +2,7 @@
# See LICENSE for details. # See LICENSE for details.
from platformio.platforms.base import BasePlatform from platformio.platforms.base import BasePlatform
from platformio.util import get_boards
class TeensyPlatform(BasePlatform): class TeensyPlatform(BasePlatform):
@ -13,8 +14,15 @@ class TeensyPlatform(BasePlatform):
PACKAGES = { PACKAGES = {
"toolchain-atmelavr": {
"default": True
},
"toolchain-gccarmnoneeabi": { "toolchain-gccarmnoneeabi": {
"alias": "toolchain", "default": True
},
"ldscripts": {
"default": True "default": True
}, },
@ -23,3 +31,17 @@ class TeensyPlatform(BasePlatform):
"default": True "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)