From 9a221085d4b33c2dc6a875f30ff1c5fab398142a Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Wed, 4 Feb 2015 20:29:07 +0200 Subject: [PATCH 1/5] Fix optional board "extra_flags" and "ldscript" --- platformio/builder/main.py | 9 ----- .../builder/scripts/frameworks/opencm3.py | 4 +-- platformio/builder/scripts/frameworks/spl.py | 2 +- platformio/builder/scripts/stm32.py | 33 ++++++++----------- platformio/builder/scripts/titiva.py | 10 +++--- platformio/builder/tools/platformio.py | 10 ++++++ 6 files changed, 31 insertions(+), 37 deletions(-) diff --git a/platformio/builder/main.py b/platformio/builder/main.py index e2383e00..3bde0b9d 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -84,15 +84,6 @@ if "BOARD" in env: env.Replace(UPLOAD_PROTOCOL="${BOARD_OPTIONS['upload']['protocol']}") if "UPLOAD_SPEED" not in env: env.Replace(UPLOAD_SPEED="${BOARD_OPTIONS['upload']['speed']}") - # specific linker script - if "ldscript" in env.get("BOARD_OPTIONS", {}).get("build", {}): - env.Replace( - LINKFLAGS=["-T", join( - "$PIOHOME_DIR", "packages", "ldscripts", - "${BOARD_OPTIONS['build']['ldscript']}")] - ) - if "extra_flags" in env.get("BOARD_OPTIONS", {}).get("build", {}): - env.MergeFlags(env.subst("${BOARD_OPTIONS['build']['extra_flags']}")) if "IGNORE_LIBS" in env: env['IGNORE_LIBS'] = [l.strip() for l in env['IGNORE_LIBS'].split(",")] diff --git a/platformio/builder/scripts/frameworks/opencm3.py b/platformio/builder/scripts/frameworks/opencm3.py index 82c9a5bb..d07357c4 100644 --- a/platformio/builder/scripts/frameworks/opencm3.py +++ b/platformio/builder/scripts/frameworks/opencm3.py @@ -156,8 +156,8 @@ merge_ld_scripts(ldscript_path) generate_nvic_files() # override ldscript by opencm3 -assert env['LINKFLAGS'][0] == "-T" -env['LINKFLAGS'][1] = ldscript_path +assert "-T" in env['LINKFLAGS'] +env['LINKFLAGS'][env['LINKFLAGS'].index("-T") + 1] = ldscript_path libs = [] env.VariantDir( diff --git a/platformio/builder/scripts/frameworks/spl.py b/platformio/builder/scripts/frameworks/spl.py index 239a6ba2..62801bfd 100644 --- a/platformio/builder/scripts/frameworks/spl.py +++ b/platformio/builder/scripts/frameworks/spl.py @@ -50,7 +50,7 @@ if "STM32F40_41xxx" in extra_flags: elif "STM32F303xC" in extra_flags: ignore_files += ["stm32f30x_hrtim.c"] elif "STM32L1XX_MD" in extra_flags: - ignore_files += ["stm32l1xx_flash_ramfunc.c"] # removed warning + ignore_files += ["stm32l1xx_flash_ramfunc.c"] libs = [] libs.append(envsafe.BuildLibrary( diff --git a/platformio/builder/scripts/stm32.py b/platformio/builder/scripts/stm32.py index 38b3af25..3793e7de 100644 --- a/platformio/builder/scripts/stm32.py +++ b/platformio/builder/scripts/stm32.py @@ -48,6 +48,20 @@ env.Replace( "-fno-exceptions" ], + CPPDEFINES=[ + "F_CPU=$BOARD_F_CPU", + "${BOARD_OPTIONS['build']['variant'].upper()}" + ], + + LINKFLAGS=[ + "-Os", + "-nostartfiles", + "-nostdlib", + "-Wl,--gc-sections", + "-mthumb", + "-mcpu=${BOARD_OPTIONS['build']['mcu']}" + ], + UPLOADER=join("$PIOPACKAGES_DIR", "tool-stlink", "st-flash"), UPLOADERFLAGS=[ "write", # write in flash @@ -58,25 +72,6 @@ env.Replace( UPLOADCMD="$UPLOADER $UPLOADERFLAGS" ) - -env.Append( - CPPDEFINES=[ - "F_CPU=$BOARD_F_CPU", - "${BOARD_OPTIONS['build']['variant'].upper()}" - ] -) - -env.Append( - LINKFLAGS=[ - "-Os", - "-nostartfiles", - "-nostdlib", - "-Wl,--gc-sections", - "-mthumb", - "-mcpu=${BOARD_OPTIONS['build']['mcu']}" - ] -) - if env.get("BOARD_OPTIONS", {}).get("build", {}).get("mcu")[-2:] == "m4": env.Append( ASFLAGS=[ diff --git a/platformio/builder/scripts/titiva.py b/platformio/builder/scripts/titiva.py index e5c39a88..613e6aef 100644 --- a/platformio/builder/scripts/titiva.py +++ b/platformio/builder/scripts/titiva.py @@ -59,11 +59,6 @@ env.Replace( "F_CPU=$BOARD_F_CPU" ], - UPLOADER=join("$PIOPACKAGES_DIR", "tool-lm4flash", "lm4flash"), - UPLOADCMD="$UPLOADER $SOURCES" -) - -env.Append( LINKFLAGS=[ "-Os", "-nostartfiles", @@ -74,7 +69,10 @@ env.Append( "-mfloat-abi=hard", "-mfpu=fpv4-sp-d16", "-fsingle-precision-constant" - ] + ], + + UPLOADER=join("$PIOPACKAGES_DIR", "tool-lm4flash", "lm4flash"), + UPLOADCMD="$UPLOADER $SOURCES" ) env.Append( diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 7f6ceb08..09aba659 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -16,6 +16,16 @@ from platformio.util import get_serialports def ProcessGeneral(env): corelibs = [] + # specific linker script + if "ldscript" in env.get("BOARD_OPTIONS", {}).get("build", {}): + env.Append( + LINKFLAGS=["-T", join( + "$PIOHOME_DIR", "packages", "ldscripts", + "${BOARD_OPTIONS['build']['ldscript']}")] + ) + if "extra_flags" in env.get("BOARD_OPTIONS", {}).get("build", {}): + env.MergeFlags(env.subst("${BOARD_OPTIONS['build']['extra_flags']}")) + if "BUILD_FLAGS" in env: env.MergeFlags(env['BUILD_FLAGS']) From 2ab49d7f2462f5423353e2d037f73d139394d5ef Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Wed, 4 Feb 2015 20:39:38 +0200 Subject: [PATCH 2/5] Initial support for Teensy 3 --- platformio/boards/teensy.json | 65 +++++++++ platformio/builder/scripts/teensy.py | 205 +++++++++++++++++++++++++++ platformio/platforms/teensy.py | 25 ++++ 3 files changed, 295 insertions(+) create mode 100644 platformio/boards/teensy.json create mode 100644 platformio/builder/scripts/teensy.py create mode 100644 platformio/platforms/teensy.py diff --git a/platformio/boards/teensy.json b/platformio/boards/teensy.json new file mode 100644 index 00000000..23e30817 --- /dev/null +++ b/platformio/boards/teensy.json @@ -0,0 +1,65 @@ +{ + "teensy2": { + "build": { + "core": "teensy", + "f_cpu": "16000000L", + "mcu": "atmega32u4", + "variant": "teensy2" + }, + "name": "Teensy 2.0", + "platform": "teensy", + "upload": { + "maximum_ram_size": 2560, + "maximum_size": 32256 + } + }, + + "teensypp2": { + "build": { + "core": "teensy", + "f_cpu": "16000000L", + "mcu": "at90usb1286", + "variant": "teensypp2" + }, + "name": "Teensy 2.0", + "platform": "teensy", + "upload": { + "maximum_ram_size": 8192, + "maximum_size": 130048 + } + }, + + "teensy30": { + "build": { + "core": "teensy3", + "extra_flags": "-D__MK20DX128__", + "f_cpu": "48000000L", + "ldscript": "mk20dx128.ld", + "mcu": "mk20dx128", + "variant": "teensy30" + }, + "name": "Teensy 3.0", + "platform": "teensy", + "upload": { + "maximum_ram_size": 16384, + "maximum_size": 131072 + } + }, + + "teensy31": { + "build": { + "core": "teensy3", + "extra_flags": "-D__MK20DX256__", + "f_cpu": "72000000L", + "ldscript": "mk20dx256.ld", + "mcu": "mk20dx256", + "variant": "teensy31" + }, + "name": "Teensy 3.1", + "platform": "teensy", + "upload": { + "maximum_ram_size": 65536, + "maximum_size": 262144 + } + } +} \ No newline at end of file diff --git a/platformio/builder/scripts/teensy.py b/platformio/builder/scripts/teensy.py new file mode 100644 index 00000000..b3c9845a --- /dev/null +++ b/platformio/builder/scripts/teensy.py @@ -0,0 +1,205 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +""" + Builder for Teensy boards +""" + +from os.path import join + +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", + + ARFLAGS=["rcs"], + + CXXFLAGS=[ + "-std=c++0x" + ], + + CPPFLAGS=[ + "-mmcu=$BOARD_MCU" + ], + + CPPDEFINES=[ + "SERIALNUM=-1164905212" # ????? + ], + + LINKFLAGS=[ + "-mmcu=$BOARD_MCU" + ] + ) + +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", + + ARFLAGS=["rcs"], + + ASFLAGS=[ + "-mcpu=cortex-m4", + "-mthumb", + #"-nostdlib" + ], + + CXXFLAGS=[ + "-std=gnu++0x", + "-fno-rtti", + ], + + CPPFLAGS=[ + "-mcpu=cortex-m4", + "-mthumb", + "-ffunction-sections", # place each function in its own section + "-fdata-sections", + #"-nostdlib" + ], + + CPPDEFINES=[ + "TIME_T=1423046159" # @TODO + ], + + LINKFLAGS=[ + "-mcpu=cortex-m4", + "-mthumb", + "-Wl,--gc-sections", + #"-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", + "-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_VID=null", + "USB_PID=null", + "USB_VID=null", + "TEENSYDUINO=120", + "USB_SERIAL", + "LAYOUT_US_ENGLISH", + "__MK20DX256__" + ], + + CXXFLAGS=[ + "-felide-constructors", + "-fno-exceptions" + ], + + 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' +) + +CORELIBS = env.ProcessGeneral() + +# +# Target: Build executable and linkable firmware +# + +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 +# + +if "uploadlazy" in COMMAND_LINE_TARGETS: + target_hex = join("$BUILD_DIR", "firmware.hex") +else: + target_hex = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf) + +# +# Target: Upload by default .hex file +# + +upload = env.Alias(["upload", "uploadlazy"], target_hex, ("$UPLOADCMD")) +AlwaysBuild(upload) + +# +# Target: Upload .eep file +# + +uploadeep = env.Alias(["uploadeep"], target_eep, ("$UPLOADEEPCMD")) +AlwaysBuild(uploadeep) + +# +# Target: Define targets +# + +Default(target_hex) diff --git a/platformio/platforms/teensy.py b/platformio/platforms/teensy.py new file mode 100644 index 00000000..bf4e375a --- /dev/null +++ b/platformio/platforms/teensy.py @@ -0,0 +1,25 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +from platformio.platforms.base import BasePlatform + + +class TeensyPlatform(BasePlatform): + + """ + An embedded platform for Teensy boards + (with Arduino Framework) + """ + + PACKAGES = { + + "toolchain-gccarmnoneeabi": { + "alias": "toolchain", + "default": True + }, + + "framework-arduinoteensy": { + "alias": "framework", + "default": True + } + } From 6fac35fcedb595747b05c35d3e97765515ddc933 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Thu, 5 Feb 2015 20:00:56 +0200 Subject: [PATCH 3/5] Cleanup --- platformio/builder/scripts/frameworks/cmsis.py | 1 - platformio/builder/scripts/frameworks/opencm3.py | 1 - platformio/builder/scripts/frameworks/spl.py | 1 - 3 files changed, 3 deletions(-) diff --git a/platformio/builder/scripts/frameworks/cmsis.py b/platformio/builder/scripts/frameworks/cmsis.py index a1c0c9a6..4f194034 100644 --- a/platformio/builder/scripts/frameworks/cmsis.py +++ b/platformio/builder/scripts/frameworks/cmsis.py @@ -9,7 +9,6 @@ from os.path import join from SCons.Script import Import, Return - env = None Import("env") diff --git a/platformio/builder/scripts/frameworks/opencm3.py b/platformio/builder/scripts/frameworks/opencm3.py index d07357c4..324d7bee 100644 --- a/platformio/builder/scripts/frameworks/opencm3.py +++ b/platformio/builder/scripts/frameworks/opencm3.py @@ -13,7 +13,6 @@ from SCons.Script import Import, Return from platformio.util import exec_command - env = None Import("env") BOARD_BUILDOPTS = env.get("BOARD_OPTIONS", {}).get("build", {}) diff --git a/platformio/builder/scripts/frameworks/spl.py b/platformio/builder/scripts/frameworks/spl.py index 62801bfd..39cdb4ec 100644 --- a/platformio/builder/scripts/frameworks/spl.py +++ b/platformio/builder/scripts/frameworks/spl.py @@ -9,7 +9,6 @@ from os.path import join from SCons.Script import Import, Return - env = None Import("env") From 7cdb8b0c7d8873882f6adec6769f630035e08928 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Thu, 5 Feb 2015 20:13:21 +0200 Subject: [PATCH 4/5] Resolve uploading and major improvements --- .../builder/scripts/frameworks/arduino.py | 41 ++++++++-- platformio/builder/scripts/teensy.py | 82 ++++++++----------- platformio/platforms/teensy.py | 24 +++++- 3 files changed, 89 insertions(+), 58 deletions(-) diff --git a/platformio/builder/scripts/frameworks/arduino.py b/platformio/builder/scripts/frameworks/arduino.py index ef7f2123..2ea76556 100644 --- a/platformio/builder/scripts/frameworks/arduino.py +++ b/platformio/builder/scripts/frameworks/arduino.py @@ -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 # diff --git a/platformio/builder/scripts/teensy.py b/platformio/builder/scripts/teensy.py index b3c9845a..42446526 100644 --- a/platformio/builder/scripts/teensy.py +++ b/platformio/builder/scripts/teensy.py @@ -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 # diff --git a/platformio/platforms/teensy.py b/platformio/platforms/teensy.py index bf4e375a..4a45a2ca 100644 --- a/platformio/platforms/teensy.py +++ b/platformio/platforms/teensy.py @@ -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) From 70839abf887afa6aa740ae1f328bd891118014c9 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Fri, 6 Feb 2015 18:34:29 +0200 Subject: [PATCH 5/5] Finalize with Teensy platform --- platformio/boards/teensy.json | 20 ++++++++----------- .../builder/scripts/frameworks/arduino.py | 2 +- platformio/builder/scripts/teensy.py | 6 ++++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/platformio/boards/teensy.json b/platformio/boards/teensy.json index 23e30817..b1882bc9 100644 --- a/platformio/boards/teensy.json +++ b/platformio/boards/teensy.json @@ -1,10 +1,9 @@ { - "teensy2": { + "teensy20": { "build": { "core": "teensy", "f_cpu": "16000000L", - "mcu": "atmega32u4", - "variant": "teensy2" + "mcu": "atmega32u4" }, "name": "Teensy 2.0", "platform": "teensy", @@ -14,14 +13,13 @@ } }, - "teensypp2": { + "teensy20pp": { "build": { "core": "teensy", "f_cpu": "16000000L", - "mcu": "at90usb1286", - "variant": "teensypp2" + "mcu": "at90usb1286" }, - "name": "Teensy 2.0", + "name": "Teensy++ 2.0", "platform": "teensy", "upload": { "maximum_ram_size": 8192, @@ -35,8 +33,7 @@ "extra_flags": "-D__MK20DX128__", "f_cpu": "48000000L", "ldscript": "mk20dx128.ld", - "mcu": "mk20dx128", - "variant": "teensy30" + "mcu": "mk20dx128" }, "name": "Teensy 3.0", "platform": "teensy", @@ -52,8 +49,7 @@ "extra_flags": "-D__MK20DX256__", "f_cpu": "72000000L", "ldscript": "mk20dx256.ld", - "mcu": "mk20dx256", - "variant": "teensy31" + "mcu": "mk20dx256" }, "name": "Teensy 3.1", "platform": "teensy", @@ -62,4 +58,4 @@ "maximum_size": 262144 } } -} \ No newline at end of file +} diff --git a/platformio/builder/scripts/frameworks/arduino.py b/platformio/builder/scripts/frameworks/arduino.py index 2ea76556..c99ae9a6 100644 --- a/platformio/builder/scripts/frameworks/arduino.py +++ b/platformio/builder/scripts/frameworks/arduino.py @@ -2,7 +2,7 @@ # See LICENSE for details. """ - Build script for Android Framework (based on Wiring). + Build script for Arduino Framework (based on Wiring). """ from os import listdir diff --git a/platformio/builder/scripts/teensy.py b/platformio/builder/scripts/teensy.py index 42446526..11d391e5 100644 --- a/platformio/builder/scripts/teensy.py +++ b/platformio/builder/scripts/teensy.py @@ -5,7 +5,9 @@ Builder for Teensy boards """ +import time from os.path import isfile, join +from random import randint from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default, DefaultEnvironment) @@ -32,7 +34,7 @@ if env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy": ], CPPDEFINES=[ - "SERIALNUM=-1164905212" # ????? + "SERIALNUM=-%d" % randint(1000000000, 2000000000) ], LINKFLAGS=[ @@ -71,7 +73,7 @@ elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3": ], CPPDEFINES=[ - "TIME_T=1423046159" # @TODO + "TIME_T=%d" % time.time() ], LINKFLAGS=[