Add support for Digistump development platform
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
"""
|
||||
Builder for Digistump 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("mcu") != "cortex-m3":
|
||||
env.Replace(
|
||||
AR="avr-ar",
|
||||
AS="avr-gcc",
|
||||
CC="avr-gcc",
|
||||
CXX="avr-g++",
|
||||
OBJCOPY="avr-objcopy",
|
||||
RANLIB="avr-ranlib",
|
||||
SIZETOOL="avr-size",
|
||||
|
||||
ARFLAGS=["rcs"],
|
||||
|
||||
CPPFLAGS=[
|
||||
"-mmcu=$BOARD_MCU"
|
||||
],
|
||||
|
||||
LINKFLAGS=[
|
||||
"-mmcu=$BOARD_MCU"
|
||||
],
|
||||
|
||||
SIZEPRINTCMD='"$SIZETOOL" --mcu=$BOARD_MCU -C -d $SOURCES'
|
||||
)
|
||||
|
||||
else:
|
||||
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",
|
||||
SIZETOOL="arm-none-eabi-size",
|
||||
|
||||
ARFLAGS=["rcs"],
|
||||
|
||||
ASFLAGS=[
|
||||
"-mcpu=${BOARD_OPTIONS['build']['mcu']}",
|
||||
"-mthumb"
|
||||
# "-nostdlib"
|
||||
],
|
||||
|
||||
CXXFLAGS=[
|
||||
"-fno-rtti",
|
||||
],
|
||||
|
||||
CPPFLAGS=[
|
||||
"-mcpu=${BOARD_OPTIONS['build']['mcu']}",
|
||||
"-mthumb",
|
||||
"-ffunction-sections", # place each function in its own section
|
||||
"-fdata-sections"
|
||||
# "-nostdlib"
|
||||
],
|
||||
|
||||
CPPDEFINES=[
|
||||
"printf=iprintf"
|
||||
],
|
||||
|
||||
LINKFLAGS=[
|
||||
"-mcpu=cortex-m3",
|
||||
"-mthumb",
|
||||
"-Wl,--gc-sections",
|
||||
"-Wl,--entry=Reset_Handler"
|
||||
# "-nostartfiles",
|
||||
# "-nostdlib",
|
||||
],
|
||||
|
||||
SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES'
|
||||
)
|
||||
|
||||
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"
|
||||
],
|
||||
|
||||
CXXFLAGS=[
|
||||
"-felide-constructors",
|
||||
"-fno-exceptions"
|
||||
],
|
||||
|
||||
LINKFLAGS=[
|
||||
"-Os",
|
||||
"-Wl,--start-group"
|
||||
|
||||
]
|
||||
)
|
||||
|
||||
if env.get("BOARD_OPTIONS", {}).get("build", {}).get("mcu") == "cortex-m3":
|
||||
env.Append(
|
||||
UPLOADER=join("$PIOPACKAGES_DIR", "$PIOPACKAGE_UPLOADER", "bossac"),
|
||||
UPLOADERFLAGS=[
|
||||
"--info",
|
||||
"--debug",
|
||||
"--port", "$UPLOAD_PORT",
|
||||
"--erase",
|
||||
"--write",
|
||||
"--verify",
|
||||
"--boot"
|
||||
],
|
||||
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
|
||||
)
|
||||
else:
|
||||
env.Append(
|
||||
UPLOADER=join("$PIOPACKAGES_DIR", "tool-avrdude", "avrdude"),
|
||||
UPLOADERFLAGS=[
|
||||
"-q", # suppress progress output
|
||||
"-D", # disable auto erase for flash memory
|
||||
"-p", "$BOARD_MCU",
|
||||
"-C", '"%s"' % join("$PIOPACKAGES_DIR",
|
||||
"tool-avrdude", "avrdude.conf"),
|
||||
"-c", "$UPLOAD_PROTOCOL",
|
||||
"-b", "$UPLOAD_SPEED",
|
||||
"-P", "$UPLOAD_PORT"
|
||||
],
|
||||
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS -U flash:w:$SOURCES:i'
|
||||
)
|
||||
|
||||
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: Print binary size
|
||||
#
|
||||
|
||||
target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
|
||||
AlwaysBuild(target_size)
|
||||
|
||||
#
|
||||
# Target: Upload by default .hex file
|
||||
#
|
||||
|
||||
upload = env.Alias(["upload", "uploadlazy"], target_hex, ("$UPLOADCMD"))
|
||||
AlwaysBuild(upload)
|
||||
|
||||
#
|
||||
# Target: Define targets
|
||||
#
|
||||
|
||||
Default([target_hex, target_size])
|
||||
@@ -5,7 +5,7 @@
|
||||
Build script for Arduino Framework (based on Wiring).
|
||||
"""
|
||||
|
||||
from os import listdir
|
||||
from os import listdir, walk
|
||||
from os.path import isfile, join
|
||||
|
||||
from SCons.Script import Import, Return
|
||||
@@ -13,37 +13,89 @@ from SCons.Script import Import, Return
|
||||
env = None
|
||||
Import("env")
|
||||
|
||||
env.Replace(
|
||||
PLATFORMFW_DIR=join(
|
||||
BOARD_OPTS = env.get("BOARD_OPTIONS", {})
|
||||
BOARD_BUILDOPTS = BOARD_OPTS.get("build", {})
|
||||
|
||||
#
|
||||
# Determine framework directory
|
||||
# based on development platform
|
||||
#
|
||||
|
||||
PLATFORMFW_DIR = join("$PIOPACKAGES_DIR",
|
||||
"framework-arduino${PLATFORM.replace('atmel', '')}")
|
||||
|
||||
if env.get("PLATFORM") == "digistump":
|
||||
PLATFORMFW_DIR = join(
|
||||
"$PIOPACKAGES_DIR",
|
||||
"framework-arduino${PLATFORM.replace('atmel', '')}")
|
||||
"framework-arduino%s" % (
|
||||
"sam" if BOARD_BUILDOPTS.get("mcu") == "cortex-m3" else "avr")
|
||||
)
|
||||
|
||||
env.Replace(PLATFORMFW_DIR=PLATFORMFW_DIR)
|
||||
|
||||
#
|
||||
# Base
|
||||
#
|
||||
|
||||
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("PLATFORM") == "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")
|
||||
]
|
||||
)
|
||||
|
||||
BOARD_BUILDOPTS = env.get("BOARD_OPTIONS", {}).get("build", {})
|
||||
|
||||
|
||||
#
|
||||
# Atmel SAM platform
|
||||
#
|
||||
|
||||
if env.get("BOARD_OPTIONS", {}).get("platform", None) == "atmelsam":
|
||||
if env.subst("${PLATFORMFW_DIR}")[-3:] == "sam":
|
||||
env.VariantDir(
|
||||
join("$BUILD_DIR", "FrameworkCMSISInc"),
|
||||
join("$PLATFORMFW_DIR", "system", "CMSIS", "CMSIS", "include")
|
||||
)
|
||||
env.VariantDir(
|
||||
join("$BUILD_DIR", "FrameworkLibSamInc"),
|
||||
join("$PLATFORMFW_DIR", "system", "libsam")
|
||||
)
|
||||
env.VariantDir(
|
||||
join("$BUILD_DIR", "FrameworkDeviceInc"),
|
||||
join("$PLATFORMFW_DIR", "system", "CMSIS", "Device", "ATMEL")
|
||||
)
|
||||
env.VariantDir(
|
||||
join("$BUILD_DIR", "FrameworkLibSam"),
|
||||
join("$PLATFORMFW_DIR", "system", "libsam")
|
||||
)
|
||||
|
||||
env.VariantDir(
|
||||
join("$BUILD_DIR", "FrameworkArduinoInc"),
|
||||
join("$PLATFORMFW_DIR", "cores", "digix")
|
||||
)
|
||||
env.Append(
|
||||
CPPPATH=[
|
||||
join("$BUILD_DIR", "FrameworkCMSISInc"),
|
||||
join("$BUILD_DIR", "FrameworkLibSamInc"),
|
||||
join("$BUILD_DIR", "FrameworkDeviceInc")
|
||||
join("$BUILD_DIR", "FrameworkLibSam"),
|
||||
join("$BUILD_DIR", "FrameworkLibSam", "include"),
|
||||
join("$BUILD_DIR", "FrameworkDeviceInc"),
|
||||
join("$BUILD_DIR", "FrameworkDeviceInc", "sam3xa", "include")
|
||||
]
|
||||
)
|
||||
env.Append(
|
||||
@@ -53,6 +105,25 @@ if env.get("BOARD_OPTIONS", {}).get("platform", None) == "atmelsam":
|
||||
]
|
||||
)
|
||||
|
||||
# search relative includes in lib SAM directories
|
||||
core_dir = join(env.subst("$PLATFORMFW_DIR"), "system", "libsam")
|
||||
for root, _, files in walk(core_dir):
|
||||
for lib_file in files:
|
||||
file_path = join(root, lib_file)
|
||||
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)
|
||||
|
||||
#
|
||||
# Teensy platform
|
||||
#
|
||||
@@ -79,60 +150,39 @@ if BOARD_BUILDOPTS.get("core", None) == "teensy":
|
||||
fp.write(content)
|
||||
|
||||
#
|
||||
# Miscellaneous
|
||||
# Target: Build Core Library
|
||||
#
|
||||
|
||||
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")
|
||||
]
|
||||
)
|
||||
libs = []
|
||||
|
||||
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")
|
||||
]
|
||||
)
|
||||
libs.append(env.BuildLibrary(
|
||||
join("$BUILD_DIR", "FrameworkArduinoVariant"),
|
||||
join("$PLATFORMFW_DIR", "variants",
|
||||
"${BOARD_OPTIONS['build']['variant']}")
|
||||
))
|
||||
|
||||
#
|
||||
# Target: Build Core Library
|
||||
#
|
||||
|
||||
libs = []
|
||||
|
||||
libs.append(env.BuildLibrary(
|
||||
envsafe = env.Clone()
|
||||
libs.append(envsafe.BuildLibrary(
|
||||
join("$BUILD_DIR", "FrameworkArduino"),
|
||||
join("$PLATFORMFW_DIR", "cores", "${BOARD_OPTIONS['build']['core']}")
|
||||
))
|
||||
|
||||
if env.subst("${PLATFORMFW_DIR}")[-3:] == "sam":
|
||||
envsafe.Append(
|
||||
CFLAGS=[
|
||||
"-std=gnu99"
|
||||
]
|
||||
)
|
||||
libs.append(envsafe.BuildLibrary(
|
||||
join("$BUILD_DIR", "SamLib"),
|
||||
join("$PLATFORMFW_DIR", "system", "libsam", "source")
|
||||
))
|
||||
|
||||
Return("env libs")
|
||||
|
||||
Reference in New Issue
Block a user