Initial support for Teensy 3

This commit is contained in:
Valeriy Koval
2015-02-04 20:39:38 +02:00
parent 9a221085d4
commit 2ab49d7f24
3 changed files with 295 additions and 0 deletions

View File

@ -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
}
}
}

View File

@ -0,0 +1,205 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# 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)

View File

@ -0,0 +1,25 @@
# Copyright (C) Ivan Kravets <me@ikravets.com>
# 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
}
}