mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Merge branch 'feature/teensy' into develop
This commit is contained in:
61
platformio/boards/teensy.json
Normal file
61
platformio/boards/teensy.json
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"teensy20": {
|
||||||
|
"build": {
|
||||||
|
"core": "teensy",
|
||||||
|
"f_cpu": "16000000L",
|
||||||
|
"mcu": "atmega32u4"
|
||||||
|
},
|
||||||
|
"name": "Teensy 2.0",
|
||||||
|
"platform": "teensy",
|
||||||
|
"upload": {
|
||||||
|
"maximum_ram_size": 2560,
|
||||||
|
"maximum_size": 32256
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"teensy20pp": {
|
||||||
|
"build": {
|
||||||
|
"core": "teensy",
|
||||||
|
"f_cpu": "16000000L",
|
||||||
|
"mcu": "at90usb1286"
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"name": "Teensy 3.1",
|
||||||
|
"platform": "teensy",
|
||||||
|
"upload": {
|
||||||
|
"maximum_ram_size": 65536,
|
||||||
|
"maximum_size": 262144
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,49 +5,19 @@
|
|||||||
Build script for Arduino Framework (based on Wiring).
|
Build script for Arduino 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(
|
|
||||||
open(join(env.subst("$PLATFORMFW_DIR"),
|
|
||||||
"version.txt")).read().replace(".", "").strip())
|
|
||||||
|
|
||||||
# usb flags
|
#
|
||||||
ARDUINO_USBDEFINES = []
|
# Atmel SAM platform
|
||||||
if "usb_product" in env.subst("${BOARD_OPTIONS['build']}"):
|
#
|
||||||
ARDUINO_USBDEFINES = [
|
|
||||||
"USB_VID=${BOARD_OPTIONS['build']['vid']}",
|
|
||||||
"USB_PID=${BOARD_OPTIONS['build']['pid']}",
|
|
||||||
'USB_PRODUCT=\\"%s\\"' % (env.subst(
|
|
||||||
"${BOARD_OPTIONS['build']['usb_product']}").replace('"', ""))
|
|
||||||
]
|
|
||||||
|
|
||||||
env.Append(
|
|
||||||
CPPDEFINES=[
|
|
||||||
"ARDUINO=%d" % ARDUINO_VERSION
|
|
||||||
] + ARDUINO_USBDEFINES,
|
|
||||||
|
|
||||||
CPPPATH=[
|
|
||||||
join("$BUILD_DIR", "FrameworkArduino")
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
# include board variant
|
|
||||||
if "variant" in env.get("BOARD_OPTIONS", {}).get("build", {}):
|
|
||||||
env.VariantDir(
|
|
||||||
join("$BUILD_DIR", "FrameworkArduinoVariant"),
|
|
||||||
join("$PLATFORMFW_DIR", "variants",
|
|
||||||
"${BOARD_OPTIONS['build']['variant']}")
|
|
||||||
)
|
|
||||||
env.Append(
|
|
||||||
CPPPATH=[
|
|
||||||
join("$BUILD_DIR", "FrameworkArduinoVariant")
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
if env.get("BOARD_OPTIONS", {}).get("platform", None) == "sam":
|
if env.get("BOARD_OPTIONS", {}).get("platform", None) == "sam":
|
||||||
env.VariantDir(
|
env.VariantDir(
|
||||||
@ -76,6 +46,77 @@ if env.get("BOARD_OPTIONS", {}).get("platform", None) == "sam":
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Teensy platform
|
||||||
|
#
|
||||||
|
|
||||||
|
# Teensy 2.x Core
|
||||||
|
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)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Miscellaneous
|
||||||
|
#
|
||||||
|
|
||||||
|
ARDUINO_VERSION = int(
|
||||||
|
open(join(env.subst("$PLATFORMFW_DIR"),
|
||||||
|
"version.txt")).read().replace(".", "").strip())
|
||||||
|
|
||||||
|
# usb flags
|
||||||
|
ARDUINO_USBDEFINES = []
|
||||||
|
if "usb_product" in BOARD_BUILDOPTS:
|
||||||
|
ARDUINO_USBDEFINES = [
|
||||||
|
"USB_VID=${BOARD_OPTIONS['build']['vid']}",
|
||||||
|
"USB_PID=${BOARD_OPTIONS['build']['pid']}",
|
||||||
|
'USB_PRODUCT=\\"%s\\"' % (env.subst(
|
||||||
|
"${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_USBDEFINES,
|
||||||
|
|
||||||
|
CPPPATH=[
|
||||||
|
join("$BUILD_DIR", "FrameworkArduino")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
if "variant" in BOARD_BUILDOPTS:
|
||||||
|
env.VariantDir(
|
||||||
|
join("$BUILD_DIR", "FrameworkArduinoVariant"),
|
||||||
|
join("$PLATFORMFW_DIR", "variants",
|
||||||
|
"${BOARD_OPTIONS['build']['variant']}")
|
||||||
|
)
|
||||||
|
env.Append(
|
||||||
|
CPPPATH=[
|
||||||
|
join("$BUILD_DIR", "FrameworkArduinoVariant")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Target: Build Core Library
|
# Target: Build Core Library
|
||||||
#
|
#
|
||||||
|
@ -9,7 +9,6 @@ from os.path import join
|
|||||||
|
|
||||||
from SCons.Script import Import, Return
|
from SCons.Script import Import, Return
|
||||||
|
|
||||||
|
|
||||||
env = None
|
env = None
|
||||||
Import("env")
|
Import("env")
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ from SCons.Script import Import, Return
|
|||||||
|
|
||||||
from platformio.util import exec_command
|
from platformio.util import exec_command
|
||||||
|
|
||||||
|
|
||||||
env = None
|
env = None
|
||||||
Import("env")
|
Import("env")
|
||||||
BOARD_BUILDOPTS = env.get("BOARD_OPTIONS", {}).get("build", {})
|
BOARD_BUILDOPTS = env.get("BOARD_OPTIONS", {}).get("build", {})
|
||||||
|
@ -9,7 +9,6 @@ from os.path import join
|
|||||||
|
|
||||||
from SCons.Script import Import, Return
|
from SCons.Script import Import, Return
|
||||||
|
|
||||||
|
|
||||||
env = None
|
env = None
|
||||||
Import("env")
|
Import("env")
|
||||||
|
|
||||||
|
189
platformio/builder/scripts/teensy.py
Normal file
189
platformio/builder/scripts/teensy.py
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
|
# See LICENSE for details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
|
||||||
|
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=-%d" % randint(1000000000, 2000000000)
|
||||||
|
],
|
||||||
|
|
||||||
|
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=%d" % time.time()
|
||||||
|
],
|
||||||
|
|
||||||
|
LINKFLAGS=[
|
||||||
|
"-mcpu=cortex-m4",
|
||||||
|
"-mthumb",
|
||||||
|
"-Wl,--gc-sections",
|
||||||
|
# "-nostartfiles",
|
||||||
|
# "-nostdlib",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
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",
|
||||||
|
"LAYOUT_US_ENGLISH"
|
||||||
|
],
|
||||||
|
|
||||||
|
CXXFLAGS=[
|
||||||
|
"-felide-constructors",
|
||||||
|
"-fno-exceptions"
|
||||||
|
],
|
||||||
|
|
||||||
|
LINKFLAGS=[
|
||||||
|
"-Os"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
#
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Target: Upload by default .hex file
|
||||||
|
#
|
||||||
|
|
||||||
|
upload = env.Alias(["upload", "uploadlazy"], target_hex, ("$UPLOADHEXCMD"))
|
||||||
|
AlwaysBuild(upload)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Target: Define targets
|
||||||
|
#
|
||||||
|
|
||||||
|
Default(target_hex)
|
47
platformio/platforms/teensy.py
Normal file
47
platformio/platforms/teensy.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||||
|
# See LICENSE for details.
|
||||||
|
|
||||||
|
from platformio.platforms.base import BasePlatform
|
||||||
|
from platformio.util import get_boards
|
||||||
|
|
||||||
|
|
||||||
|
class TeensyPlatform(BasePlatform):
|
||||||
|
|
||||||
|
"""
|
||||||
|
An embedded platform for Teensy boards
|
||||||
|
(with Arduino Framework)
|
||||||
|
"""
|
||||||
|
|
||||||
|
PACKAGES = {
|
||||||
|
|
||||||
|
"toolchain-atmelavr": {
|
||||||
|
"default": True
|
||||||
|
},
|
||||||
|
|
||||||
|
"toolchain-gccarmnoneeabi": {
|
||||||
|
"default": True
|
||||||
|
},
|
||||||
|
|
||||||
|
"ldscripts": {
|
||||||
|
"default": True
|
||||||
|
},
|
||||||
|
|
||||||
|
"framework-arduinoteensy": {
|
||||||
|
"alias": "framework",
|
||||||
|
"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)
|
Reference in New Issue
Block a user