Move boards and platforms to separate repos // Issue #479

This commit is contained in:
Ivan Kravets committed 2016-05-23 22:28:48 +03:00
1 parent b3d27b42ad
commit 349b159a7b
77 files changed
-10172

No files matched your search

-13
View File
@@ -1,13 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-168
View File
@@ -1,168 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Atmel AVR series of microcontrollers
"""
from os.path import join
from time import sleep
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
from platformio.util import get_serialports
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
if "program" in COMMAND_LINE_TARGETS:
return
if "micronucleus" in env['UPLOADER']:
print "Please unplug/plug device ..."
upload_options = env.get("BOARD_OPTIONS", {}).get("upload", {})
# Deprecated: compatibility with old projects. Use `program` instead
if "usb" in env.subst("$UPLOAD_PROTOCOL"):
upload_options['require_upload_port'] = False
env.Replace(UPLOAD_SPEED=None)
if env.subst("$UPLOAD_SPEED"):
env.Append(UPLOADERFLAGS=["-b", "$UPLOAD_SPEED"])
if upload_options and not upload_options.get("require_upload_port", False):
return
env.AutodetectUploadPort()
env.Append(UPLOADERFLAGS=["-P", '"$UPLOAD_PORT"'])
if env.subst("$BOARD") == "raspduino":
def _rpi_sysgpio(path, value):
with open(path, "w") as f:
f.write(str(value))
_rpi_sysgpio("/sys/class/gpio/export", 18)
_rpi_sysgpio("/sys/class/gpio/gpio18/direction", "out")
_rpi_sysgpio("/sys/class/gpio/gpio18/value", 1)
sleep(0.1)
_rpi_sysgpio("/sys/class/gpio/gpio18/value", 0)
_rpi_sysgpio("/sys/class/gpio/unexport", 18)
else:
if not upload_options.get("disable_flushing", False):
env.FlushSerialBuffer("$UPLOAD_PORT")
before_ports = [i['port'] for i in get_serialports()]
if upload_options.get("use_1200bps_touch", False):
env.TouchSerialPort("$UPLOAD_PORT", 1200)
if upload_options.get("wait_for_upload_port", False):
env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports))
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "baseavr.py")))
env.Append(
CFLAGS=[
"-std=gnu11"
],
CXXFLAGS=[
"-std=gnu++11"
]
)
if "digispark" in env.get(
"BOARD_OPTIONS", {}).get("build", {}).get("core", ""):
env.Replace(
UPLOADER=join("$PIOPACKAGES_DIR", "tool-micronucleus", "micronucleus"),
UPLOADERFLAGS=[
"-c", "$UPLOAD_PROTOCOL",
"--timeout", "60"
],
UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
)
else:
env.Replace(
UPLOADER=join("$PIOPACKAGES_DIR", "tool-avrdude", "avrdude"),
UPLOADERFLAGS=[
"-v",
"-p", "$BOARD_MCU",
"-C",
'"%s"' % join("$PIOPACKAGES_DIR", "tool-avrdude", "avrdude.conf"),
"-c", "$UPLOAD_PROTOCOL"
],
UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS -D -U flash:w:$SOURCES:i',
UPLOADEEPCMD='"$UPLOADER" $UPLOADERFLAGS -U eeprom:w:$SOURCES:i',
PROGRAMHEXCMD='"$UPLOADER" $UPLOADERFLAGS -U flash:w:$SOURCES:i'
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .hex file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.hex")
else:
target_firm = 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_firm,
[BeforeUpload, "$UPLOADHEXCMD"])
AlwaysBuild(upload)
#
# Target: Upload EEPROM data (from EEMEM directive)
#
uploadeep = env.Alias(
"uploadeep",
env.ElfToEep(join("$BUILD_DIR", "firmware"), target_elf),
[BeforeUpload, "$UPLOADEEPCMD"])
AlwaysBuild(uploadeep)
#
# Target: Upload firmware using external programmer
#
program = env.Alias("program", target_firm, [BeforeUpload, "$PROGRAMHEXCMD"])
AlwaysBuild(program)
#
# Setup default targets
#
Default([target_firm, target_size])
-189
View File
@@ -1,189 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Atmel SAM series of microcontrollers
"""
from os.path import basename, join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
from platformio.util import get_serialports
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
env.AutodetectUploadPort()
board_type = env.subst("$BOARD")
if "zero" not in board_type:
env.Append(
UPLOADERFLAGS=[
"-U",
"true" if ("usb" in board_type.lower(
) or board_type == "digix") else "false"
])
upload_options = env.get("BOARD_OPTIONS", {}).get("upload", {})
if not upload_options.get("disable_flushing", False):
env.FlushSerialBuffer("$UPLOAD_PORT")
before_ports = [i['port'] for i in get_serialports()]
if upload_options.get("use_1200bps_touch", False):
env.TouchSerialPort("$UPLOAD_PORT", 1200)
if upload_options.get("wait_for_upload_port", False):
env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports))
# use only port name for BOSSA
if "/" in env.subst("$UPLOAD_PORT"):
env.Replace(UPLOAD_PORT=basename(env.subst("$UPLOAD_PORT")))
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
if env.subst("$BOARD") == "zero":
env.Replace(
UPLOADER=join("$PIOPACKAGES_DIR", "tool-openocd", "bin", "openocd"),
UPLOADERFLAGS=[
"-d2",
"-s",
join(
"$PIOPACKAGES_DIR",
"tool-openocd", "share", "openocd", "scripts"),
"-f",
join(
"$PLATFORMFW_DIR", "variants",
"${BOARD_OPTIONS['build']['variant']}", "openocd_scripts",
"${BOARD_OPTIONS['build']['variant']}.cfg"
),
"-c", "\"telnet_port", "disabled;",
"program", "{{$SOURCES}}",
"verify", "reset", "0x00002000;", "shutdown\""
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS'
)
else:
env.Replace(
UPLOADER=join("$PIOPACKAGES_DIR", "$PIOPACKAGE_UPLOADER", "bossac"),
UPLOADERFLAGS=[
"--info",
"--port", '"$UPLOAD_PORT"',
"--erase",
"--write",
"--verify",
"--reset",
"--debug"
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
)
env.Append(
CCFLAGS=[
"--param", "max-inline-insns-single=500",
"-MMD"
],
CFLAGS=[
"-std=gnu11"
],
CXXFLAGS=[
"-std=gnu++11",
"-fno-threadsafe-statics"
],
CPPDEFINES=[
"USBCON",
'USB_MANUFACTURER="PlatformIO"'
],
LINKFLAGS=[
"-Wl,--check-sections",
"-Wl,--unresolved-symbols=report-all",
"-Wl,--warn-common",
"-Wl,--warn-section-align"
]
)
if "sam3x8e" in env.get("BOARD_OPTIONS", {}).get("build", {}).get("mcu", None):
env.Append(
CPPDEFINES=[
"printf=iprintf"
],
LINKFLAGS=[
"-Wl,--entry=Reset_Handler",
"-Wl,--start-group"
],
UPLOADERFLAGS=[
"--boot",
]
)
elif "zero" in env.subst("$BOARD"):
env.Append(
LINKFLAGS=[
"--specs=nosys.specs",
"--specs=nano.specs"
]
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .bin file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.bin")
else:
target_firm = env.ElfToBin(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 .bin file
#
if env.subst("$BOARD") == "zero":
upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADCMD")
else:
upload = env.Alias(["upload", "uploadlazy"], target_firm,
[BeforeUpload, "$UPLOADCMD"])
AlwaysBuild(upload)
#
# Setup default targets
#
Default([target_firm, target_size])
-97
View File
@@ -1,97 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Base for ARM microcontrollers.
"""
from SCons.Script import Builder, DefaultEnvironment
env = DefaultEnvironment()
env.Replace(
AR="arm-none-eabi-ar",
AS="arm-none-eabi-as",
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=["-x", "assembler-with-cpp"],
CCFLAGS=[
"-g", # include debugging info (so errors include line numbers)
"-Os", # optimize for size
"-ffunction-sections", # place each function in its own section
"-fdata-sections",
"-Wall",
"-mthumb",
"-mcpu=${BOARD_OPTIONS['build']['cpu']}",
"-nostdlib"
],
CXXFLAGS=[
"-fno-rtti",
"-fno-exceptions"
],
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU"
],
LINKFLAGS=[
"-Os",
"-Wl,--gc-sections,--relax",
"-mthumb",
"-mcpu=${BOARD_OPTIONS['build']['cpu']}"
],
LIBS=["c", "gcc", "m"],
SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES',
PROGNAME="firmware",
PROGSUFFIX=".elf"
)
env.Append(
ASFLAGS=env.get("CCFLAGS", [])[:],
BUILDERS=dict(
ElfToBin=Builder(
action=" ".join([
"$OBJCOPY",
"-O",
"binary",
"$SOURCES",
"$TARGET"]),
suffix=".bin"
),
ElfToHex=Builder(
action=" ".join([
"$OBJCOPY",
"-O",
"ihex",
"-R",
".eeprom",
"$SOURCES",
"$TARGET"]),
suffix=".hex"
)
)
)
-98
View File
@@ -1,98 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Base for Atmel AVR series of microcontrollers
"""
from SCons.Script import Builder, DefaultEnvironment
env = DefaultEnvironment()
env.Replace(
AR="avr-ar",
AS="avr-as",
CC="avr-gcc",
CXX="avr-g++",
OBJCOPY="avr-objcopy",
RANLIB="avr-ranlib",
SIZETOOL="avr-size",
ARFLAGS=["rcs"],
ASFLAGS=["-x", "assembler-with-cpp"],
CCFLAGS=[
"-g", # include debugging info (so errors include line numbers)
"-Os", # optimize for size
"-Wall", # show warnings
"-ffunction-sections", # place each function in its own section
"-fdata-sections",
"-mmcu=$BOARD_MCU"
],
CXXFLAGS=[
"-fno-exceptions",
"-fno-threadsafe-statics"
],
CPPDEFINES=["F_CPU=$BOARD_F_CPU"],
LINKFLAGS=[
"-Os",
"-mmcu=$BOARD_MCU",
"-Wl,--gc-sections,--relax"
],
LIBS=["m"],
SIZEPRINTCMD='"$SIZETOOL" --mcu=$BOARD_MCU -C -d $SOURCES',
PROGNAME="firmware",
PROGSUFFIX=".elf"
)
env.Append(
ASFLAGS=env.get("CCFLAGS", [])[:],
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"
)
)
)
-357
View File
@@ -1,357 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# pylint: disable=redefined-outer-name
"""
Builder for Espressif MCUs
"""
import re
from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment)
def _get_flash_size(env):
# use board's flash size by default
board_max_size = int(
env.get("BOARD_OPTIONS", {}).get("upload", {}).get("maximum_size", 0))
# check if user overrides LD Script
match = re.search(r"\.flash\.(\d+)(m|k).*\.ld", env.GetActualLDScript())
if match:
if match.group(2) == "k":
board_max_size = int(match.group(1)) * 1024
elif match.group(2) == "m":
board_max_size = int(match.group(1)) * 1024 * 1024
return ("%dK" % (board_max_size / 1024) if board_max_size < 1048576
else "%dM" % (board_max_size / 1048576))
def _get_board_f_flash(env):
frequency = env.subst("$BOARD_F_FLASH")
frequency = str(frequency).replace("L", "")
return int(int(frequency) / 1000000)
env = DefaultEnvironment()
env.Replace(
__get_flash_size=_get_flash_size,
__get_board_f_flash=_get_board_f_flash,
AR="xtensa-lx106-elf-ar",
AS="xtensa-lx106-elf-as",
CC="xtensa-lx106-elf-gcc",
CXX="xtensa-lx106-elf-g++",
OBJCOPY=join("$PIOPACKAGES_DIR", "tool-esptool", "esptool"),
RANLIB="xtensa-lx106-elf-ranlib",
SIZETOOL="xtensa-lx106-elf-size",
ARFLAGS=["rcs"],
ASFLAGS=["-x", "assembler-with-cpp"],
CFLAGS=[
"-std=gnu99",
"-Wpointer-arith",
"-Wno-implicit-function-declaration",
"-Wl,-EL",
"-fno-inline-functions",
"-nostdlib"
],
CCFLAGS=[
"-Os", # optimize for size
"-mlongcalls",
"-mtext-section-literals",
"-falign-functions=4",
"-U__STRICT_ANSI__",
"-ffunction-sections",
"-fdata-sections",
"-MMD" # output dependancy info
],
CXXFLAGS=[
"-fno-rtti",
"-fno-exceptions",
"-std=c++11"
],
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU",
"__ets__",
"ICACHE_FLASH"
],
LINKFLAGS=[
"-Os",
"-nostdlib",
"-Wl,--no-check-sections",
"-u", "call_user_start",
"-Wl,-static",
"-Wl,--gc-sections"
],
#
# Upload
#
UPLOADER=join("$PIOPACKAGES_DIR", "tool-esptool", "esptool"),
UPLOADEROTA=join("$PLATFORMFW_DIR", "tools", "espota.py"),
UPLOADERFLAGS=[
"-vv",
"-cd", "$UPLOAD_RESETMETHOD",
"-cb", "$UPLOAD_SPEED",
"-cp", '"$UPLOAD_PORT"'
],
UPLOADEROTAFLAGS=[
"--debug",
"--progress",
"-i", "$UPLOAD_PORT",
"$UPLOAD_FLAGS"
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS -cf $SOURCE',
UPLOADOTACMD='"$PYTHONEXE" "$UPLOADEROTA" $UPLOADEROTAFLAGS -f $SOURCE',
#
# Misc
#
MKSPIFFSTOOL=join("$PIOPACKAGES_DIR", "tool-mkspiffs", "mkspiffs"),
SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES',
PROGNAME="firmware",
PROGSUFFIX=".elf"
)
env.Append(
ASFLAGS=env.get("CCFLAGS", [])[:],
BUILDERS=dict(
ElfToBin=Builder(
action=" ".join([
'"$OBJCOPY"',
"-eo",
'"%s"' % join("$PLATFORMFW_DIR", "bootloaders",
"eboot", "eboot.elf"),
"-bo", "$TARGET",
"-bm", "$BOARD_FLASH_MODE",
"-bf", "${__get_board_f_flash(__env__)}",
"-bz", "${__get_flash_size(__env__)}",
"-bs", ".text",
"-bp", "4096",
"-ec",
"-eo", "$SOURCES",
"-bs", ".irom0.text",
"-bs", ".text",
"-bs", ".data",
"-bs", ".rodata",
"-bc", "-ec"
]),
suffix=".bin"
)
)
)
#
# SPIFFS
#
def _fetch_spiffs_size(target, source, env):
spiffs_re = re.compile(
r"PROVIDE\s*\(\s*_SPIFFS_(\w+)\s*=\s*(0x[\dA-F]+)\s*\)")
with open(env.GetActualLDScript()) as f:
for line in f.readlines():
match = spiffs_re.search(line)
if not match:
continue
env["SPIFFS_%s" % match.group(1).upper()] = match.group(2)
assert all([k in env for k in ["SPIFFS_START", "SPIFFS_END", "SPIFFS_PAGE",
"SPIFFS_BLOCK"]])
# esptool flash starts from 0
for k in ("SPIFFS_START", "SPIFFS_END"):
_value = 0
if int(env[k], 16) < 0x40300000:
_value = int(env[k], 16) & 0xFFFFF
else:
_value = int(env[k], 16) & 0xFFFFFF
_value -= 0x200000 # esptool offset
env[k] = hex(_value)
return (target, source)
env.Append(
BUILDERS=dict(
DataToBin=Builder(
action=" ".join([
'"$MKSPIFFSTOOL"',
"-c", "$SOURCES",
"-p", "${int(SPIFFS_PAGE, 16)}",
"-b", "${int(SPIFFS_BLOCK, 16)}",
"-s", "${int(SPIFFS_END, 16) - int(SPIFFS_START, 16)}",
"$TARGET"
]),
emitter=_fetch_spiffs_size,
source_factory=env.Dir,
suffix=".bin"
)
)
)
if "uploadfs" in COMMAND_LINE_TARGETS:
env.Append(
UPLOADERFLAGS=["-ca", "$SPIFFS_START"],
UPLOADEROTAFLAGS=["-s"]
)
#
# Framework and SDK specific configuration
#
if "FRAMEWORK" in env:
env.Append(
LINKFLAGS=[
"-Wl,-wrap,system_restart_local",
"-Wl,-wrap,register_chipv6_phy"
]
)
# Handle uploading via OTA
ota_port = None
if env.get("UPLOAD_PORT"):
ota_port = re.match(
r"\"?((([0-9]{1,3}\.){3}[0-9]{1,3})|.+\.local)\"?$",
env.get("UPLOAD_PORT"))
if ota_port:
env.Replace(UPLOADCMD="$UPLOADOTACMD")
# Configure native SDK
else:
env.Append(
CPPPATH=[
join("$PIOPACKAGES_DIR", "sdk-esp8266", "include"),
"$PROJECTSRC_DIR"
],
LIBPATH=[
join("$PIOPACKAGES_DIR", "sdk-esp8266", "lib"),
join("$PIOPACKAGES_DIR", "sdk-esp8266", "ld")
],
BUILDERS=dict(
ElfToBin=Builder(
action=" ".join([
'"$OBJCOPY"',
"-eo", "$SOURCES",
"-bo", "${TARGETS[0]}",
"-bm", "$BOARD_FLASH_MODE",
"-bf", "${__get_board_f_flash(__env__)}",
"-bz", "${__get_flash_size(__env__)}",
"-bs", ".text",
"-bs", ".data",
"-bs", ".rodata",
"-bc", "-ec",
"-eo", "$SOURCES",
"-es", ".irom0.text", "${TARGETS[1]}",
"-ec", "-v"
]),
suffix=".bin"
)
)
)
env.Replace(
LIBS=[
"c", "gcc", "phy", "pp", "net80211", "lwip", "wpa", "wpa2",
"main", "wps", "crypto", "json", "ssl", "pwm", "upgrade",
"smartconfig", "airkiss", "at"
],
UPLOADERFLAGS=[
"-vv",
"-cd", "$UPLOAD_RESETMETHOD",
"-cb", "$UPLOAD_SPEED",
"-cp", '"$UPLOAD_PORT"',
"-ca", "0x00000",
"-cf", "${SOURCES[0]}",
"-ca", "0x40000",
"-cf", "${SOURCES[1]}"
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS',
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .hex or SPIFFS image
#
if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
target_firm = env.DataToBin(
join("$BUILD_DIR", "spiffs"), "$PROJECTDATA_DIR")
AlwaysBuild(target_firm)
elif "uploadlazy" in COMMAND_LINE_TARGETS:
if "FRAMEWORK" not in env:
target_firm = [
join("$BUILD_DIR", "firmware_00000.bin"),
join("$BUILD_DIR", "firmware_40000.bin")
]
else:
target_firm = join("$BUILD_DIR", "firmware.bin")
else:
if "FRAMEWORK" not in env:
target_firm = env.ElfToBin(
[join("$BUILD_DIR", "firmware_00000"),
join("$BUILD_DIR", "firmware_40000")], target_elf)
else:
target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf)
#
# Target: Print binary size
#
target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
AlwaysBuild(target_size)
#
# Target: Upload firmware or SPIFFS image
#
target_upload = env.Alias(
["upload", "uploadlazy", "uploadfs"], target_firm,
[lambda target, source, env: env.AutodetectUploadPort(), "$UPLOADCMD"])
env.AlwaysBuild(target_upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
@@ -1,13 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
@@ -1,339 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Arduino
Arduino Wiring-based Framework allows writing cross-platform software to
control devices attached to a wide range of Arduino boards to create all
kinds of creative coding, interactive objects, spaces or physical experiences.
http://arduino.cc/en/Reference/HomePage
"""
from os import listdir, walk
from os.path import isdir, isfile, join
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
BOARD_OPTS = env.get("BOARD_OPTIONS", {})
BOARD_BUILDOPTS = BOARD_OPTS.get("build", {})
BOARD_CORELIBDIRNAME = BOARD_BUILDOPTS.get("core")
#
# Determine framework directory
# based on development platform
#
PLATFORMFW_DIR = join("$PIOPACKAGES_DIR",
"framework-arduino${PLATFORM.replace('atmel', '')}")
if "digispark" in BOARD_BUILDOPTS.get("core"):
BOARD_CORELIBDIRNAME = "digispark"
PLATFORMFW_DIR = join(
"$PIOPACKAGES_DIR",
"framework-arduino%s" % (
"sam" if BOARD_BUILDOPTS.get("cpu") == "cortex-m3" else "avr")
)
elif env.get("PLATFORM") == "timsp430":
PLATFORMFW_DIR = join(
"$PIOPACKAGES_DIR",
"framework-arduinomsp430"
)
elif env.get("PLATFORM") == "espressif":
env.Prepend(
CPPPATH=[
join("$PLATFORMFW_DIR", "tools", "sdk", "include"),
join("$PLATFORMFW_DIR", "tools", "sdk", "lwip", "include")
],
LIBPATH=[join("$PLATFORMFW_DIR", "tools", "sdk", "lib")],
LIBS=["mesh", "wpa2", "smartconfig", "pp", "main", "wpa", "lwip",
"net80211", "wps", "crypto", "phy", "hal", "axtls", "gcc", "m"]
)
env.VariantDirWrap(
join("$BUILD_DIR", "generic"),
join("$PIOPACKAGES_DIR", "framework-arduinoespressif",
"variants", "generic")
)
elif env.get("PLATFORM") == "nordicnrf51":
PLATFORMFW_DIR = join(
"$PIOPACKAGES_DIR",
"framework-arduinonordicnrf51"
)
env.Prepend(
CPPPATH=[
join("$PLATFORMFW_DIR", "system", "CMSIS", "CMSIS", "Include"),
join("$PLATFORMFW_DIR", "system", "RFduino"),
join("$PLATFORMFW_DIR", "system", "RFduino", "include")
],
LIBPATH=[
join(
"$PLATFORMFW_DIR",
"variants",
"${BOARD_OPTIONS['build']['variant']}"
),
join(
"$PLATFORMFW_DIR",
"variants",
"${BOARD_OPTIONS['build']['variant']}",
"linker_scripts",
"gcc"
),
],
LIBS=["RFduino", "RFduinoBLE", "RFduinoGZLL", "RFduinoSystem"]
)
elif env.get("PLATFORM") == "microchippic32":
PLATFORMFW_DIR = join(
"$PIOPACKAGES_DIR",
"framework-arduinomicrochippic32"
)
env.Prepend(
LIBPATH=[
join(
"$PLATFORMFW_DIR", "cores",
"${BOARD_OPTIONS['build']['core']}"
),
join(
"$PLATFORMFW_DIR", "variants",
"${BOARD_OPTIONS['build']['variant']}"
)
]
)
elif "intel" in env.get("PLATFORM"):
PLATFORMFW_DIR = join(
"$PIOPACKAGES_DIR",
"framework-arduinointel"
)
if BOARD_CORELIBDIRNAME == "arc32":
env.Prepend(
CPPPATH=[
join("$PLATFORMFW_DIR", "system",
"libarc32_arduino101", "drivers"),
join("$PLATFORMFW_DIR", "system",
"libarc32_arduino101", "common"),
join("$PLATFORMFW_DIR", "system",
"libarc32_arduino101", "framework", "include"),
join("$PLATFORMFW_DIR", "system",
"libarc32_arduino101", "bootcode"),
join("$BUILD_DIR", "IntelDrivers")
]
)
env.Prepend(
LIBPATH=[
join(
"$PLATFORMFW_DIR", "variants",
"${BOARD_OPTIONS['build']['variant']}"
),
join(
"$PLATFORMFW_DIR", "variants",
"${BOARD_OPTIONS['build']['variant']}",
"linker_scripts"
)
]
)
env.Replace(PLATFORMFW_DIR=PLATFORMFW_DIR)
#
# Lookup for specific core's libraries
#
if isdir(join(env.subst("$PLATFORMFW_DIR"), "libraries", "__cores__",
BOARD_CORELIBDIRNAME)):
lib_dirs = env.get("LIBSOURCE_DIRS")
lib_dirs.insert(
lib_dirs.index(join("$PLATFORMFW_DIR", "libraries")),
join(PLATFORMFW_DIR, "libraries", "__cores__", BOARD_CORELIBDIRNAME)
)
env.Replace(
LIBSOURCE_DIRS=lib_dirs
)
#
# 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']['hwid'][0][0]}",
"USB_PID=${BOARD_OPTIONS['build']['hwid'][0][1]}",
'USB_PRODUCT=\\"%s\\"' % (env.subst(
"${BOARD_OPTIONS['build']['usb_product']}").replace('"', "")),
'USB_MANUFACTURER=\\"%s\\"' % (env.subst(
"${BOARD_OPTIONS['vendor']}").replace('"', ""))
]
if env.get("PLATFORM") == "teensy":
ARDUINO_USBDEFINES += [
"ARDUINO=10600",
"TEENSYDUINO=%d" % ARDUINO_VERSION
]
else:
ARDUINO_USBDEFINES += ["ARDUINO=%d" % ARDUINO_VERSION]
env.Append(
CPPDEFINES=ARDUINO_USBDEFINES,
CPPPATH=[
join("$BUILD_DIR", "FrameworkArduino")
]
)
#
# Atmel SAM platform
#
if env.subst("${PLATFORMFW_DIR}")[-3:] == "sam":
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkCMSISInc"),
join("$PLATFORMFW_DIR", "system", "CMSIS", "CMSIS", "Include")
)
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkDeviceInc"),
join("$PLATFORMFW_DIR", "system", "CMSIS", "Device", "ATMEL")
)
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkLibSam"),
join("$PLATFORMFW_DIR", "system", "libsam")
)
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkArduinoInc"),
join("$PLATFORMFW_DIR", "cores", "${BOARD_OPTIONS['build']['core']}")
)
env.Append(
CPPPATH=[
join("$BUILD_DIR", "FrameworkCMSISInc"),
join("$BUILD_DIR", "FrameworkLibSam"),
join("$BUILD_DIR", "FrameworkLibSam", "include"),
join("$BUILD_DIR", "FrameworkDeviceInc"),
join(
"$BUILD_DIR",
"FrameworkDeviceInc",
"${BOARD_OPTIONS['build']['mcu'][3:]}",
"include"
)
],
LIBPATH=[
join(
"$PLATFORMFW_DIR",
"variants",
"${BOARD_OPTIONS['build']['variant']}",
"linker_scripts",
"gcc"
)
]
)
# 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
#
# 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 sorted(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
#
libs = []
if "variant" in BOARD_BUILDOPTS:
env.Append(
CPPPATH=[
join("$BUILD_DIR", "FrameworkArduinoVariant")
]
)
libs.append(env.BuildLibrary(
join("$BUILD_DIR", "FrameworkArduinoVariant"),
join("$PLATFORMFW_DIR", "variants",
"${BOARD_OPTIONS['build']['variant']}")
))
envsafe = env.Clone()
if BOARD_BUILDOPTS.get("core", None) == "teensy3":
libs.append("arm_cortex%sl_math" % (
"M4" if BOARD_BUILDOPTS.get("cpu") == "cortex-m4" else "M0"))
if env.subst("$BOARD") == "genuino101":
libs.append("libarc32drv_arduino101")
libs.append(envsafe.BuildLibrary(
join("$BUILD_DIR", "FrameworkArduino"),
join("$PLATFORMFW_DIR", "cores", "${BOARD_OPTIONS['build']['core']}")
))
if "sam3x8e" in BOARD_BUILDOPTS.get("mcu", ""):
env.Append(
LIBPATH=[
join("$PLATFORMFW_DIR", "variants",
"${BOARD_OPTIONS['build']['variant']}")
]
)
libs.append("sam_sam3x8e_gcc_rel")
env.Prepend(LIBS=libs)
@@ -1,93 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
CMSIS
The ARM Cortex Microcontroller Software Interface Standard (CMSIS) is a
vendor-independent hardware abstraction layer for the Cortex-M processor
series and specifies debugger interfaces. The CMSIS enables consistent and
simple software interfaces to the processor for interface peripherals,
real-time operating systems, and middleware. It simplifies software
re-use, reducing the learning curve for new microcontroller developers
and cutting the time-to-market for devices.
http://www.arm.com/products/processors/cortex-m/cortex-microcontroller-software-interface-standard.php
"""
from os.path import isfile, join
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Replace(
PLATFORMFW_DIR=join("$PIOPACKAGES_DIR", "framework-cmsis")
)
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkCMSIS"),
join("$PLATFORMFW_DIR", "cores", "${BOARD_OPTIONS['build']['core']}")
)
env.Append(
CPPPATH=[
join("$BUILD_DIR", "FrameworkCMSIS"),
join("$BUILD_DIR", "FrameworkCMSISCommon"),
join("$BUILD_DIR", "FrameworkCMSISVariant")
]
)
envsafe = env.Clone()
#
# Target: Build Core Library
#
# use mbed ldscript with bootloader section
ldscript = env.get("BOARD_OPTIONS", {}).get("build", {}).get("ldscript")
if not isfile(join(env.subst("$PIOPACKAGES_DIR"), "ldscripts", ldscript)):
if "mbed" in env.get("BOARD_OPTIONS", {}).get("frameworks", {}):
env.Append(
LINKFLAGS=[
'-Wl,-T"%s"' %
join(
"$PIOPACKAGES_DIR", "framework-mbed", "variant",
env.subst("$BOARD").upper(), "mbed",
"TARGET_%s" % env.subst(
"$BOARD").upper(), "TOOLCHAIN_GCC_ARM",
"%s.ld" % ldscript.upper()[:-3]
)
]
)
libs = []
libs.append(envsafe.BuildLibrary(
join("$BUILD_DIR", "FrameworkCMSISVariant"),
join(
"$PLATFORMFW_DIR", "variants",
env.subst("${BOARD_OPTIONS['build']['variant']}")[0:7],
"${BOARD_OPTIONS['build']['variant']}"
)
))
libs.append(envsafe.BuildLibrary(
join("$BUILD_DIR", "FrameworkCMSISCommon"),
join(
"$PLATFORMFW_DIR", "variants",
env.subst("${BOARD_OPTIONS['build']['variant']}")[0:7], "common"
)
))
env.Append(LIBS=libs)
@@ -1,74 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Energia
Energia Wiring-based framework enables pretty much anyone to start easily
creating microcontroller-based projects and applications. Its easy-to-use
libraries and functions provide developers of all experience levels to start
blinking LEDs, buzzing buzzers and sensing sensors more quickly than ever
before.
http://energia.nu/reference/
"""
from os.path import join
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Replace(
PLATFORMFW_DIR=join("$PIOPACKAGES_DIR", "framework-energia${PLATFORM[2:]}")
)
ENERGIA_VERSION = int(
open(join(env.subst("$PLATFORMFW_DIR"),
"version.txt")).read().replace(".", "").strip())
# include board variant
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkEnergiaVariant"),
join("$PLATFORMFW_DIR", "variants", "${BOARD_OPTIONS['build']['variant']}")
)
env.Append(
CPPDEFINES=[
"ARDUINO=101",
"ENERGIA=%d" % ENERGIA_VERSION
],
CPPPATH=[
join("$BUILD_DIR", "FrameworkEnergia"),
join("$BUILD_DIR", "FrameworkEnergiaVariant")
]
)
if env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "lm4f":
env.Append(
LINKFLAGS=["-Wl,--entry=ResetISR"]
)
#
# Target: Build Core Library
#
libs = []
libs.append(env.BuildLibrary(
join("$BUILD_DIR", "FrameworkEnergia"),
join("$PLATFORMFW_DIR", "cores", "${BOARD_OPTIONS['build']['core']}")
))
env.Append(LIBS=libs)
@@ -1,191 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
libOpenCM3
The libOpenCM3 framework aims to create a free/libre/open-source
firmware library for various ARM Cortex-M0(+)/M3/M4 microcontrollers,
including ST STM32, Ti Tiva and Stellaris, NXP LPC 11xx, 13xx, 15xx,
17xx parts, Atmel SAM3, Energy Micro EFM32 and others.
http://www.libopencm3.org/wiki/Main_Page
"""
from __future__ import absolute_import
import re
from os import listdir, sep, walk
from os.path import isfile, join, normpath
from SCons.Script import DefaultEnvironment
from platformio.util import exec_command
env = DefaultEnvironment()
env.Replace(
PLATFORMFW_DIR=join("$PIOPACKAGES_DIR", "framework-libopencm3")
)
BOARD_BUILDOPTS = env.get("BOARD_OPTIONS", {}).get("build", {})
def find_ldscript(src_dir):
ldscript = None
matches = []
for item in sorted(listdir(src_dir)):
_path = join(src_dir, item)
if not isfile(_path) or not item.endswith(".ld"):
continue
matches.append(_path)
if len(matches) == 1:
ldscript = matches[0]
elif isfile(join(src_dir, BOARD_BUILDOPTS['ldscript'])):
ldscript = join(src_dir, BOARD_BUILDOPTS['ldscript'])
return ldscript
def generate_nvic_files():
fw_dir = env.subst("$PLATFORMFW_DIR")
for root, _, files in walk(join(fw_dir, "include", "libopencm3")):
if "irq.json" not in files or isfile(join(root, "nvic.h")):
continue
exec_command(
["python", join("scripts", "irq2nvic_h"),
join("." + root.replace(fw_dir, ""),
"irq.json").replace("\\", "/")],
cwd=fw_dir
)
def parse_makefile_data(makefile):
data = {"includes": [], "objs": [], "vpath": ["./"]}
with open(makefile) as f:
content = f.read()
# fetch "includes"
re_include = re.compile(r"^include\s+([^\r\n]+)", re.M)
for match in re_include.finditer(content):
data['includes'].append(match.group(1))
# fetch "vpath"s
re_vpath = re.compile(r"^VPATH\s+\+?=\s+([^\r\n]+)", re.M)
for match in re_vpath.finditer(content):
data['vpath'] += match.group(1).split(":")
# fetch obj files
objs_match = re.search(
r"^OBJS\s+\+?=\s+([^\.]+\.o\s*(?:\s+\\s+)?)+", content, re.M)
assert objs_match
data['objs'] = re.sub(
r"(OBJS|[\+=\\\s]+)", "\n", objs_match.group(0)).split()
return data
def get_source_files(src_dir):
mkdata = parse_makefile_data(join(src_dir, "Makefile"))
for include in mkdata['includes']:
_mkdata = parse_makefile_data(normpath(join(src_dir, include)))
for key, value in _mkdata.iteritems():
for v in value:
if v not in mkdata[key]:
mkdata[key].append(v)
sources = []
lib_root = env.subst("$PLATFORMFW_DIR")
for obj_file in mkdata['objs']:
src_file = obj_file[:-1] + "c"
for search_path in mkdata['vpath']:
src_path = normpath(join(src_dir, search_path, src_file))
if isfile(src_path):
sources.append(join("$BUILD_DIR", "FrameworkLibOpenCM3",
src_path.replace(lib_root + sep, "")))
break
return sources
def merge_ld_scripts(main_ld_file):
def _include_callback(match):
included_ld_file = match.group(1)
# search included ld file in lib directories
for root, _, files in walk(env.subst(join("$PLATFORMFW_DIR", "lib"))):
if included_ld_file not in files:
continue
with open(join(root, included_ld_file)) as fp:
return fp.read()
return match.group(0)
content = ""
with open(main_ld_file) as f:
content = f.read()
incre = re.compile(r"^INCLUDE\s+\"?([^\.]+\.ld)\"?", re.M)
with open(main_ld_file, "w") as f:
f.write(incre.sub(_include_callback, content))
#
# Processing ...
#
if BOARD_BUILDOPTS.get("core") == "lm4f":
env.Append(
CPPDEFINES=["LM4F"]
)
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkLibOpenCM3Variant"),
join("$PLATFORMFW_DIR", "include")
)
env.Append(
CPPPATH=[
join("$BUILD_DIR", "FrameworkLibOpenCM3"),
join("$BUILD_DIR", "FrameworkLibOpenCM3Variant")
]
)
root_dir = env.subst(
join("$PLATFORMFW_DIR", "lib", BOARD_BUILDOPTS.get("core")))
if BOARD_BUILDOPTS.get("core") == "stm32":
root_dir = join(root_dir, BOARD_BUILDOPTS.get("variant")[5:7])
ldscript_path = find_ldscript(root_dir)
if ldscript_path:
merge_ld_scripts(ldscript_path)
generate_nvic_files()
# override ldscript by libopencm3
assert "LDSCRIPT_PATH" in env
env.Replace(
LDSCRIPT_PATH=ldscript_path
)
libs = []
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkLibOpenCM3"),
"$PLATFORMFW_DIR"
)
libs.append(env.Library(
join("$BUILD_DIR", "FrameworkLibOpenCM3"),
get_source_files(root_dir)
))
env.Append(LIBS=libs)
@@ -1,289 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
mbed
The mbed framework The mbed SDK has been designed to provide enough
hardware abstraction to be intuitive and concise, yet powerful enough to
build complex projects. It is built on the low-level ARM CMSIS APIs,
allowing you to code down to the metal if needed. In addition to RTOS,
USB and Networking libraries, a cookbook of hundreds of reusable
peripheral and module libraries have been built on top of the SDK by
the mbed Developer Community.
http://mbed.org/
"""
from __future__ import print_function
import re
import sys
import xml.etree.ElementTree as ElementTree
from binascii import crc32
from os import walk
from os.path import basename, isfile, join, normpath
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
BOARD_OPTS = env.get("BOARD_OPTIONS", {}).get("build", {})
env.Replace(
PLATFORMFW_DIR=join("$PIOPACKAGES_DIR", "framework-mbed")
)
MBED_VARIANTS = {
"blueboard_lpc11u24": "LPC11U24",
"dipcortexm0": "LPC11U24",
"seeeduinoArchPro": "ARCH_PRO",
"seeedArchMax": "ARCH_MAX",
"ubloxc027": "UBLOX_C027",
"lpc1114fn28": "LPC1114",
"lpc11u35": "LPC11U35_401",
"mbuino": "LPC11U24",
"nrf51_mkit": "NRF51822",
"seeedTinyBLE": "SEEED_TINY_BLE",
"redBearLab": "RBLAB_NRF51822",
"nrf51-dt": "NRF51_DK",
"redBearLabBLENano": "RBLAB_BLENANO",
"wallBotBLE": "NRF51822",
"frdm_kl25z": "KL25Z",
"frdm_kl46z": "KL46Z",
"frdm_k64f": "K64F",
"frdm_kl05z": "KL05Z",
"frdm_k20d50m": "K20D50M",
"frdm_k22f": "K22F",
"teensy31": "TEENSY3_1",
"dfcm_nnn40": "DELTA_DFCM_NNN40",
"samr21_xpro": "SAMR21G18A",
"saml21_xpro_b": "SAML21J18A",
"samd21_xpro": "SAMD21J18A",
"bbcmicrobit": "NRF51822"
}
MBED_LIBS_MAP = {
"dsp": {"ar": ["dsp", "cmsis_dsp"]},
"eth": {"ar": ["eth"], "deps": ["rtos"]},
"fat": {"ar": ["fat"]},
"rtos": {"ar": ["rtos", "rtx"]},
"usb": {"ar": ["USBDevice"]},
"usb_host": {"ar": ["USBHost"]}
}
def get_mbedlib_includes():
result = []
for lib in MBED_LIBS_MAP.keys():
includes = []
lib_dir = join(env.subst("$PLATFORMFW_DIR"), "libs", lib)
for _, _, files in walk(lib_dir):
for libfile in files:
if libfile.endswith(".h"):
includes.append(libfile)
result.append((lib, set(includes)))
return result
def get_used_mbedlibs():
re_includes = re.compile(r"^(#include\s+(?:\<|\")([^\r\n\"]+))",
re.M | re.I)
srcincs = []
for root, _, files in walk(env.get("PROJECTSRC_DIR")):
for pfile in files:
if not any([pfile.endswith(ext) for ext in (".h", ".c", ".cpp")]):
continue
with open(join(root, pfile)) as fp:
srcincs.extend([i[1] for i in re_includes.findall(fp.read())])
srcincs = set(srcincs)
result = {}
for libname, libincs in get_mbedlib_includes():
if libincs & srcincs and libname not in result:
result[libname] = MBED_LIBS_MAP[libname]
return result
def add_mbedlib(libname, libar):
if libar in env.get("LIBS"):
return
lib_dir = join(env.subst("$PLATFORMFW_DIR"), "libs", libname)
if not isfile(join(lib_dir, "TARGET_%s" % variant,
"TOOLCHAIN_GCC_ARM", "lib%s.a" % libar)):
print(
"Warning: %s board doesn't have native support for '%s' library!" %
(env.get("BOARD"), libname), file=sys.stderr)
return
env.Append(
LIBPATH=[
join(env.subst("$PLATFORMFW_DIR"), "libs", libname,
"TARGET_%s" % variant, "TOOLCHAIN_GCC_ARM")
],
LIBS=[libar]
)
sysincdirs = (
"eth",
"include",
"ipv4",
"lwip-eth",
"lwip-sys"
)
for root, _, files in walk(lib_dir):
if (not any(f.endswith(".h") for f in files) and
basename(root) not in sysincdirs):
continue
var_dir = join("$BUILD_DIR", "FrameworkMbed%sInc%d" %
(libname.upper(), crc32(root)))
if var_dir in env.get("CPPPATH"):
continue
env.VariantDirWrap(var_dir, root)
env.Append(CPPPATH=[var_dir])
def parse_eix_file(filename):
result = {}
paths = (
("CFLAGS", "./Target/Source/CC/Switch"),
("CXXFLAGS", "./Target/Source/CPPC/Switch"),
("CPPDEFINES", "./Target/Source/Symbols/Symbol"),
("FILES", "./Target/Files/File"),
("LINKFLAGS", "./Target/Source/LD/Switch"),
("OBJFILES", "./Target/Source/Addobjects/Addobject"),
("LIBPATH", "./Target/Linker/Librarypaths/Librarypath"),
("STDLIBS", "./Target/Source/Syslibs/Library"),
("LDSCRIPT_PATH", "./Target/Source/Scriptfile"),
("CPPPATH", "./Target/Compiler/Includepaths/Includepath")
)
tree = ElementTree.parse(filename)
for (key, path) in paths:
if key not in result:
result[key] = []
for node in tree.findall(path):
_nkeys = node.keys()
result[key].append(
node.get(_nkeys[0]) if len(_nkeys) == 1 else node.attrib)
return result
def get_build_flags(data):
flags = {}
cflags = set(data.get("CFLAGS", []))
cxxflags = set(data.get("CXXFLAGS", []))
ccflags = set(cflags & cxxflags)
flags['CCFLAGS'] = list(ccflags)
flags['CXXFLAGS'] = list(cxxflags - ccflags)
flags['CFLAGS'] = list(cflags - ccflags)
return flags
def _mbed_whole_archive_hook(libs_):
if (not isinstance(libs_, list) or
env.get("BOARD_OPTIONS", {}).get("platform") != "ststm32"):
return libs_
_dynlibs = []
_stlibs = []
for l_ in libs_:
if isinstance(l_, basestring):
_stlibs.append(l_)
else:
_dynlibs.append(l_)
libs_ = []
if _dynlibs:
libs_.append("-Wl,-whole-archive")
libs_.extend(_dynlibs)
libs_.append("-Wl,-no-whole-archive")
libs_.extend(_stlibs)
return libs_
board_type = env.subst("$BOARD")
variant = MBED_VARIANTS[
board_type] if board_type in MBED_VARIANTS else board_type.upper()
eixdata = parse_eix_file(
join(env.subst("$PLATFORMFW_DIR"), "variant", variant, "%s.eix" % variant))
build_flags = get_build_flags(eixdata)
variant_dir = join("$PLATFORMFW_DIR", "variant", variant)
env.Replace(
_mbed_whole_archive_hook=_mbed_whole_archive_hook,
_LIBFLAGS="${_mbed_whole_archive_hook(%s)}" % env.get("_LIBFLAGS")[2:-1],
CCFLAGS=build_flags.get("CCFLAGS", []),
CFLAGS=build_flags.get("CFLAGS", []),
CXXFLAGS=build_flags.get("CXXFLAGS", []),
LINKFLAGS=eixdata.get("LINKFLAGS", []),
CPPDEFINES=[define for define in eixdata.get("CPPDEFINES", [])],
LDSCRIPT_PATH=normpath(
join(variant_dir, eixdata.get("LDSCRIPT_PATH")[0]))
)
# restore external build flags
env.ProcessFlags([
env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"),
env.get("BUILD_FLAGS")
])
# Hook for K64F and K22F
if board_type in ("frdm_k22f", "frdm_k64f"):
env.Append(
LINKFLAGS=["-Wl,--start-group"]
)
for lib_path in eixdata.get("CPPPATH"):
_vdir = join("$BUILD_DIR", "FrameworkMbedInc%d" % crc32(lib_path))
env.VariantDirWrap(_vdir, join(variant_dir, lib_path))
env.Append(CPPPATH=[_vdir])
env.Append(
LIBPATH=[join(variant_dir, lib_path)
for lib_path in eixdata.get("LIBPATH", [])
if lib_path.startswith("mbed")]
)
#
# Target: Build mbed Library
#
libs = [l for l in eixdata.get("STDLIBS", []) if l not in env.get("LIBS", [])]
libs.extend(["mbed", "c", "gcc"])
libs.append(env.Library(
join("$BUILD_DIR", "FrameworkMbed"),
[join(variant_dir, f)
for f in eixdata.get("OBJFILES", [])]
))
env.Prepend(LIBS=libs)
for _libname, _libdata in get_used_mbedlibs().iteritems():
for _libar in _libdata['ar']:
add_mbedlib(_libname, _libar)
if "deps" not in _libdata:
continue
for libdep in _libdata['deps']:
for _libar in MBED_LIBS_MAP[libdep]['ar']:
add_mbedlib(libdep, _libar)
@@ -1,35 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Simba
Simba is an RTOS and build framework. It aims to make embedded
programming easy and portable.
http://simba-os.readthedocs.org
"""
from os.path import join
from SCons.Script import DefaultEnvironment, SConscript
env = DefaultEnvironment()
env.Replace(
PLATFORMFW_DIR=join("$PIOPACKAGES_DIR", "framework-simba")
)
SConscript(
[env.subst(join("$PLATFORMFW_DIR", "make", "platformio.sconscript"))])
@@ -1,119 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
SPL
The ST Standard Peripheral Library provides a set of functions for
handling the peripherals on the STM32 Cortex-M3 family.
The idea is to save the user (the new user, in particular) having to deal
directly with the registers.
http://www.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1743?sc=stm32embeddedsoftware
"""
from os.path import isfile, join
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Replace(
PLATFORMFW_DIR=join("$PIOPACKAGES_DIR", "framework-spl")
)
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkCMSIS"),
join("$PLATFORMFW_DIR", "${BOARD_OPTIONS['build']['core']}",
"cmsis", "cores", "${BOARD_OPTIONS['build']['core']}")
)
env.VariantDirWrap(
join("$BUILD_DIR", "FrameworkSPLInc"),
join(
"$PLATFORMFW_DIR", "${BOARD_OPTIONS['build']['core']}", "spl",
"variants", env.subst("${BOARD_OPTIONS['build']['variant']}")[0:7],
"inc"
)
)
env.Append(
CPPPATH=[
join("$BUILD_DIR", "FrameworkCMSIS"),
join("$BUILD_DIR", "FrameworkCMSISVariant"),
join("$BUILD_DIR", "FrameworkSPLInc"),
join("$BUILD_DIR", "FrameworkSPL")
]
)
envsafe = env.Clone()
envsafe.Append(
CPPPATH=["$BUILDSRC_DIR"],
CPPDEFINES=[
"USE_STDPERIPH_DRIVER"
]
)
#
# Target: Build SPL Library
#
# use mbed ldscript with bootloader section
ldscript = env.get("BOARD_OPTIONS", {}).get("build", {}).get("ldscript")
if not isfile(join(env.subst("$PIOPACKAGES_DIR"), "ldscripts", ldscript)):
if "mbed" in env.get("BOARD_OPTIONS", {}).get("frameworks", {}):
env.Append(
LINKFLAGS=[
'-Wl,-T"%s"' %
join(
"$PIOPACKAGES_DIR", "framework-mbed", "variant",
env.subst("$BOARD").upper(), "mbed",
"TARGET_%s" % env.subst(
"$BOARD").upper(), "TOOLCHAIN_GCC_ARM",
"%s.ld" % ldscript.upper()[:-3]
)
]
)
extra_flags = env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags")
src_filter_patterns = ["+<*>"]
if "STM32F40_41xxx" in extra_flags:
src_filter_patterns += ["-<stm32f4xx_fmc.c>"]
if "STM32F427_437xx" in extra_flags:
src_filter_patterns += ["-<stm32f4xx_fsmc.c>"]
elif "STM32F303xC" in extra_flags:
src_filter_patterns += ["-<stm32f30x_hrtim.c>"]
elif "STM32L1XX_MD" in extra_flags:
src_filter_patterns += ["-<stm32l1xx_flash_ramfunc.c>"]
libs = []
libs.append(envsafe.BuildLibrary(
join("$BUILD_DIR", "FrameworkCMSISVariant"),
join(
"$PLATFORMFW_DIR", "${BOARD_OPTIONS['build']['core']}", "cmsis",
"variants", env.subst("${BOARD_OPTIONS['build']['variant']}")[0:7]
)
))
libs.append(envsafe.BuildLibrary(
join("$BUILD_DIR", "FrameworkSPL"),
join("$PLATFORMFW_DIR", "${BOARD_OPTIONS['build']['core']}",
"spl", "variants",
env.subst("${BOARD_OPTIONS['build']['variant']}")[0:7], "src"),
src_filter=" ".join(src_filter_patterns)
))
env.Append(LIBS=libs)
@@ -1,65 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
WiringPi
WiringPi is a GPIO access library written in C for the BCM2835 used in the
Raspberry Pi. It's designed to be familiar to people who have used the Arduino
"wiring" system.
http://wiringpi.com
"""
from os.path import join
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Replace(
CPPFLAGS=[
"-O2",
"-Wformat=2",
"-Wall",
"-Winline",
"-pipe",
"-fPIC"
],
LIBS=["pthread"]
)
env.Append(
CPPDEFINES=[
"_GNU_SOURCE"
],
CPPPATH=[
join("$BUILD_DIR", "FrameworkWiringPi")
]
)
#
# Target: Build Core Library
#
libs = []
libs.append(env.BuildLibrary(
join("$BUILD_DIR", "FrameworkWiringPi"),
join("$PIOPACKAGES_DIR", "framework-wiringpi", "wiringPi")
))
env.Append(LIBS=libs)
@@ -1,61 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Freescale Kinetis series ARM microcontrollers.
"""
from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .bin file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.bin")
else:
target_firm = env.ElfToBin(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 .bin file
#
upload = env.Alias(["upload", "uploadlazy"], target_firm, env.UploadToDisk)
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-200
View File
@@ -1,200 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Intel ARC32 microcontrollers
"""
from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment)
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
if "program" in COMMAND_LINE_TARGETS:
return
env.AutodetectUploadPort()
env.Prepend(UPLOADERFLAGS=['"$UPLOAD_PORT"'])
if env.get("BOARD_OPTIONS", {}).get("upload", {}).get(
"use_1200bps_touch", False):
env.TouchSerialPort("$UPLOAD_PORT", 1200)
env = DefaultEnvironment()
env.Replace(
AR="arc-elf32-ar",
AS="arc-elf32-as",
CC="arc-elf32-gcc",
CXX="arc-elf32-g++",
OBJCOPY="arc-elf32-objcopy",
RANLIB="arc-elf32-ranlib",
SIZETOOL="arc-elf32-size",
ARFLAGS=["rcs"],
ASFLAGS=["-x", "assembler-with-cpp"],
CCFLAGS=[
"-g",
"-Os",
"-ffunction-sections",
"-fdata-sections",
"-Wall",
"-mav2em",
"-mlittle-endian",
"-m${BOARD_OPTIONS['build']['mcu']}",
"-fno-reorder-functions",
"-fno-asynchronous-unwind-tables",
"-fno-omit-frame-pointer",
"-fno-defer-pop",
"-Wno-unused-but-set-variable",
"-Wno-main",
"-ffreestanding",
"-fno-stack-protector",
"-mno-sdata",
"-fsigned-char"
],
CXXFLAGS=[
"-fno-rtti",
"-std=c++11",
"-fno-exceptions"
],
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU",
"ARDUINO_ARC32_TOOLS",
"__CPU_ARC__",
"CLOCK_SPEED=%d" % (
int(env.subst("${BOARD_OPTIONS['build']['f_cpu']}").replace(
"L", ""))/1000000),
"CONFIG_SOC_GPIO_32",
"CONFIG_SOC_GPIO_AON",
"INFRA_MULTI_CPU_SUPPORT",
"CFW_MULTI_CPU_SUPPORT",
"HAS_SHARED_MEM"
],
LINKFLAGS=[
"-Os",
"-Wl,--gc-sections",
"-Wl,-X",
"-Wl,-N",
"-Wl,-m${BOARD_OPTIONS['build']['mcu']}",
"-Wl,-marcelf",
"-static",
"-nostdlib",
"-nodefaultlibs",
"-nostartfiles",
"-Wl,--whole-archive",
"-larc32drv_arduino101",
"-Wl,--no-whole-archive"
],
LIBS=["c", "m", "gcc"],
SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES',
UPLOADER=join("$PIOPACKAGES_DIR", "tool-arduino101load", "arduino101load"),
DFUUTIL=join("$PIOPACKAGES_DIR", "tool-arduino101load", "dfu-util"),
UPLOADCMD='"$UPLOADER" $DFUUTIL $SOURCES $UPLOADERFLAGS verbose',
PROGNAME="firmware",
PROGSUFFIX=".elf"
)
env.Append(
ASFLAGS=env.get("CCFLAGS", [])[:],
BUILDERS=dict(
ElfToBin=Builder(
action=" ".join([
"$OBJCOPY",
"-S",
"-O",
"binary",
"-R",
".note",
"-R",
".comment",
"-R",
"COMMON",
"-R",
".eh_frame",
"$SOURCES",
"$TARGET"]),
suffix=".bin"
),
ElfToHex=Builder(
action=" ".join([
"$OBJCOPY",
"-S",
"-O",
"binary",
"-R",
".note",
"-R",
".comment",
"-R",
"COMMON",
"-R",
".eh_frame",
"$SOURCES",
"$TARGET"]),
suffix=".hex"
)
)
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .bin
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.bin")
else:
target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf)
#
# Target: Print binary size
#
target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
AlwaysBuild(target_size)
#
# Target: Upload firmware
#
upload = env.Alias(
["upload", "uploadlazy"], target_firm, [BeforeUpload, "$UPLOADCMD"])
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-149
View File
@@ -1,149 +0,0 @@
"""
Build script for lattice ice40 FPGAs
latticeice40-builder.py
"""
import os
from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment, Environment, Exit, GetOption,
Glob)
env = DefaultEnvironment()
env.Replace(PROGNAME="hardware")
env.Append(SIMULNAME="simulation")
# -- Get the local folder in which the icestorm tools should be installed
piopackages_dir = env.subst('$PIOPACKAGES_DIR')
bin_dir = join(piopackages_dir, 'toolchain-icestorm', 'bin')
# -- Add this path to the PATH env variable. First the building tools will be
# -- searched in the local PATH. If they are not founde, the global ones will
# -- be executed (if installed)
env.PrependENVPath('PATH', bin_dir)
# -- Target name for synthesis
TARGET = join(env['BUILD_DIR'], env['PROGNAME'])
# -- Target name for simulation
# TARGET_SIM = join(env['PROJECT_DIR'], env['SIMULNAME'])
# -- Get a list of all the verilog files in the src folfer, in ASCII, with
# -- the full path. All these files are used for the simulation
v_nodes = Glob(join(env['PROJECTSRC_DIR'], '*.v'))
src_sim = [str(f) for f in v_nodes]
# --------- Get the Testbench file (there should be only 1)
# -- Create a list with all the files finished in _tb.v. It should contain
# -- the test bench
list_tb = [f for f in src_sim if f[-5:].upper() == "_TB.V"]
if len(list_tb) > 1:
print "---> WARNING: More than one testbenches used"
# -- Error checking
try:
testbench = list_tb[0]
# -- there is no testbench
except IndexError:
testbench = None
if 'sim' in COMMAND_LINE_TARGETS:
if testbench is None:
print "ERROR!!! NO testbench found for simulation"
Exit(1)
# -- Simulation name
testbench_file = os.path.split(testbench)[-1]
SIMULNAME, ext = os.path.splitext(testbench_file)
else:
SIMULNAME = ''
TARGET_SIM = join(env.subst('$BUILD_DIR'), SIMULNAME)
# -------- Get the synthesis files. They are ALL the files except the
# -------- testbench
src_synth = [f for f in src_sim if f not in list_tb]
# -- For debugging
print "Testbench: %s" % testbench
# -- Get the PCF file
src_dir = env.subst('$PROJECTSRC_DIR')
PCFs = join(src_dir, '*.pcf')
PCF_list = Glob(PCFs)
try:
PCF = PCF_list[0]
except IndexError:
print "\n--------> ERROR: no .pcf file found <----------\n"
Exit(2)
# -- Debug
print "----> PCF Found: %s" % PCF
# -- Builder 1 (.v --> .blif)
synth = Builder(action='yosys -p \"synth_ice40 -blif %s.blif\" \
$SOURCES' % TARGET,
suffix='.blif',
src_suffix='.v')
# -- Builder 2 (.blif --> .asc)
pnr = Builder(action='arachne-pnr -d 1k -o $TARGET -p %s \
$SOURCE' % PCF,
suffix='.asc',
src_suffix='.blif')
# -- Builder 3 (.asc --> .bin)
bitstream = Builder(action='icepack $SOURCE $TARGET',
suffix='.bin',
src_suffix='.asc')
# -- Builder 4 (.asc --> .rpt)
time_rpt = Builder(action='icetime -mtr $TARGET $SOURCE',
suffix='.rpt',
src_suffix='.asc')
env.Append(BUILDERS={'Synth': synth, 'PnR': pnr, 'Bin': bitstream,
'Time': time_rpt})
blif = env.Synth(TARGET, [src_synth])
asc = env.PnR(TARGET, [blif, PCF])
binf = env.Bin(TARGET, asc)
upload = env.Alias('upload', binf, 'iceprog ' + ' $SOURCE')
AlwaysBuild(upload)
# -- Target for calculating the time (.rpt)
# rpt = env.Time(asc)
t = env.Alias('time', env.Time('time.rpt', asc))
# -------------------- Simulation ------------------
# -- Constructor para generar simulacion: icarus Verilog
iverilog = Builder(action='iverilog -o $TARGET $SOURCES ',
suffix='.out',
src_suffix='.v')
vcd = Builder(action=' $SOURCE',
suffix='.vcd', src_suffix='.out')
simenv = Environment(BUILDERS={'IVerilog': iverilog, 'VCD': vcd},
ENV=os.environ)
out = simenv.IVerilog(TARGET_SIM, src_sim)
vcd_file = simenv.VCD(SIMULNAME, out)
waves = simenv.Alias('sim', vcd_file, 'gtkwave ' +
join(env['PROJECT_DIR'], "%s " % vcd_file[0]) +
join(env['PROJECTSRC_DIR'], SIMULNAME) +
'.gtkw')
AlwaysBuild(waves)
Default([binf])
# -- These is for cleaning the files generated using the alias targets
if GetOption('clean'):
env.Default([t])
simenv.Default([out, vcd_file])
-60
View File
@@ -1,60 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Linux ARM
"""
from SCons.Script import AlwaysBuild, Default, DefaultEnvironment
from platformio.util import get_systype
env = DefaultEnvironment()
env.Replace(
_BINPREFIX="",
AR="${_BINPREFIX}ar",
AS="${_BINPREFIX}as",
CC="${_BINPREFIX}gcc",
CXX="${_BINPREFIX}g++",
OBJCOPY="${_BINPREFIX}objcopy",
RANLIB="${_BINPREFIX}ranlib",
SIZETOOL="${_BINPREFIX}size",
SIZEPRINTCMD='"$SIZETOOL" $SOURCES'
)
if get_systype() == "darwin_x86_64":
env.Replace(
_BINPREFIX="arm-linux-gnueabihf-"
)
#
# Target: Build executable program
#
target_bin = env.BuildProgram()
#
# Target: Print binary size
#
target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)
#
# Target: Define targets
#
Default([target_bin])
-60
View File
@@ -1,60 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Linux Linux i686 / 32-bit
"""
from SCons.Script import AlwaysBuild, Default, DefaultEnvironment
from platformio.util import get_systype
env = DefaultEnvironment()
env.Replace(
_BINPREFIX="",
AR="${_BINPREFIX}ar",
AS="${_BINPREFIX}as",
CC="${_BINPREFIX}gcc",
CXX="${_BINPREFIX}g++",
OBJCOPY="${_BINPREFIX}objcopy",
RANLIB="${_BINPREFIX}ranlib",
SIZETOOL="${_BINPREFIX}size",
SIZEPRINTCMD='"$SIZETOOL" $SOURCES'
)
if get_systype() == "darwin_x86_64":
env.Replace(
_BINPREFIX="i586-pc-linux-"
)
#
# Target: Build executable program
#
target_bin = env.BuildProgram()
#
# Target: Print binary size
#
target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)
#
# Target: Define targets
#
Default([target_bin])
@@ -1,60 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Linux Linux x64_64 / 64-bit
"""
from SCons.Script import AlwaysBuild, Default, DefaultEnvironment
from platformio.util import get_systype
env = DefaultEnvironment()
env.Replace(
_BINPREFIX="",
AR="${_BINPREFIX}ar",
AS="${_BINPREFIX}as",
CC="${_BINPREFIX}gcc",
CXX="${_BINPREFIX}g++",
OBJCOPY="${_BINPREFIX}objcopy",
RANLIB="${_BINPREFIX}ranlib",
SIZETOOL="${_BINPREFIX}size",
SIZEPRINTCMD='"$SIZETOOL" $SOURCES'
)
if get_systype() == "darwin_x86_64":
env.Replace(
_BINPREFIX="x86_64-pc-linux-"
)
#
# Target: Build executable program
#
target_bin = env.BuildProgram()
#
# Target: Print binary size
#
target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)
#
# Target: Define targets
#
Default([target_bin])
@@ -1,190 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Microchip PIC32 microcontrollers
"""
from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment)
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
env.AutodetectUploadPort()
env.Prepend(UPLOADERFLAGS=["-d", '"$UPLOAD_PORT"'])
env = DefaultEnvironment()
env.Replace(
AR="pic32-ar",
AS="pic32-as",
CC="pic32-gcc",
CXX="pic32-g++",
OBJCOPY="pic32-objcopy",
RANLIB="pic32-ranlib",
SIZETOOL="pic32-size",
ARFLAGS=["rcs"],
ASFLAGS=[
"-g1",
"-O2",
"-Wa,--gdwarf-2",
"-mprocessor=$BOARD_MCU"
],
CCFLAGS=[
"-w",
"-g",
"-O2",
"-MMD",
"-mdebugger",
"-mno-smart-io",
"-mprocessor=$BOARD_MCU",
"-ffunction-sections",
"-fdata-sections",
"-Wcast-align",
"-fno-short-double",
"-ftoplevel-reorder"
],
CXXFLAGS=["-fno-exceptions"],
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU",
"MPIDEVER=16777998",
"MPIDE=150"
],
LINKFLAGS=[
"-w",
"-Os",
"-mdebugger",
"-mprocessor=$BOARD_MCU",
"-mno-peripheral-libs",
"-nostartfiles",
"-Wl,--gc-sections"
],
LIBS=["m"],
SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES',
UPLOADER=join("$PIOPACKAGES_DIR", "tool-pic32prog", "pic32prog"),
UPLOADERFLAGS=[
"-b", "$UPLOAD_SPEED"
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES',
PROGNAME="firmware",
PROGSUFFIX=".elf"
)
if int(env.get("BOARD_OPTIONS", {}).get(
"upload", {}).get("maximum_ram_size", 0)) < 65535:
env.Append(
CCFLAGS=["-G1024"]
)
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"
)
)
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Hook: Fix option for LD script
#
_new_linkflags = []
for f in env['LINKFLAGS']:
if not f.startswith("-Wl,-T"):
_new_linkflags.append(f)
else:
_new_linkflags.append("-Wl,--script=%s" % f[6:])
env.Replace(LINKFLAGS=_new_linkflags)
env.Append(
LINKFLAGS=[
"-Wl,--script=chipKIT-application-COMMON%s.ld" % (
"-MZ" if "MZ" in env.get("BOARD_OPTIONS", {}).get(
"build", {}).get("mcu") else "")
]
)
#
# Target: Build the .hex
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.hex")
else:
target_firm = 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 firmware
#
upload = env.Alias(
["upload", "uploadlazy"], target_firm, [BeforeUpload, "$UPLOADCMD"])
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-44
View File
@@ -1,44 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for native platform
"""
from SCons.Script import AlwaysBuild, Default, DefaultEnvironment
env = DefaultEnvironment()
env.Replace(
SIZEPRINTCMD="size $SOURCES"
)
#
# Target: Build executable program
#
target_bin = env.BuildProgram()
#
# Target: Print binary size
#
target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)
#
# Target: Define targets
#
Default([target_bin])
-77
View File
@@ -1,77 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Nordic nRF51 series ARM microcontrollers.
"""
from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
if env.subst("$BOARD") == "rfduino":
env.Append(
CCFLAGS=["-fno-builtin"],
LINKFLAGS=["--specs=nano.specs"]
)
env.Replace(
UPLOADER=join("$PIOPACKAGES_DIR", "tool-rfdloader", "rfdloader"),
UPLOADERFLAGS=["-q", '"$UPLOAD_PORT"'],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .bin file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.hex")
else:
target_firm = 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 .bin file
#
if env.subst("$BOARD") == "rfduino":
upload = env.Alias(
["upload", "uploadlazy"], target_firm,
[lambda target, source, env: env.AutodetectUploadPort(), "$UPLOADCMD"])
else:
upload = env.Alias(["upload", "uploadlazy"], target_firm, env.UploadToDisk)
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-70
View File
@@ -1,70 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for NXP LPC series ARM microcontrollers.
"""
from os.path import join
from shutil import copyfile
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
def UploadToDisk(target, source, env): # pylint: disable=W0613,W0621
env.AutodetectUploadPort()
copyfile(join(env.subst("$BUILD_DIR"), "firmware.bin"),
join(env.subst("$UPLOAD_PORT"), "firmware.bin"))
print("Firmware has been successfully uploaded.\n"
"Please restart your board.")
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .bin file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.bin")
else:
target_firm = env.ElfToBin(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 .bin file
#
upload = env.Alias(["upload", "uploadlazy"], target_firm, UploadToDisk)
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
@@ -1,61 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Silicon Labs EFM32 series ARM microcontrollers.
"""
from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .bin file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.bin")
else:
target_firm = env.ElfToBin(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 .bin file
#
upload = env.Alias(["upload", "uploadlazy"], target_firm, env.UploadToDisk)
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-113
View File
@@ -1,113 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for ST STM32 Series ARM microcontrollers.
"""
from os.path import isfile, join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
if env.subst("$UPLOAD_PROTOCOL") == "gdb":
if not isfile(join(env.subst("$PROJECT_DIR"), "upload.gdb")):
env.Exit(
"Error: You are using GDB as firmware uploader. "
"Please specify upload commands in upload.gdb "
"file in project directory!"
)
env.Replace(
UPLOADER=join(
"$PIOPACKAGES_DIR", "toolchain-gccarmnoneeabi",
"bin", "arm-none-eabi-gdb"
),
UPLOADERFLAGS=[
join("$BUILD_DIR", "firmware.elf"),
"-batch",
"-x",
'"%s"' % join("$PROJECT_DIR", "upload.gdb")
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS'
)
else:
env.Replace(
UPLOADER=join("$PIOPACKAGES_DIR", "tool-stlink", "st-flash"),
UPLOADERFLAGS=[
"write", # write in flash
"$SOURCES", # firmware path to flash
"0x08000000" # flash start adress
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS'
)
env.Append(
CPPDEFINES=[
env.get("BOARD_OPTIONS", {}).get(
"build", {}).get("variant", "").upper()
],
LIBS=["stdc++", "nosys"],
LINKFLAGS=[
"-nostartfiles",
"-nostdlib"
]
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .bin file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.bin")
else:
target_firm = env.ElfToBin(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 .bin file
#
if "mbed" in env.subst("$FRAMEWORK") and not env.subst("$UPLOAD_PROTOCOL"):
upload = env.Alias(["upload", "uploadlazy"],
target_firm, env.UploadToDisk)
else:
upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADCMD")
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-115
View File
@@ -1,115 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Teensy boards
"""
from os.path import isfile, join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
env = DefaultEnvironment()
if env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy":
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "baseavr.py")))
elif env.get("BOARD_OPTIONS", {}).get("build", {}).get("core") == "teensy3":
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
env.Append(
LINKFLAGS=[
"-Wl,--defsym=__rtc_localtime=$UNIX_TIME",
"-fsingle-precision-constant",
"--specs=nano.specs"
],
CCFLAGS=[
"-fsingle-precision-constant"
]
)
env.Append(
CPPDEFINES=[
"USB_SERIAL",
"LAYOUT_US_ENGLISH"
],
CXXFLAGS=[
"-std=gnu++0x",
"-felide-constructors"
]
)
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
"-s", # soft reboot if device not online
"-v" # verbose output
],
UPLOADHEXCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
)
else:
env.Append(
REBOOTER=join(
"$PIOPACKAGES_DIR", "tool-teensy", "teensy_reboot"),
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'
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the firmware file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.hex")
else:
target_firm = 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 firmware file
#
upload = env.Alias(
["upload", "uploadlazy"], target_firm,
["$UPLOADHEXCMD"] + (["$REBOOTER"] if "REBOOTER" in env else []))
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-127
View File
@@ -1,127 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Texas Instruments
MSP430 Ultra-Low Power 16-bit microcontrollers
"""
from os.path import join
from platform import system
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default,
DefaultEnvironment)
env = DefaultEnvironment()
env.Replace(
AR="msp430-ar",
AS="msp430-as",
CC="msp430-gcc",
CXX="msp430-g++",
OBJCOPY="msp430-objcopy",
RANLIB="msp430-ranlib",
SIZETOOL="msp430-size",
ARFLAGS=["rcs"],
ASFLAGS=["-x", "assembler-with-cpp"],
CCFLAGS=[
"-g", # include debugging info (so errors include line numbers)
"-Os", # optimize for size
# "-Wall", # show warnings
"-ffunction-sections", # place each function in its own section
"-fdata-sections",
"-mmcu=$BOARD_MCU"
],
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU"
],
LINK="$CC",
LINKFLAGS=[
"-Os",
"-mmcu=$BOARD_MCU",
"-Wl,-gc-sections,-u,main"
],
LIBS=["m"],
SIZEPRINTCMD='"$SIZETOOL" -B -d $SOURCES',
UPLOADER=join("$PIOPACKAGES_DIR", "tool-mspdebug", "mspdebug"),
UPLOADERFLAGS=[
"$UPLOAD_PROTOCOL" if system() != "Windows" else "tilib",
"--force-reset"
],
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS "prog $SOURCES"',
PROGNAME="firmware",
PROGSUFFIX=".elf"
)
env.Append(
ASFLAGS=env.get("CCFLAGS", [])[:],
BUILDERS=dict(
ElfToHex=Builder(
action=" ".join([
"$OBJCOPY",
"-O",
"ihex",
"-R",
".eeprom",
"$SOURCES",
"$TARGET"]),
suffix=".hex"
)
)
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .hex
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.hex")
else:
target_firm = 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 firmware
#
upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADCMD")
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-74
View File
@@ -1,74 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Texas Instruments
Tiva C Series ARM Cortex-M4 microcontrollers.
"""
from os.path import join
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
DefaultEnvironment, SConscript)
env = DefaultEnvironment()
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
env.Replace(
UPLOADER=join("$PIOPACKAGES_DIR", "tool-lm4flash", "lm4flash"),
UPLOADCMD='"$UPLOADER" $SOURCES'
)
env.Append(
LINKFLAGS=[
"-nostartfiles",
"-nostdlib"
]
)
#
# Target: Build executable and linkable firmware
#
target_elf = env.BuildProgram()
#
# Target: Build the .bin file
#
if "uploadlazy" in COMMAND_LINE_TARGETS:
target_firm = join("$BUILD_DIR", "firmware.bin")
else:
target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf)
#
# Target: Print binary size
#
target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
AlwaysBuild(target_size)
#
# Target: Upload firmware
#
upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADCMD")
AlwaysBuild(upload)
#
# Target: Define targets
#
Default([target_firm, target_size])
-65
View File
@@ -1,65 +0,0 @@
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Builder for Windows x86 / 32bit
"""
from SCons.Script import AlwaysBuild, Default, DefaultEnvironment
from platformio.util import get_systype
env = DefaultEnvironment()
env.Replace(
_BINPREFIX="",
AR="${_BINPREFIX}ar",
AS="${_BINPREFIX}as",
CC="${_BINPREFIX}gcc",
CXX="${_BINPREFIX}g++",
OBJCOPY="${_BINPREFIX}objcopy",
RANLIB="${_BINPREFIX}ranlib",
SIZETOOL="${_BINPREFIX}size",
SIZEPRINTCMD='"$SIZETOOL" $SOURCES',
PROGSUFFIX=".exe"
)
if get_systype() == "darwin_x86_64":
env.Replace(
_BINPREFIX="i586-mingw32-"
)
elif get_systype() in ("linux_x86_64", "linux_i686"):
env.Replace(
_BINPREFIX="i686-w64-mingw32-"
)
#
# Target: Build executable program
#
target_bin = env.BuildProgram()
#
# Target: Print binary size
#
target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)
#
# Target: Define targets
#
Default([target_bin])