From 486529b11251b2a1fb7929d9c7b9b3b0a5879520 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Tue, 28 Jun 2016 11:27:49 +0300 Subject: [PATCH] Add initial support for Arduino M0 Pro board // Issue #472 --- platformio/boards/arduino.json | 33 ++++++- platformio/builder/scripts/atmelsam.py | 123 +++++++++++++++---------- 2 files changed, 108 insertions(+), 48 deletions(-) diff --git a/platformio/boards/arduino.json b/platformio/boards/arduino.json index 36153504..6baf0751 100644 --- a/platformio/boards/arduino.json +++ b/platformio/boards/arduino.json @@ -885,7 +885,7 @@ "disable_flushing": true, "maximum_ram_size": 32768, "maximum_size": 262144, - "protocol": "sam-ba", + "protocol": "openocd", "require_upload_port" : false, "use_1200bps_touch": false, "wait_for_upload_port": false @@ -955,5 +955,36 @@ }, "url": "https://www.arduino.cc/en/Main/ArduinoMKR1000", "vendor": "Arduino" + }, + "mzeropro": { + "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": [ + ["0x03EB", "0x2111"], + ["0x2A03", "0x804F"] + ] + }, + "frameworks": ["arduino"], + "name": "Arduino M0 Pro (Programming Port)", + "platform": "atmelsam", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 262144, + "protocol": "openocd", + "require_upload_port" : false, + "use_1200bps_touch": false, + "wait_for_upload_port": false, + "section_start": "0x4000" + }, + "url": "http://www.arduino.org/products/boards/arduino-m0-pro", + "vendor": "Arduino" } } diff --git a/platformio/builder/scripts/atmelsam.py b/platformio/builder/scripts/atmelsam.py index 9c9297e4..8fe0a0c7 100644 --- a/platformio/builder/scripts/atmelsam.py +++ b/platformio/builder/scripts/atmelsam.py @@ -25,14 +25,6 @@ from platformio.util import get_serialports def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 - 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", {}) @@ -48,7 +40,8 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports)) # use only port name for BOSSA - if "/" in env.subst("$UPLOAD_PORT"): + if ("/" in env.subst("$UPLOAD_PORT") and + env.subst("$UPLOAD_PROTOCOL") == "sam-ba"): env.Replace(UPLOAD_PORT=basename(env.subst("$UPLOAD_PORT"))) @@ -56,41 +49,8 @@ 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' - ) +BOARD_OPTIONS = env.get("BOARD_OPTIONS", {}) + env.Append( @@ -120,8 +80,21 @@ env.Append( ] ) +user_code_section = BOARD_OPTIONS.get("upload", {}).get("section_start", False) -if "sam3x8e" in env.get("BOARD_OPTIONS", {}).get("build", {}).get("mcu", None): +if user_code_section: + env.Append( + CPPDEFINES=[ + "printf=iprintf" + ], + + LINKFLAGS=[ + "-Wl,--entry=Reset_Handler", + "-Wl,--section-start=.text=%s" % user_code_section + ] + ) + +if "sam3x8e" in BOARD_OPTIONS.get("build", {}).get("mcu", ""): env.Append( CPPDEFINES=[ "printf=iprintf" @@ -137,7 +110,7 @@ if "sam3x8e" in env.get("BOARD_OPTIONS", {}).get("build", {}).get("mcu", None): ] ) -elif "samd" in env.get("BOARD_OPTIONS", {}).get("build", {}).get("mcu", None): +elif "samd" in BOARD_OPTIONS.get("build", {}).get("mcu", ""): env.Append( LINKFLAGS=[ "--specs=nosys.specs", @@ -145,6 +118,62 @@ elif "samd" in env.get("BOARD_OPTIONS", {}).get("build", {}).get("mcu", None): ] ) + +upload_protocol = BOARD_OPTIONS.get("upload", {}).get("protocol", None) + +if upload_protocol == "openocd": + 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", + "%s;" % user_code_section if user_code_section else "0x2000", + "shutdown\"" + ], + + UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS' + ) + +elif upload_protocol == "sam-ba": + + board_type = env.subst("$BOARD") + + env.Replace( + UPLOADER=join("$PIOPACKAGES_DIR", "$PIOPACKAGE_UPLOADER", "bossac"), + UPLOADERFLAGS=[ + "--info", + "--port", '"$UPLOAD_PORT"', + "--erase", + "--write", + "--verify", + "--reset", + "--debug", + "-U", + "true" if ("usb" in board_type.lower( + ) or board_type == "digix") else "false" + ], + + UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES' + ) + # # Target: Build executable and linkable firmware # @@ -171,7 +200,7 @@ AlwaysBuild(target_size) # Target: Upload by default .bin file # -if env.subst("$BOARD") == "zero": +if upload_protocol == "openocd": upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADCMD") else: upload = env.Alias(