From 2c7c74743ddab85336f1afcdd4c0eb56154b8170 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Mon, 4 Jul 2016 19:28:02 +0300 Subject: [PATCH] Initial support for Arduino M0/Tian boards // Issue #472 --- platformio/boards/arduino.json | 66 ++++++++++++++++++++++++++ platformio/builder/scripts/atmelsam.py | 36 +++++++++++++- 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/platformio/boards/arduino.json b/platformio/boards/arduino.json index 6baf07510b..29f2214771 100644 --- a/platformio/boards/arduino.json +++ b/platformio/boards/arduino.json @@ -986,5 +986,71 @@ }, "url": "http://www.arduino.org/products/boards/arduino-m0-pro", "vendor": "Arduino" + }, + "mzeroUSB": { + "build": { + "core": "arduino_zero", + "extra_flags": "-DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__", + "f_cpu": "48000000L", + "mcu": "samd21g18a", + "cpu": "cortex-m0plus", + "usb_product": "Arduino M0/Pro", + "variant": "arduino_zero", + "ldscript": "samd21g18a_bootloader_org.ld", + "hwids": [ + ["0x2A03", "0x004D"], + ["0x2A03", "0x804D"], + ["0x2A03", "0x004F"], + ["0x2A03", "0x804F"] + ] + }, + "frameworks": ["arduino"], + "name": "Arduino M0 Pro (Native USB Port)", + "platform": "atmelsam", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 262144, + "protocol": "stk500v2", + "require_upload_port" : true, + "speed": 57600, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "section_start": "0x4000" + }, + "url": "http://www.arduino.org/products/boards/arduino-m0-pro", + "vendor": "Arduino" + }, + "tian": { + "build": { + "core": "arduino_zero", + "extra_flags": "-DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__", + "f_cpu": "48000000L", + "mcu": "samd21g18a", + "cpu": "cortex-m0plus", + "usb_product": "Arduino Tian", + "variant": "arduino_zero", + "ldscript": "samd21g18a_bootloader_org.ld", + "hwids": [ + ["0x10C4", "0xEA70"], + ["0x2A03", "0x8052"] + ] + }, + "frameworks": ["arduino"], + "name": "Arduino Tian", + "platform": "atmelsam", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 262144, + "protocol": "stk500v2", + "require_upload_port" : true, + "speed": 57600, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "section_start": "0x4000" + }, + "url": "http://www.arduino.org/products/boards/arduino-tian", + "vendor": "Arduino" } } diff --git a/platformio/builder/scripts/atmelsam.py b/platformio/builder/scripts/atmelsam.py index 39440cb068..26009472e8 100644 --- a/platformio/builder/scripts/atmelsam.py +++ b/platformio/builder/scripts/atmelsam.py @@ -18,7 +18,7 @@ from os.path import basename, join -from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default, +from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default, DefaultEnvironment, SConscript) from platformio.util import get_serialports @@ -173,6 +173,38 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 if "sam3x8e" in BOARD_OPTIONS.get("build", {}).get("mcu", ""): env.Append(UPLOADERFLAGS=["--boot"]) +elif upload_protocol == "stk500v2": + env.Append( + BUILDERS=dict( + ElfToHex=Builder( + action=" ".join([ + "$OBJCOPY", + "-O", + "ihex", + "-R", + ".eeprom", + "$SOURCES", + "$TARGET"]), + suffix=".hex" + ) + ) + ) + + env.Replace( + UPLOADER=join("$PIOPACKAGES_DIR", "tool-avrdude", "avrdude"), + UPLOADERFLAGS=[ + "-C", '"%s"' % join("$PIOPACKAGES_DIR", + "tool-avrdude", "avrdude.conf"), + "-v", + "-p", "atmega2560", # Arduino M0/Tian upload hook + "-c", "$UPLOAD_PROTOCOL", + "-P", '"$UPLOAD_PORT"', + "-b", "$UPLOAD_SPEED" + ], + + UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS -U flash:w:$SOURCES:i' + ) + # # Target: Build executable and linkable firmware # @@ -185,6 +217,8 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 if "uploadlazy" in COMMAND_LINE_TARGETS: target_firm = join("$BUILD_DIR", "firmware.bin") +elif upload_protocol == "stk500v2": + target_firm = env.ElfToHex(join("$BUILD_DIR", "firmware"), target_elf) else: target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf)