2015-02-05 15:58:12 +02:00
|
|
|
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
|
|
|
|
# See LICENSE for details.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Builder for Atmel SAM series of microcontrollers
|
|
|
|
|
"""
|
|
|
|
|
|
2015-03-18 23:17:39 +02:00
|
|
|
from os.path import basename, join
|
2015-02-05 15:58:12 +02:00
|
|
|
|
2015-02-18 20:11:52 +02:00
|
|
|
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default,
|
|
|
|
|
DefaultEnvironment, SConscript)
|
2015-02-05 15:58:12 +02:00
|
|
|
|
2015-03-04 14:11:50 +02:00
|
|
|
from platformio.util import get_serialports
|
|
|
|
|
|
2015-02-23 19:01:03 +02:00
|
|
|
|
|
|
|
|
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
|
|
|
|
|
env.AutodetectUploadPort()
|
|
|
|
|
|
2015-03-04 14:11:50 +02:00
|
|
|
board_type = env.subst("$BOARD")
|
|
|
|
|
env.Append(
|
|
|
|
|
UPLOADERFLAGS=[
|
|
|
|
|
"-U",
|
2015-03-18 23:17:39 +02:00
|
|
|
"true" if ("usb" in board_type.lower(
|
|
|
|
|
) or board_type == "digix") else "false"
|
2015-03-04 14:11:50 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
2015-03-18 23:17:39 +02:00
|
|
|
# use only port name for BOSSA
|
|
|
|
|
if "/" in env.subst("$UPLOAD_PORT"):
|
|
|
|
|
env.Replace(UPLOAD_PORT=basename(env.subst("$UPLOAD_PORT")))
|
|
|
|
|
|
2015-02-05 15:58:12 +02:00
|
|
|
|
|
|
|
|
env = DefaultEnvironment()
|
2015-02-23 21:02:40 +02:00
|
|
|
|
|
|
|
|
SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")))
|
2015-02-05 15:58:12 +02:00
|
|
|
|
|
|
|
|
env.Replace(
|
2015-02-06 18:12:56 +02:00
|
|
|
UPLOADER=join("$PIOPACKAGES_DIR", "$PIOPACKAGE_UPLOADER", "bossac"),
|
2015-02-05 15:58:12 +02:00
|
|
|
UPLOADERFLAGS=[
|
2015-02-06 18:12:56 +02:00
|
|
|
"--info",
|
2015-02-05 15:58:12 +02:00
|
|
|
"--port", "$UPLOAD_PORT",
|
2015-02-06 18:12:56 +02:00
|
|
|
"--erase",
|
|
|
|
|
"--write",
|
|
|
|
|
"--verify",
|
2015-02-23 16:49:01 +02:00
|
|
|
"--boot",
|
|
|
|
|
"--reset"
|
2015-02-05 15:58:12 +02:00
|
|
|
],
|
2015-02-23 19:01:03 +02:00
|
|
|
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES'
|
2015-02-05 15:58:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
env.Append(
|
2015-02-18 20:11:52 +02:00
|
|
|
CPPDEFINES=[
|
2015-03-18 23:17:39 +02:00
|
|
|
"printf=iprintf",
|
|
|
|
|
"USBCON",
|
|
|
|
|
'USB_MANUFACTURER="PlatformIO"'
|
2015-02-18 20:11:52 +02:00
|
|
|
],
|
|
|
|
|
|
|
|
|
|
LINKFLAGS=[
|
|
|
|
|
"-Wl,--entry=Reset_Handler",
|
|
|
|
|
"-Wl,--start-group"
|
|
|
|
|
]
|
2015-02-05 15:58:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Target: Build executable and linkable firmware
|
|
|
|
|
#
|
|
|
|
|
|
2015-03-09 12:22:24 +02:00
|
|
|
target_elf = env.BuildFirmware()
|
2015-02-05 15:58:12 +02:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Target: Build the .bin file
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if "uploadlazy" in COMMAND_LINE_TARGETS:
|
2015-02-18 20:21:20 +02:00
|
|
|
target_firm = join("$BUILD_DIR", "firmware.bin")
|
2015-02-05 15:58:12 +02:00
|
|
|
else:
|
2015-02-18 20:21:20 +02:00
|
|
|
target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf)
|
2015-02-05 15:58:12 +02:00
|
|
|
|
2015-02-09 19:57:39 +02:00
|
|
|
#
|
|
|
|
|
# Target: Print binary size
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD")
|
|
|
|
|
AlwaysBuild(target_size)
|
|
|
|
|
|
2015-02-05 15:58:12 +02:00
|
|
|
#
|
|
|
|
|
# Target: Upload by default .bin file
|
|
|
|
|
#
|
|
|
|
|
|
2015-02-23 19:01:03 +02:00
|
|
|
upload = env.Alias(["upload", "uploadlazy"], target_firm,
|
|
|
|
|
[BeforeUpload, "$UPLOADCMD"])
|
2015-02-05 15:58:12 +02:00
|
|
|
AlwaysBuild(upload)
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Setup default targets
|
|
|
|
|
#
|
|
|
|
|
|
2015-02-18 20:21:20 +02:00
|
|
|
Default([target_firm, target_size])
|