From 2defbde8ea0903fec08b130e3b524ae8e7af98aa Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 22 Jun 2020 14:14:31 +0300 Subject: [PATCH 01/18] Move vendor URL to "homepage" field --- platform.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform.json b/platform.json index 495ae45..d1b2383 100644 --- a/platform.json +++ b/platform.json @@ -2,8 +2,7 @@ "name": "atmelmegaavr", "title": "Atmel megaAVR", "description": "8-bit MCUs Built for Real-time Control with Core Independent Peripherals combining intelligent hardware peripherals along with the low-power capability of an AVR core, megaAVR microcontrollers (MCUs) broaden the effectiveness of your real-time control systems.", - "url": "https://www.microchip.com/design-centers/8-bit/avr-mcus/device-selection/atmega4809", - "homepage": "http://platformio.org/platforms/atmelmegaavr", + "homepage": "https://www.microchip.com/design-centers/8-bit/avr-mcus/device-selection/atmega4809", "license": "Apache-2.0", "engines": { "platformio": "<5" From 8b8079fa53a42ebc659b9843201c186649b2e424 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Tue, 21 Jul 2020 18:17:39 +0200 Subject: [PATCH 02/18] Add board manifest files for MegaCoreX compatible targets --- boards/ATmega1608.json | 31 +++++++++++++++++++++++++++++++ boards/ATmega1609.json | 31 +++++++++++++++++++++++++++++++ boards/ATmega3208.json | 31 +++++++++++++++++++++++++++++++ boards/ATmega3209.json | 31 +++++++++++++++++++++++++++++++ boards/ATmega4808.json | 31 +++++++++++++++++++++++++++++++ boards/ATmega4809.json | 31 +++++++++++++++++++++++++++++++ boards/ATmega808.json | 31 +++++++++++++++++++++++++++++++ boards/ATmega809.json | 31 +++++++++++++++++++++++++++++++ 8 files changed, 248 insertions(+) create mode 100644 boards/ATmega1608.json create mode 100644 boards/ATmega1609.json create mode 100644 boards/ATmega3208.json create mode 100644 boards/ATmega3209.json create mode 100644 boards/ATmega4808.json create mode 100644 boards/ATmega4809.json create mode 100644 boards/ATmega808.json create mode 100644 boards/ATmega809.json diff --git a/boards/ATmega1608.json b/boards/ATmega1608.json new file mode 100644 index 0000000..76fde27 --- /dev/null +++ b/boards/ATmega1608.json @@ -0,0 +1,31 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA1608", + "f_cpu": "16000000L", + "mcu": "atmega1608", + "variant": "32pin-standard" + }, + "hardware": { + "oscillator": "internal", + "uart": "no_bootloader" + }, + "bootloader":{ + "led_pin": "A7" + }, + "frameworks": [ + "arduino" + ], + "name": "ATmega1608", + "upload": { + "maximum_ram_size": 2048, + "maximum_size": 16384, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.microchip.com/wwwproducts/en/ATMEGA1608", + "vendor": "Microchip" +} diff --git a/boards/ATmega1609.json b/boards/ATmega1609.json new file mode 100644 index 0000000..195edbc --- /dev/null +++ b/boards/ATmega1609.json @@ -0,0 +1,31 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA1609", + "f_cpu": "16000000L", + "mcu": "atmega1609", + "variant": "48pin-standard" + }, + "hardware": { + "oscillator": "internal", + "uart": "no_bootloader" + }, + "bootloader":{ + "led_pin": "A7" + }, + "frameworks": [ + "arduino" + ], + "name": "ATmega1609", + "upload": { + "maximum_ram_size": 2048, + "maximum_size": 16384, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.microchip.com/wwwproducts/en/ATMEGA1609", + "vendor": "Microchip" +} diff --git a/boards/ATmega3208.json b/boards/ATmega3208.json new file mode 100644 index 0000000..56a31ea --- /dev/null +++ b/boards/ATmega3208.json @@ -0,0 +1,31 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA3208", + "f_cpu": "16000000L", + "mcu": "atmega3208", + "variant": "32pin-standard" + }, + "hardware": { + "oscillator": "internal", + "uart": "no_bootloader" + }, + "bootloader":{ + "led_pin": "A7" + }, + "frameworks": [ + "arduino" + ], + "name": "ATmega3208", + "upload": { + "maximum_ram_size": 4096, + "maximum_size": 32768, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.microchip.com/wwwproducts/en/ATMEGA3208", + "vendor": "Microchip" +} diff --git a/boards/ATmega3209.json b/boards/ATmega3209.json new file mode 100644 index 0000000..cb2c123 --- /dev/null +++ b/boards/ATmega3209.json @@ -0,0 +1,31 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA3209", + "f_cpu": "16000000L", + "mcu": "atmega3209", + "variant": "48pin-standard" + }, + "hardware": { + "oscillator": "internal", + "uart": "no_bootloader" + }, + "bootloader":{ + "led_pin": "A7" + }, + "frameworks": [ + "arduino" + ], + "name": "ATmega3209", + "upload": { + "maximum_ram_size": 4096, + "maximum_size": 32768, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.microchip.com/wwwproducts/en/ATMEGA3209", + "vendor": "Microchip" +} diff --git a/boards/ATmega4808.json b/boards/ATmega4808.json new file mode 100644 index 0000000..43e92a3 --- /dev/null +++ b/boards/ATmega4808.json @@ -0,0 +1,31 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA4808", + "f_cpu": "16000000L", + "mcu": "atmega4808", + "variant": "32pin-standard" + }, + "hardware": { + "oscillator": "internal", + "uart": "no_bootloader" + }, + "bootloader":{ + "led_pin": "A7" + }, + "frameworks": [ + "arduino" + ], + "name": "ATmega4808", + "upload": { + "maximum_ram_size": 6144, + "maximum_size": 49152, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.microchip.com/wwwproducts/en/ATMEGA4808", + "vendor": "Microchip" +} diff --git a/boards/ATmega4809.json b/boards/ATmega4809.json new file mode 100644 index 0000000..89b3915 --- /dev/null +++ b/boards/ATmega4809.json @@ -0,0 +1,31 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA4809", + "f_cpu": "16000000L", + "mcu": "atmega4809", + "variant": "48pin-standard" + }, + "hardware": { + "oscillator": "internal", + "uart": "no_bootloader" + }, + "bootloader":{ + "led_pin": "A7" + }, + "frameworks": [ + "arduino" + ], + "name": "ATmega4809", + "upload": { + "maximum_ram_size": 6144, + "maximum_size": 49152, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.microchip.com/wwwproducts/en/ATMEGA4809", + "vendor": "Microchip" +} diff --git a/boards/ATmega808.json b/boards/ATmega808.json new file mode 100644 index 0000000..1d8fe85 --- /dev/null +++ b/boards/ATmega808.json @@ -0,0 +1,31 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA808", + "f_cpu": "16000000L", + "mcu": "atmega808", + "variant": "32pin-standard" + }, + "hardware": { + "oscillator": "internal", + "uart": "no_bootloader" + }, + "bootloader":{ + "led_pin": "A7" + }, + "frameworks": [ + "arduino" + ], + "name": "ATmega808", + "upload": { + "maximum_ram_size": 1024, + "maximum_size": 8192, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.microchip.com/wwwproducts/en/ATMEGA808", + "vendor": "Microchip" +} diff --git a/boards/ATmega809.json b/boards/ATmega809.json new file mode 100644 index 0000000..a40299a --- /dev/null +++ b/boards/ATmega809.json @@ -0,0 +1,31 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA809", + "f_cpu": "16000000L", + "mcu": "atmega809", + "variant": "48pin-standard" + }, + "hardware": { + "oscillator": "internal", + "uart": "no_bootloader" + }, + "bootloader":{ + "led_pin": "A7" + }, + "frameworks": [ + "arduino" + ], + "name": "ATmega809", + "upload": { + "maximum_ram_size": 1024, + "maximum_size": 8192, + "protocol": "jtag2updi", + "require_upload_port": true, + "speed": 115200, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.microchip.com/wwwproducts/en/ATMEGA809", + "vendor": "Microchip" +} From 582035587d7e0f8c5e08a839eb6d52e6219afd38 Mon Sep 17 00:00:00 2001 From: Valerii Koval Date: Tue, 4 Aug 2020 14:33:53 +0300 Subject: [PATCH 03/18] Add keywords field to platform manifest --- platform.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform.json b/platform.json index d1b2383..2eb0507 100644 --- a/platform.json +++ b/platform.json @@ -4,6 +4,13 @@ "description": "8-bit MCUs Built for Real-time Control with Core Independent Peripherals combining intelligent hardware peripherals along with the low-power capability of an AVR core, megaAVR microcontrollers (MCUs) broaden the effectiveness of your real-time control systems.", "homepage": "https://www.microchip.com/design-centers/8-bit/avr-mcus/device-selection/atmega4809", "license": "Apache-2.0", + "keywords": [ + "dev-platform", + "Microchip", + "megaAVR", + "Atmel", + "8-bit" + ], "engines": { "platformio": "<5" }, From 9b8a92c4006976d9c9eb43f7ba27f7dd36795709 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 25 Aug 2020 17:17:33 +0300 Subject: [PATCH 04/18] Use "platformio" owner for package dependencies --- platform.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/platform.json b/platform.json index 2eb0507..64f113a 100644 --- a/platform.json +++ b/platform.json @@ -5,11 +5,11 @@ "homepage": "https://www.microchip.com/design-centers/8-bit/avr-mcus/device-selection/atmega4809", "license": "Apache-2.0", "keywords": [ - "dev-platform", - "Microchip", - "megaAVR", - "Atmel", - "8-bit" + "dev-platform", + "Microchip", + "megaAVR", + "Atmel", + "8-bit" ], "engines": { "platformio": "<5" @@ -32,16 +32,19 @@ "packages": { "toolchain-atmelavr": { "type": "toolchain", + "owner": "platformio", "version": "~1.70300.0" }, "framework-arduino-megaavr": { "type": "framework", "optional": true, + "owner": "platformio", "version": "~1.8.6" }, "tool-avrdude-megaavr": { "type": "uploader", "optional": true, + "owner": "platformio", "version": "~1.60300.0" } } From 86888b639cca0eb9ec196b5251b404f1fce9d2f2 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 3 Sep 2020 15:18:19 +0300 Subject: [PATCH 05/18] Minimal compatible PlatformIO Core is 5.0 --- platform.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/platform.json b/platform.json index 64f113a..8412bc9 100644 --- a/platform.json +++ b/platform.json @@ -12,17 +12,13 @@ "8-bit" ], "engines": { - "platformio": "<5" + "platformio": "^5" }, "repository": { "type": "git", "url": "https://github.com/platformio/platform-atmelmegaavr.git" }, "version": "1.1.1", - "packageRepositories": [ - "https://dl.bintray.com/platformio/dl-packages/manifest.json", - "http://dl.platformio.org/packages/manifest.json" - ], "frameworks": { "arduino": { "package": "framework-arduino-megaavr", From 9ceb183865f622dc75fc5a1e32294a5e7ae358f1 Mon Sep 17 00:00:00 2001 From: valeros Date: Fri, 16 Oct 2020 00:44:49 +0300 Subject: [PATCH 06/18] Don't wait for upload port after reset for Nano Every // Resolve #6 --- boards/nano_every.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/boards/nano_every.json b/boards/nano_every.json index f41d9f6..66a9bcb 100644 --- a/boards/nano_every.json +++ b/boards/nano_every.json @@ -30,8 +30,7 @@ "protocol": "jtag2updi", "require_upload_port": true, "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "use_1200bps_touch": true }, "url": "https://www.arduino.cc/en/Guide/NANOEvery", "vendor": "Arduino" From 7121b110459eefd08f08a9055b8520180845f013 Mon Sep 17 00:00:00 2001 From: valeros Date: Fri, 16 Oct 2020 00:49:14 +0300 Subject: [PATCH 07/18] Preparations for MegaCoreX support // Issue #2 --- boards/nano_every.json | 5 +-- boards/uno_wifi_rev2.json | 10 +++--- builder/frameworks/arduino.py | 60 +++++++++++++++++++---------------- builder/main.py | 19 ++++++----- platform.json | 6 ++++ platform.py | 43 +++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 44 deletions(-) create mode 100644 platform.py diff --git a/boards/nano_every.json b/boards/nano_every.json index 66a9bcb..b77a16d 100644 --- a/boards/nano_every.json +++ b/boards/nano_every.json @@ -14,10 +14,10 @@ "variant": "nona4809" }, "bootloader": { - "SYSCFG0": "0xC9", + "SYSCFG0": "0xC9", "file": "atmega4809_uart_bl.hex", "fuses_file": "fuses_4809.bin", - "BOOTEND": "0x00", + "BOOTEND": "0x00", "OSCCFG": "0x01" }, "frameworks": [ @@ -25,6 +25,7 @@ ], "name": "Arduino Nano Every", "upload": { + "extra_flags": "-e", "maximum_ram_size": 6144, "maximum_size": 48640, "protocol": "jtag2updi", diff --git a/boards/uno_wifi_rev2.json b/boards/uno_wifi_rev2.json index 5d4f52a..f8d325c 100644 --- a/boards/uno_wifi_rev2.json +++ b/boards/uno_wifi_rev2.json @@ -17,8 +17,8 @@ "bootloader": { "file": "atmega4809_uart_bl.hex", "fuses_file": "fuses_4809.bin", - "BOOTEND": "0x02", - "SYSCFG0": "0xC9", + "BOOTEND": "0x02", + "SYSCFG0": "0xC9", "OSCCFG": "0x01" }, "frameworks": [ @@ -26,13 +26,11 @@ ], "name": "Arduino Uno WiFi Rev2", "upload": { - "disable_flushing": true, + "extra_flags": "-e", "maximum_ram_size": 6144, "maximum_size": 48640, "protocol": "xplainedmini_updi", - "require_upload_port": true, - "speed": 115200, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.arduino.cc/en/Guide/ArduinoUnoWiFiRev2", "vendor": "Arduino" diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index 7aac52f..de66713 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -29,12 +29,15 @@ env = DefaultEnvironment() platform = env.PioPlatform() +board = env.BoardConfig() +build_core = board.get("build.core", "") FRAMEWORK_DIR = platform.get_package_dir("framework-arduino-megaavr") -assert isdir(FRAMEWORK_DIR) +if build_core != "arduino": + FRAMEWORK_DIR = platform.get_package_dir( + "framework-arduino-megaavr-%s" % build_core.lower()) -board = env.BoardConfig() -build_core = board.get("build.core", "") +assert isdir(FRAMEWORK_DIR) CPPDEFINES = [ "ARDUINO_ARCH_MEGAAVR", @@ -66,32 +69,33 @@ ] ) -# Bootloader and fuses for uploading purposes -bootloader_config = board.get("bootloader", {}) -if "BOOTLOADER_CMD" not in env: - if env.subst("$BOARD") == "uno_wifi_rev2": - bootloader_path = join( - FRAMEWORK_DIR, "bootloaders", board.get("bootloader.file", "")) - if isfile(bootloader_path): - env.Replace(BOOTLOADER_CMD='-Uflash:w:"%s":i' % bootloader_path) - else: - sys.stderr.write( - "Error: Couldn't find bootloader image %s\n" % bootloader_path) - env.Exit(1) - -if "FUSES_CMD" not in env: - for fuse in ("OSCCFG", "SYSCFG0", "BOOTEND"): - if not bootloader_config.get(fuse, ""): - sys.stderr.write("Error: Missing %s fuse value\n" % fuse) - env.Exit(1) - - env.Replace( - FUSES_CMD="-Ufuse2:w:%s:m -Ufuse5:w:%s:m -Ufuse8:w:%s:m" % ( - bootloader_config.get("OSCCFG"), - bootloader_config.get("SYSCFG0"), - bootloader_config.get("BOOTEND") +if env.subst("$BOARD") in ("nano_every", "uno_wifi_rev2"): + # Bootloader and fuses for uploading purposes + bootloader_config = board.get("bootloader", {}) + if "BOOTLOADER_CMD" not in env: + if env.subst("$BOARD") == "uno_wifi_rev2": + bootloader_path = join( + FRAMEWORK_DIR, "bootloaders", board.get("bootloader.file", "")) + if isfile(bootloader_path): + env.Replace(BOOTLOADER_CMD='-Uflash:w:"%s":i' % bootloader_path) + else: + sys.stderr.write( + "Error: Couldn't find bootloader image %s\n" % bootloader_path) + env.Exit(1) + + if "FUSES_CMD" not in env: + for fuse in ("OSCCFG", "SYSCFG0", "BOOTEND"): + if not bootloader_config.get(fuse, ""): + sys.stderr.write("Error: Missing %s fuse value\n" % fuse) + env.Exit(1) + + env.Replace( + FUSES_CMD="-Ufuse2:w:%s:m -Ufuse5:w:%s:m -Ufuse8:w:%s:m" % ( + bootloader_config.get("OSCCFG"), + bootloader_config.get("SYSCFG0"), + bootloader_config.get("BOOTEND") + ) ) - ) # # Target: Build Core Library diff --git a/builder/main.py b/builder/main.py index 6c0038c..62be400 100644 --- a/builder/main.py +++ b/builder/main.py @@ -32,10 +32,15 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 if "extra_flags" in upload_options: env.Append(UPLOADERFLAGS=upload_options.get("extra_flags")) - # disable erasing by default - env.Append(UPLOADERFLAGS=["-e"]) - if upload_options and not upload_options.get("require_upload_port", False): + # upload methods via USB + if env.subst("$UPLOAD_PROTOCOL") in ( + "xplainedmini_updi", + "xplainedpro_updi", + "curiosity_updi", + "jtagice3_updi", + ): + env.Append(UPLOADERFLAGS=["-P", "usb"]) return env.AutodetectUploadPort() @@ -74,8 +79,9 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 UPLOADER="avrdude", UPLOADERFLAGS=[ "-p", "$BOARD_MCU", "-C", - join(env.PioPlatform().get_package_dir("tool-avrdude-megaavr") or "", - "avrdude.conf"), "-c", "$UPLOAD_PROTOCOL", "-D", "-V" + '"%s"' % join(env.PioPlatform().get_package_dir( + "tool-avrdude-megaavr") or "", "avrdude.conf"), + "-c", "$UPLOAD_PROTOCOL", "-D", "-V" ], PROGSUFFIX=".elf" @@ -170,9 +176,6 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 if upload_protocol == "custom": upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] -elif upload_protocol == "xplainedmini_updi": - env.Append(UPLOADERFLAGS=["-P", "usb", "-e", "-b", "$UPLOAD_SPEED"]) - upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] else: upload_actions = [ env.VerboseAction(BeforeUpload, "Looking for upload port..."), diff --git a/platform.json b/platform.json index 8412bc9..9241a76 100644 --- a/platform.json +++ b/platform.json @@ -37,6 +37,12 @@ "owner": "platformio", "version": "~1.8.6" }, + "framework-arduino-megaavr-megacorex": { + "type": "framework", + "optional": true, + "owner": "platformio", + "version": "~1.0.5" + }, "tool-avrdude-megaavr": { "type": "uploader", "optional": true, diff --git a/platform.py b/platform.py new file mode 100644 index 0000000..327b688 --- /dev/null +++ b/platform.py @@ -0,0 +1,43 @@ +# Copyright 2014-present PlatformIO +# +# 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. + +from platformio.managers.platform import PlatformBase + + +class AtmelmegaavrPlatform(PlatformBase): + + def configure_default_packages(self, variables, targets): + if not variables.get("board"): + return super(AtmelmegaavrPlatform, self).configure_default_packages( + variables, targets) + + build_core = variables.get( + "board_build.core", self.board_config(variables.get("board")).get( + "build.core", "arduino")) + + if "arduino" in variables.get("pioframework", []) and build_core != "arduino": + framework_package = "framework-arduino-megaavr-%s" % build_core.lower() + self.frameworks["arduino"]["package"] = framework_package + self.packages[framework_package]["optional"] = False + self.packages["framework-arduino-megaavr"]["optional"] = True + + if build_core == "MegaCoreX": + self.packages["toolchain-atmelavr"]["version"] = "~2.70300.0" + self.packages["tool-avrdude-megaavr"]["version"] = "~2.60300.0" + + if any(t in targets for t in ("fuses", "bootloader")): + self.packages["tool-avrdude"]["optional"] = False + + return super(AtmelmegaavrPlatform, self).configure_default_packages( + variables, targets) From b360efcd47bfb25930cd3dd193511e95cd994d82 Mon Sep 17 00:00:00 2001 From: valeros Date: Fri, 16 Oct 2020 00:56:44 +0300 Subject: [PATCH 08/18] Update blink example with MegaCoreX envs --- examples/arduino-blink/platformio.ini | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini index 0672aa4..4538615 100644 --- a/examples/arduino-blink/platformio.ini +++ b/examples/arduino-blink/platformio.ini @@ -16,3 +16,23 @@ board = uno_wifi_rev2 platform = atmelmegaavr framework = arduino board = nano_every + +[env:ATmega1608] +platform = atmelmegaavr +framework = arduino +board = ATmega1608 + +[env:ATmega3209] +platform = atmelmegaavr +framework = arduino +board = ATmega3209 + +[env:ATmega4808] +platform = atmelmegaavr +framework = arduino +board = ATmega4808 + +[env:ATmega809] +platform = atmelmegaavr +framework = arduino +board = ATmega809 From d44875b28bba39baf2a4b71b816a0e6faa06facf Mon Sep 17 00:00:00 2001 From: valeros Date: Wed, 21 Oct 2020 17:37:46 +0300 Subject: [PATCH 09/18] Fix avrdude package name --- platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.py b/platform.py index 327b688..88da715 100644 --- a/platform.py +++ b/platform.py @@ -37,7 +37,7 @@ def configure_default_packages(self, variables, targets): self.packages["tool-avrdude-megaavr"]["version"] = "~2.60300.0" if any(t in targets for t in ("fuses", "bootloader")): - self.packages["tool-avrdude"]["optional"] = False + self.packages["tool-avrdude-megaavr"]["optional"] = False return super(AtmelmegaavrPlatform, self).configure_default_packages( variables, targets) From 8dbe2b1e0b528e0ea1d605b6ed35f3e6e693ed72 Mon Sep 17 00:00:00 2001 From: valeros Date: Wed, 21 Oct 2020 22:17:32 +0300 Subject: [PATCH 10/18] Preparations for fuses and bootloader programming // Issue #2 --- boards/nano_every.json | 6 +- boards/uno_wifi_rev2.json | 2 +- builder/bootloader.py | 103 ++++++++++++++++++++++++++++++++++ builder/frameworks/arduino.py | 28 --------- builder/fuses.py | 63 +++++++++++++++++++++ builder/main.py | 64 ++++++++++++--------- 6 files changed, 207 insertions(+), 59 deletions(-) create mode 100644 builder/bootloader.py create mode 100644 builder/fuses.py diff --git a/boards/nano_every.json b/boards/nano_every.json index b77a16d..c348028 100644 --- a/boards/nano_every.json +++ b/boards/nano_every.json @@ -13,10 +13,8 @@ "usb_product": "Arduino Nano Every", "variant": "nona4809" }, - "bootloader": { + "fuses": { "SYSCFG0": "0xC9", - "file": "atmega4809_uart_bl.hex", - "fuses_file": "fuses_4809.bin", "BOOTEND": "0x00", "OSCCFG": "0x01" }, @@ -25,7 +23,7 @@ ], "name": "Arduino Nano Every", "upload": { - "extra_flags": "-e", + "extra_flags": ["-V", "-e", "-D"], "maximum_ram_size": 6144, "maximum_size": 48640, "protocol": "jtag2updi", diff --git a/boards/uno_wifi_rev2.json b/boards/uno_wifi_rev2.json index f8d325c..14f059b 100644 --- a/boards/uno_wifi_rev2.json +++ b/boards/uno_wifi_rev2.json @@ -26,7 +26,7 @@ ], "name": "Arduino Uno WiFi Rev2", "upload": { - "extra_flags": "-e", + "extra_flags": ["-V", "-e", "-D"], "maximum_ram_size": 6144, "maximum_size": 48640, "protocol": "xplainedmini_updi", diff --git a/builder/bootloader.py b/builder/bootloader.py new file mode 100644 index 0000000..55e975c --- /dev/null +++ b/builder/bootloader.py @@ -0,0 +1,103 @@ +# Copyright 2019-present PlatformIO +# +# 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. + +import sys +import os + +from SCons.Script import ARGUMENTS, Import, Return + +Import("env") + +board = env.BoardConfig() +platform = env.PioPlatform() +core = board.get("build.core", "") + +common_cmd = [ + "avrdude", "-p", "$BOARD_MCU", "-e", "-C", + '"%s"' % os.path.join(platform.get_package_dir("tool-avrdude-megaavr"), "avrdude.conf"), + "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" +] + +framework_dir = "" +if env.get("PIOFRAMEWORK", []): + framework_dir = platform.get_package_dir(platform.frameworks[env.get( + "PIOFRAMEWORK")[0]]["package"]) + +# +# Bootloader processing +# + +bootloader_path = board.get("bootloader.file", "") +if not os.path.isfile(bootloader_path): + bootloader_path = os.path.join(framework_dir, "bootloaders", bootloader_path) + +if not os.path.isfile(bootloader_path): + sys.stderr.write("Error: Couldn't find bootloader image\n") + env.Exit(1) + +bootloader_flags = ['-Uflash:w:"%s":i' % bootloader_path] + +# +# Fuses processing +# + +bootloader_fuses = board.get("bootloader", {}) +if not bootloader_fuses: + sys.stderr.write("Error: missing bootloader configuration!\n") + env.Exit(1) + +bootloader_fuses = board.get("bootloader", {}) +if not bootloader_fuses: + sys.stderr.write("Error: No fuse values specified!\n") + env.Exit(1) + +# Note: the index represents the fuse number +fuses = ( + bootloader_fuses.get("WDTCFG", ""), + bootloader_fuses.get("BODCFG", ""), + bootloader_fuses.get("OSCCFG", ""), + "", # Reserved + bootloader_fuses.get("TCD0CFG", ""), + bootloader_fuses.get("SYSCFG0", ""), + bootloader_fuses.get("SYSCFG1", ""), + bootloader_fuses.get("APPEND", ""), + bootloader_fuses.get("BOOTEND", ""), +) + +lock_fuse = bootloader_fuses.get("LOCKBIT", "") + +fuses_cmd = [ + "avrdude", "-p", "$BOARD_MCU", "-C", + '"%s"' % os.path.join(platform.get_package_dir("tool-avrdude-megaavr"), "avrdude.conf"), + "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" +] + +if int(ARGUMENTS.get("PIOVERBOSE", 0)): + fuses_cmd.append("-v") + +for idx, value in enumerate(fuses): + if value: + fuses_cmd.append("-Ufuse%d:w:%s:m" % (idx, value)) + +if lock_fuse: + fuses_cmd.append("-Ulock:w:%s:m" % lock_fuse) + +fuses_action = env.VerboseAction(" ".join(fuses_cmd), "Setting fuses") + +bootloader_actions = [ + fuses_action, + env.VerboseAction(" ".join(common_cmd + bootloader_flags), "Uploading bootloader") +] + +Return("bootloader_actions") diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index de66713..d180b92 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -69,34 +69,6 @@ ] ) -if env.subst("$BOARD") in ("nano_every", "uno_wifi_rev2"): - # Bootloader and fuses for uploading purposes - bootloader_config = board.get("bootloader", {}) - if "BOOTLOADER_CMD" not in env: - if env.subst("$BOARD") == "uno_wifi_rev2": - bootloader_path = join( - FRAMEWORK_DIR, "bootloaders", board.get("bootloader.file", "")) - if isfile(bootloader_path): - env.Replace(BOOTLOADER_CMD='-Uflash:w:"%s":i' % bootloader_path) - else: - sys.stderr.write( - "Error: Couldn't find bootloader image %s\n" % bootloader_path) - env.Exit(1) - - if "FUSES_CMD" not in env: - for fuse in ("OSCCFG", "SYSCFG0", "BOOTEND"): - if not bootloader_config.get(fuse, ""): - sys.stderr.write("Error: Missing %s fuse value\n" % fuse) - env.Exit(1) - - env.Replace( - FUSES_CMD="-Ufuse2:w:%s:m -Ufuse5:w:%s:m -Ufuse8:w:%s:m" % ( - bootloader_config.get("OSCCFG"), - bootloader_config.get("SYSCFG0"), - bootloader_config.get("BOOTEND") - ) - ) - # # Target: Build Core Library # diff --git a/builder/fuses.py b/builder/fuses.py new file mode 100644 index 0000000..84187cc --- /dev/null +++ b/builder/fuses.py @@ -0,0 +1,63 @@ +import sys +import os + +from SCons.Script import ARGUMENTS, Import, Return + +Import("env") + + +def print_fuses_info(fuses, lock_fuse): + print("Selected fuses:") + for idx, value in enumerate(fuses): + if value: + print("[fuse%d = %s]" % (idx, value)) + if lock_fuse: + print("lock = %s" % lock_fuse) + + + +board = env.BoardConfig() +platform = env.PioPlatform() + +board_fuses = board.get("fuses", {}) +if not board_fuses: + sys.stderr.write("Error: No fuse values specified!\n") + env.Exit(1) + +# Note: the index represents the fuse number +fuses = ( + board_fuses.get("WDTCFG", ""), + board_fuses.get("BODCFG", ""), + board_fuses.get("OSCCFG", ""), + "", # Reserved + board_fuses.get("TCD0CFG", ""), + board_fuses.get("SYSCFG0", ""), + board_fuses.get("SYSCFG1", ""), + board_fuses.get("APPEND", ""), + board_fuses.get("BOOTEND", ""), +) + +lock_fuse = board_fuses.get("LOCKBIT", "") + +fuses_cmd = [ + "avrdude", "-p", "$BOARD_MCU", "-C", + '"%s"' % os.path.join(platform.get_package_dir( + "tool-avrdude-megaavr"), "avrdude.conf"), + "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" +] + +if int(ARGUMENTS.get("PIOVERBOSE", 0)): + fuses_cmd.append("-v") + +for idx, value in enumerate(fuses): + if value: + fuses_cmd.append("-Ufuse%d:w:%s:m" % (idx, value)) + +if lock_fuse: + fuses_cmd.append("-Ulock:w:%s:m" % lock_fuse) + +print_fuses_info(fuses, lock_fuse) + +fuses_action = env.VerboseAction(" ".join(fuses_cmd), "Setting fuses") + +Return("fuses_action") diff --git a/builder/main.py b/builder/main.py index 62be400..d55287f 100644 --- a/builder/main.py +++ b/builder/main.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys from os.path import join from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS, AlwaysBuild, @@ -34,13 +35,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 if upload_options and not upload_options.get("require_upload_port", False): # upload methods via USB - if env.subst("$UPLOAD_PROTOCOL") in ( - "xplainedmini_updi", - "xplainedpro_updi", - "curiosity_updi", - "jtagice3_updi", - ): - env.Append(UPLOADERFLAGS=["-P", "usb"]) + env.Append(UPLOADERFLAGS=["-P", "usb"]) return env.AutodetectUploadPort() @@ -81,8 +76,9 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 "-p", "$BOARD_MCU", "-C", '"%s"' % join(env.PioPlatform().get_package_dir( "tool-avrdude-megaavr") or "", "avrdude.conf"), - "-c", "$UPLOAD_PROTOCOL", "-D", "-V" + "-c", "$UPLOAD_PROTOCOL" ], + UPLOADCMD="$UPLOADER $UPLOADERFLAGS -U flash:w:$SOURCES:i", PROGSUFFIX=".elf" ) @@ -168,6 +164,24 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 "Calculate program size", ) +# +# Target: Setup fuses +# + +fuses_action = None +if "fuses" in COMMAND_LINE_TARGETS: + fuses_action = env.SConscript("fuses.py", exports="env") +env.AddPlatformTarget("fuses", None, fuses_action, "Set Fuses") + +# +# Target: Upload bootloader +# + +bootloader_actions = None +if "bootloader" in COMMAND_LINE_TARGETS: + bootloader_actions = env.SConscript("bootloader.py", exports="env") +env.AddPlatformTarget("bootloader", None, bootloader_actions, "Burn Bootloader") + # # Target: Upload by default .hex file # @@ -182,32 +196,30 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") ] + board = env.subst("$BOARD") + if board == "uno_wifi_rev2": + # uno_wifi_rev2 requires bootloader to be uploaded in any case + upload_actions = env.SConscript("bootloader.py", exports="env") + upload_actions + elif board == "nano_every": + # Program fuses after programming flash + upload_actions.append(env.SConscript("fuses.py", exports="env")) + if int(ARGUMENTS.get("PIOVERBOSE", 0)): env.Prepend(UPLOADERFLAGS=["-v"]) -upload_cmd = ["-U", "flash:w:$SOURCES:i"] - -if "FUSES_CMD" in env: - upload_cmd.append(env.get("FUSES_CMD")) - -if "BOOTLOADER_CMD" in env: - upload_cmd.append(env.get("BOOTLOADER_CMD")) - -env.Replace( - UPLOADCMD='$UPLOADER $UPLOADERFLAGS %s' % " ".join(upload_cmd)) - env.AddPlatformTarget("upload", target_firm, upload_actions, "Upload") # -# Target: Upload firmware using external programmer +# Deprecated target: Upload firmware using external programmer # -env.AddPlatformTarget( - "program", - target_firm, - env.VerboseAction("$UPLOADCMD", "Programming $SOURCE"), - "Upload using Programmer", -) +if "program" in COMMAND_LINE_TARGETS: + sys.stderr.write( + "Error: `program` target is deprecated. To use a programmer for uploading " + "specify custom `upload_command`.\n" + "More details: https://docs.platformio.org/en/latest/platforms/" + "atmelavr.html#upload-using-programmer\n") + env.Exit(1) # # Setup default targets From 649282d9cfc1c25df884daf2d4d5aeec23ae73b7 Mon Sep 17 00:00:00 2001 From: valeros Date: Wed, 21 Oct 2020 22:27:57 +0300 Subject: [PATCH 11/18] Typo fix --- builder/bootloader.py | 6 ++++-- builder/fuses.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/builder/bootloader.py b/builder/bootloader.py index 55e975c..48a39e1 100644 --- a/builder/bootloader.py +++ b/builder/bootloader.py @@ -23,9 +23,11 @@ platform = env.PioPlatform() core = board.get("build.core", "") +AVRDUDE_PATH = platform.get_package_dir("tool-avrdude-megaavr") or "" + common_cmd = [ "avrdude", "-p", "$BOARD_MCU", "-e", "-C", - '"%s"' % os.path.join(platform.get_package_dir("tool-avrdude-megaavr"), "avrdude.conf"), + '"%s"' % os.path.join(AVRDUDE_PATH, "avrdude.conf"), "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" ] @@ -79,7 +81,7 @@ fuses_cmd = [ "avrdude", "-p", "$BOARD_MCU", "-C", - '"%s"' % os.path.join(platform.get_package_dir("tool-avrdude-megaavr"), "avrdude.conf"), + '"%s"' % os.path.join(AVRDUDE_PATH, "avrdude.conf"), "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" ] diff --git a/builder/fuses.py b/builder/fuses.py index 84187cc..6072f6b 100644 --- a/builder/fuses.py +++ b/builder/fuses.py @@ -42,7 +42,7 @@ def print_fuses_info(fuses, lock_fuse): fuses_cmd = [ "avrdude", "-p", "$BOARD_MCU", "-C", '"%s"' % os.path.join(platform.get_package_dir( - "tool-avrdude-megaavr"), "avrdude.conf"), + "tool-avrdude-megaavr") or "", "avrdude.conf"), "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" ] From ebadbd988550a8d972641b0cd45c07c94f4e901d Mon Sep 17 00:00:00 2001 From: valeros Date: Wed, 21 Oct 2020 22:34:17 +0300 Subject: [PATCH 12/18] Fix native example --- builder/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/main.py b/builder/main.py index d55287f..a582a15 100644 --- a/builder/main.py +++ b/builder/main.py @@ -197,7 +197,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 ] board = env.subst("$BOARD") - if board == "uno_wifi_rev2": + if board == "uno_wifi_rev2" and "arduino" in env.subst("$PIOFRAMEWORK"): # uno_wifi_rev2 requires bootloader to be uploaded in any case upload_actions = env.SConscript("bootloader.py", exports="env") + upload_actions elif board == "nano_every": From 18f45669b71eaa489b24341a146d4727d1073070 Mon Sep 17 00:00:00 2001 From: valeros Date: Thu, 22 Oct 2020 14:46:40 +0300 Subject: [PATCH 13/18] Add initial support for MegaCoreX bootloaders // Issue #2 --- boards/ATmega1608.json | 6 +-- boards/ATmega1609.json | 6 +-- boards/ATmega3208.json | 6 +-- boards/ATmega3209.json | 6 +-- boards/ATmega4808.json | 6 +-- boards/ATmega4809.json | 6 +-- boards/ATmega808.json | 6 +-- boards/ATmega809.json | 6 +-- builder/bootloader.py | 112 +++++++++++++++++++++++++---------------- builder/main.py | 14 +++--- 10 files changed, 86 insertions(+), 88 deletions(-) diff --git a/boards/ATmega1608.json b/boards/ATmega1608.json index 76fde27..ccf81e8 100644 --- a/boards/ATmega1608.json +++ b/boards/ATmega1608.json @@ -7,11 +7,7 @@ "variant": "32pin-standard" }, "hardware": { - "oscillator": "internal", - "uart": "no_bootloader" - }, - "bootloader":{ - "led_pin": "A7" + "oscillator": "internal" }, "frameworks": [ "arduino" diff --git a/boards/ATmega1609.json b/boards/ATmega1609.json index 195edbc..fddc238 100644 --- a/boards/ATmega1609.json +++ b/boards/ATmega1609.json @@ -7,11 +7,7 @@ "variant": "48pin-standard" }, "hardware": { - "oscillator": "internal", - "uart": "no_bootloader" - }, - "bootloader":{ - "led_pin": "A7" + "oscillator": "internal" }, "frameworks": [ "arduino" diff --git a/boards/ATmega3208.json b/boards/ATmega3208.json index 56a31ea..3a55026 100644 --- a/boards/ATmega3208.json +++ b/boards/ATmega3208.json @@ -7,11 +7,7 @@ "variant": "32pin-standard" }, "hardware": { - "oscillator": "internal", - "uart": "no_bootloader" - }, - "bootloader":{ - "led_pin": "A7" + "oscillator": "internal" }, "frameworks": [ "arduino" diff --git a/boards/ATmega3209.json b/boards/ATmega3209.json index cb2c123..5b7bdac 100644 --- a/boards/ATmega3209.json +++ b/boards/ATmega3209.json @@ -7,11 +7,7 @@ "variant": "48pin-standard" }, "hardware": { - "oscillator": "internal", - "uart": "no_bootloader" - }, - "bootloader":{ - "led_pin": "A7" + "oscillator": "internal" }, "frameworks": [ "arduino" diff --git a/boards/ATmega4808.json b/boards/ATmega4808.json index 43e92a3..c79544d 100644 --- a/boards/ATmega4808.json +++ b/boards/ATmega4808.json @@ -7,11 +7,7 @@ "variant": "32pin-standard" }, "hardware": { - "oscillator": "internal", - "uart": "no_bootloader" - }, - "bootloader":{ - "led_pin": "A7" + "oscillator": "internal" }, "frameworks": [ "arduino" diff --git a/boards/ATmega4809.json b/boards/ATmega4809.json index 89b3915..c2a943d 100644 --- a/boards/ATmega4809.json +++ b/boards/ATmega4809.json @@ -7,11 +7,7 @@ "variant": "48pin-standard" }, "hardware": { - "oscillator": "internal", - "uart": "no_bootloader" - }, - "bootloader":{ - "led_pin": "A7" + "oscillator": "internal" }, "frameworks": [ "arduino" diff --git a/boards/ATmega808.json b/boards/ATmega808.json index 1d8fe85..65c7421 100644 --- a/boards/ATmega808.json +++ b/boards/ATmega808.json @@ -7,11 +7,7 @@ "variant": "32pin-standard" }, "hardware": { - "oscillator": "internal", - "uart": "no_bootloader" - }, - "bootloader":{ - "led_pin": "A7" + "oscillator": "internal" }, "frameworks": [ "arduino" diff --git a/boards/ATmega809.json b/boards/ATmega809.json index a40299a..fc5f8ee 100644 --- a/boards/ATmega809.json +++ b/boards/ATmega809.json @@ -7,11 +7,7 @@ "variant": "48pin-standard" }, "hardware": { - "oscillator": "internal", - "uart": "no_bootloader" - }, - "bootloader":{ - "led_pin": "A7" + "oscillator": "internal" }, "frameworks": [ "arduino" diff --git a/builder/bootloader.py b/builder/bootloader.py index 48a39e1..f5969e3 100644 --- a/builder/bootloader.py +++ b/builder/bootloader.py @@ -23,6 +23,23 @@ platform = env.PioPlatform() core = board.get("build.core", "") + +def get_suitable_optiboot_binary(framework_dir, board_config): + uart = board_config.get("hardware.uart", "uart0").upper() + bootloader_led = board_config.get("bootloader.led_pin", "A7").upper() + bootloader_speed = board_config.get("bootloader.speed", env.subst("$UPLOAD_SPEED")) + bootloader_pins = board_config.get("bootloader.pins", "DEF").upper() + bootloader_file = "Optiboot_mega0_%s_%s_%s_%s.hex" % ( + uart, bootloader_pins, bootloader_speed, bootloader_led) + + bootloader_path = os.path.join( + framework_dir, "bootloaders", "optiboot", "bootloaders", "mega0", + bootloader_speed, bootloader_file + ) + + return bootloader_path + + AVRDUDE_PATH = platform.get_package_dir("tool-avrdude-megaavr") or "" common_cmd = [ @@ -41,6 +58,18 @@ # bootloader_path = board.get("bootloader.file", "") +if core == "MegaCoreX": + if not os.path.isfile(bootloader_path): + bootloader_path = get_suitable_optiboot_binary(framework_dir, board) +else: + if not isfile(bootloader_path): + bootloader_path = join( + framework_dir, "bootloaders", bootloader_path) + + if not board.get("bootloader", {}): + sys.stderr.write("Error: missing bootloader configuration!\n") + env.Exit(1) + if not os.path.isfile(bootloader_path): bootloader_path = os.path.join(framework_dir, "bootloaders", bootloader_path) @@ -54,48 +83,47 @@ # Fuses processing # -bootloader_fuses = board.get("bootloader", {}) -if not bootloader_fuses: - sys.stderr.write("Error: missing bootloader configuration!\n") - env.Exit(1) - -bootloader_fuses = board.get("bootloader", {}) -if not bootloader_fuses: - sys.stderr.write("Error: No fuse values specified!\n") - env.Exit(1) - -# Note: the index represents the fuse number -fuses = ( - bootloader_fuses.get("WDTCFG", ""), - bootloader_fuses.get("BODCFG", ""), - bootloader_fuses.get("OSCCFG", ""), - "", # Reserved - bootloader_fuses.get("TCD0CFG", ""), - bootloader_fuses.get("SYSCFG0", ""), - bootloader_fuses.get("SYSCFG1", ""), - bootloader_fuses.get("APPEND", ""), - bootloader_fuses.get("BOOTEND", ""), -) - -lock_fuse = bootloader_fuses.get("LOCKBIT", "") - -fuses_cmd = [ - "avrdude", "-p", "$BOARD_MCU", "-C", - '"%s"' % os.path.join(AVRDUDE_PATH, "avrdude.conf"), - "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" -] - -if int(ARGUMENTS.get("PIOVERBOSE", 0)): - fuses_cmd.append("-v") - -for idx, value in enumerate(fuses): - if value: - fuses_cmd.append("-Ufuse%d:w:%s:m" % (idx, value)) - -if lock_fuse: - fuses_cmd.append("-Ulock:w:%s:m" % lock_fuse) - -fuses_action = env.VerboseAction(" ".join(fuses_cmd), "Setting fuses") +fuses_action = None +if core == "MegaCoreX": + fuses_action = env.SConscript("fuses.py", exports="env") +else: + bootloader_fuses = board.get("bootloader", {}) + if not bootloader_fuses: + sys.stderr.write("Error: missing bootloader configuration!\n") + env.Exit(1) + + # Note: the index represents the fuse number + fuses = ( + bootloader_fuses.get("WDTCFG", ""), + bootloader_fuses.get("BODCFG", ""), + bootloader_fuses.get("OSCCFG", ""), + "", # Reserved + bootloader_fuses.get("TCD0CFG", ""), + bootloader_fuses.get("SYSCFG0", ""), + bootloader_fuses.get("SYSCFG1", ""), + bootloader_fuses.get("APPEND", ""), + bootloader_fuses.get("BOOTEND", ""), + ) + + lock_fuse = bootloader_fuses.get("LOCKBIT", "") + + fuses_cmd = [ + "avrdude", "-p", "$BOARD_MCU", "-C", + '"%s"' % os.path.join(AVRDUDE_PATH, "avrdude.conf"), + "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" + ] + + if int(ARGUMENTS.get("PIOVERBOSE", 0)): + fuses_cmd.append("-v") + + for idx, value in enumerate(fuses): + if value: + fuses_cmd.append("-Ufuse%d:w:%s:m" % (idx, value)) + + if lock_fuse: + fuses_cmd.append("-Ulock:w:%s:m" % lock_fuse) + + fuses_action = env.VerboseAction(" ".join(fuses_cmd), "Setting fuses") bootloader_actions = [ fuses_action, diff --git a/builder/main.py b/builder/main.py index a582a15..7a0924d 100644 --- a/builder/main.py +++ b/builder/main.py @@ -197,12 +197,14 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 ] board = env.subst("$BOARD") - if board == "uno_wifi_rev2" and "arduino" in env.subst("$PIOFRAMEWORK"): - # uno_wifi_rev2 requires bootloader to be uploaded in any case - upload_actions = env.SConscript("bootloader.py", exports="env") + upload_actions - elif board == "nano_every": - # Program fuses after programming flash - upload_actions.append(env.SConscript("fuses.py", exports="env")) + if "upload" in COMMAND_LINE_TARGETS and "arduino" in env.subst("$PIOFRAMEWORK"): + if board == "uno_wifi_rev2": + # uno_wifi_rev2 requires bootloader to be uploaded in any case + upload_actions = env.SConscript( + "bootloader.py", exports="env") + upload_actions + elif board == "nano_every": + # Program fuses after programming flash + upload_actions.append(env.SConscript("fuses.py", exports="env")) if int(ARGUMENTS.get("PIOVERBOSE", 0)): env.Prepend(UPLOADERFLAGS=["-v"]) From 2e2b2726fc19aba6b4f3514e13274e62b9c35eba Mon Sep 17 00:00:00 2001 From: valeros Date: Thu, 22 Oct 2020 14:47:05 +0300 Subject: [PATCH 14/18] Link framework files as static archives --- builder/frameworks/arduino.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index d180b92..6ec515c 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -22,8 +22,7 @@ http://arduino.cc/en/Reference/HomePage """ -import sys -from os.path import isdir, isfile, join +from os.path import isdir, join from SCons.Script import DefaultEnvironment @@ -85,14 +84,14 @@ join(variants_dir, board.get("build.variant")) ] ) - env.BuildSources( + libs.append(env.BuildLibrary( join("$BUILD_DIR", "FrameworkArduinoVariant"), join(variants_dir, board.get("build.variant")) - ) + )) -env.BuildSources( +libs.append(env.BuildLibrary( join("$BUILD_DIR", "FrameworkArduino"), join(FRAMEWORK_DIR, "cores", build_core) -) +)) env.Prepend(LIBS=libs) From 89d5e795de7ecdc89abb3c20cc03facd56b22935 Mon Sep 17 00:00:00 2001 From: valeros Date: Thu, 29 Oct 2020 21:58:47 +0200 Subject: [PATCH 15/18] Dynamically generate config for jtag2udpi protocol // Issue #2 --- boards/ATmega1608.json | 5 +---- boards/ATmega1609.json | 5 +---- boards/ATmega3208.json | 5 +---- boards/ATmega3209.json | 5 +---- boards/ATmega4808.json | 5 +---- boards/ATmega4809.json | 5 +---- boards/ATmega808.json | 5 +---- boards/ATmega809.json | 5 +---- boards/nano_every.json | 4 +--- builder/main.py | 6 ++++++ 10 files changed, 15 insertions(+), 35 deletions(-) diff --git a/boards/ATmega1608.json b/boards/ATmega1608.json index ccf81e8..ae5a3e7 100644 --- a/boards/ATmega1608.json +++ b/boards/ATmega1608.json @@ -17,10 +17,7 @@ "maximum_ram_size": 2048, "maximum_size": 16384, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.microchip.com/wwwproducts/en/ATMEGA1608", "vendor": "Microchip" diff --git a/boards/ATmega1609.json b/boards/ATmega1609.json index fddc238..83edca7 100644 --- a/boards/ATmega1609.json +++ b/boards/ATmega1609.json @@ -17,10 +17,7 @@ "maximum_ram_size": 2048, "maximum_size": 16384, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.microchip.com/wwwproducts/en/ATMEGA1609", "vendor": "Microchip" diff --git a/boards/ATmega3208.json b/boards/ATmega3208.json index 3a55026..9744be8 100644 --- a/boards/ATmega3208.json +++ b/boards/ATmega3208.json @@ -17,10 +17,7 @@ "maximum_ram_size": 4096, "maximum_size": 32768, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.microchip.com/wwwproducts/en/ATMEGA3208", "vendor": "Microchip" diff --git a/boards/ATmega3209.json b/boards/ATmega3209.json index 5b7bdac..6c7d3f3 100644 --- a/boards/ATmega3209.json +++ b/boards/ATmega3209.json @@ -17,10 +17,7 @@ "maximum_ram_size": 4096, "maximum_size": 32768, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.microchip.com/wwwproducts/en/ATMEGA3209", "vendor": "Microchip" diff --git a/boards/ATmega4808.json b/boards/ATmega4808.json index c79544d..a0bd34c 100644 --- a/boards/ATmega4808.json +++ b/boards/ATmega4808.json @@ -17,10 +17,7 @@ "maximum_ram_size": 6144, "maximum_size": 49152, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.microchip.com/wwwproducts/en/ATMEGA4808", "vendor": "Microchip" diff --git a/boards/ATmega4809.json b/boards/ATmega4809.json index c2a943d..8b56d51 100644 --- a/boards/ATmega4809.json +++ b/boards/ATmega4809.json @@ -17,10 +17,7 @@ "maximum_ram_size": 6144, "maximum_size": 49152, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.microchip.com/wwwproducts/en/ATMEGA4809", "vendor": "Microchip" diff --git a/boards/ATmega808.json b/boards/ATmega808.json index 65c7421..5e08df6 100644 --- a/boards/ATmega808.json +++ b/boards/ATmega808.json @@ -17,10 +17,7 @@ "maximum_ram_size": 1024, "maximum_size": 8192, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.microchip.com/wwwproducts/en/ATMEGA808", "vendor": "Microchip" diff --git a/boards/ATmega809.json b/boards/ATmega809.json index fc5f8ee..bbcbc04 100644 --- a/boards/ATmega809.json +++ b/boards/ATmega809.json @@ -17,10 +17,7 @@ "maximum_ram_size": 1024, "maximum_size": 8192, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true, - "wait_for_upload_port": true + "speed": 115200 }, "url": "https://www.microchip.com/wwwproducts/en/ATMEGA809", "vendor": "Microchip" diff --git a/boards/nano_every.json b/boards/nano_every.json index c348028..1ac658b 100644 --- a/boards/nano_every.json +++ b/boards/nano_every.json @@ -27,9 +27,7 @@ "maximum_ram_size": 6144, "maximum_size": 48640, "protocol": "jtag2updi", - "require_upload_port": true, - "speed": 115200, - "use_1200bps_touch": true + "speed": 115200 }, "url": "https://www.arduino.cc/en/Guide/NANOEvery", "vendor": "Arduino" diff --git a/builder/main.py b/builder/main.py index 7a0924d..038c081 100644 --- a/builder/main.py +++ b/builder/main.py @@ -196,6 +196,12 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") ] + # jtag2updi seems to be the only protocol that requires serial port + if upload_protocol == "jtag2updi": + upload_options = env.BoardConfig().get("upload", {}) + for opt in ("require_upload_port", "use_1200bps_touch", "wait_for_upload_port"): + upload_options[opt] = True + board = env.subst("$BOARD") if "upload" in COMMAND_LINE_TARGETS and "arduino" in env.subst("$PIOFRAMEWORK"): if board == "uno_wifi_rev2": From 7bd226c4913b66476d802695febf1e613e1e9162 Mon Sep 17 00:00:00 2001 From: valeros Date: Thu, 29 Oct 2020 22:09:54 +0200 Subject: [PATCH 16/18] Add new boards --- boards/avr_iot_wg.json | 23 +++++++++++++++++++++++ boards/curiosity_nano_4809.json | 23 +++++++++++++++++++++++ boards/xplained_pro_4809.json | 23 +++++++++++++++++++++++ examples/arduino-blink/platformio.ini | 11 +++++++++++ 4 files changed, 80 insertions(+) create mode 100644 boards/avr_iot_wg.json create mode 100644 boards/curiosity_nano_4809.json create mode 100644 boards/xplained_pro_4809.json diff --git a/boards/avr_iot_wg.json b/boards/avr_iot_wg.json new file mode 100644 index 0000000..3fad172 --- /dev/null +++ b/boards/avr_iot_wg.json @@ -0,0 +1,23 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA4808", + "f_cpu": "16000000L", + "mcu": "atmega4808", + "variant": "32pin-standard" + }, + "hardware": { + "oscillator": "internal" + }, + "frameworks": [ + "arduino" + ], + "name": "AVR-IoT WG Development Board", + "upload": { + "maximum_ram_size": 6144, + "maximum_size": 49152, + "protocol": "curiosity_updi" + }, + "url": "https://www.microchip.com/developmenttools/ProductDetails/AC164160", + "vendor": "Microchip" +} diff --git a/boards/curiosity_nano_4809.json b/boards/curiosity_nano_4809.json new file mode 100644 index 0000000..3f27fb2 --- /dev/null +++ b/boards/curiosity_nano_4809.json @@ -0,0 +1,23 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA4809", + "f_cpu": "16000000L", + "mcu": "atmega4809", + "variant": "48pin-standard" + }, + "hardware": { + "oscillator": "internal" + }, + "frameworks": [ + "arduino" + ], + "name": "Curiosity Nano ATmega4809", + "upload": { + "maximum_ram_size": 6144, + "maximum_size": 49152, + "protocol": "curiosity_updi" + }, + "url": "https://www.microchip.com/developmenttools/ProductDetails/DM320115", + "vendor": "Microchip" +} diff --git a/boards/xplained_pro_4809.json b/boards/xplained_pro_4809.json new file mode 100644 index 0000000..ce5c8da --- /dev/null +++ b/boards/xplained_pro_4809.json @@ -0,0 +1,23 @@ +{ + "build": { + "core": "MegaCoreX", + "extra_flags": "-DARDUINO_AVR_ATMEGA4809", + "f_cpu": "16000000L", + "mcu": "atmega4809", + "variant": "48pin-standard" + }, + "hardware": { + "oscillator": "internal" + }, + "frameworks": [ + "arduino" + ], + "name": "Xplained Pro ATmega4809", + "upload": { + "maximum_ram_size": 6144, + "maximum_size": 49152, + "protocol": "xplainedpro_updi" + }, + "url": "https://www.microchip.com/developmenttools/ProductDetails/atmega4809-xpro", + "vendor": "Microchip" +} diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini index 4538615..99a7554 100644 --- a/examples/arduino-blink/platformio.ini +++ b/examples/arduino-blink/platformio.ini @@ -36,3 +36,14 @@ board = ATmega4808 platform = atmelmegaavr framework = arduino board = ATmega809 + +[env:uno_wifi_rev2_megacorex] +platform = atmelmegaavr +framework = arduino +board = ATmega4809 +board_build.variant = uno-wifi + +[env:avr_iot_wg] +platform = atmelmegaavr +framework = arduino +board = avr_iot_wg From 504315f15d3bef715e7cd87b68d5ad541db780f7 Mon Sep 17 00:00:00 2001 From: valeros Date: Fri, 30 Oct 2020 18:37:44 +0200 Subject: [PATCH 17/18] Update support for fuses and bootloader programming --- boards/nano_every.json | 6 +-- boards/uno_wifi_rev2.json | 6 +-- builder/bootloader.py | 90 ++++++++++++++------------------------- builder/fuses.py | 82 +++++++++++++++++++++++------------ builder/main.py | 4 +- 5 files changed, 96 insertions(+), 92 deletions(-) diff --git a/boards/nano_every.json b/boards/nano_every.json index 1ac658b..3dcc1da 100644 --- a/boards/nano_every.json +++ b/boards/nano_every.json @@ -14,9 +14,9 @@ "variant": "nona4809" }, "fuses": { - "SYSCFG0": "0xC9", - "BOOTEND": "0x00", - "OSCCFG": "0x01" + "syscfg0": "0xc9", + "bootend": "0x00", + "osccfg": "0x01" }, "frameworks": [ "arduino" diff --git a/boards/uno_wifi_rev2.json b/boards/uno_wifi_rev2.json index 14f059b..6a7b65d 100644 --- a/boards/uno_wifi_rev2.json +++ b/boards/uno_wifi_rev2.json @@ -17,9 +17,9 @@ "bootloader": { "file": "atmega4809_uart_bl.hex", "fuses_file": "fuses_4809.bin", - "BOOTEND": "0x02", - "SYSCFG0": "0xC9", - "OSCCFG": "0x01" + "bootend": "0x02", + "syscfg0": "0xc9", + "osccfg": "0x01" }, "frameworks": [ "arduino" diff --git a/builder/bootloader.py b/builder/bootloader.py index f5969e3..499d95d 100644 --- a/builder/bootloader.py +++ b/builder/bootloader.py @@ -15,7 +15,7 @@ import sys import os -from SCons.Script import ARGUMENTS, Import, Return +from SCons.Script import Import, Return Import("env") @@ -40,14 +40,6 @@ def get_suitable_optiboot_binary(framework_dir, board_config): return bootloader_path -AVRDUDE_PATH = platform.get_package_dir("tool-avrdude-megaavr") or "" - -common_cmd = [ - "avrdude", "-p", "$BOARD_MCU", "-e", "-C", - '"%s"' % os.path.join(AVRDUDE_PATH, "avrdude.conf"), - "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" -] - framework_dir = "" if env.get("PIOFRAMEWORK", []): framework_dir = platform.get_package_dir(platform.frameworks[env.get( @@ -62,9 +54,8 @@ def get_suitable_optiboot_binary(framework_dir, board_config): if not os.path.isfile(bootloader_path): bootloader_path = get_suitable_optiboot_binary(framework_dir, board) else: - if not isfile(bootloader_path): - bootloader_path = join( - framework_dir, "bootloaders", bootloader_path) + if not os.path.isfile(bootloader_path): + bootloader_path = os.path.join(framework_dir, "bootloaders", bootloader_path) if not board.get("bootloader", {}): sys.stderr.write("Error: missing bootloader configuration!\n") @@ -73,61 +64,46 @@ def get_suitable_optiboot_binary(framework_dir, board_config): if not os.path.isfile(bootloader_path): bootloader_path = os.path.join(framework_dir, "bootloaders", bootloader_path) -if not os.path.isfile(bootloader_path): +if not os.path.isfile(bootloader_path) and "BOOTFLAGS" not in env: sys.stderr.write("Error: Couldn't find bootloader image\n") env.Exit(1) -bootloader_flags = ['-Uflash:w:"%s":i' % bootloader_path] - -# -# Fuses processing -# - -fuses_action = None -if core == "MegaCoreX": - fuses_action = env.SConscript("fuses.py", exports="env") +env.Append( + BOOTUPLOADER="avrdude", + BOOTUPLOADERFLAGS=[ + "-p", + "$BOARD_MCU", + "-C", + '"%s"' + % os.path.join(env.PioPlatform().get_package_dir( + "tool-avrdude-megaavr") or "", "avrdude.conf"), + ], + BOOTFLAGS=['-Uflash:w:"%s":i' % bootloader_path], + UPLOADBOOTCMD="$BOOTUPLOADER $BOOTUPLOADERFLAGS $UPLOAD_FLAGS $BOOTFLAGS", +) + +if not env.BoardConfig().get("upload", {}).get("require_upload_port", False): + # upload methods via USB + env.Append(BOOTUPLOADERFLAGS=["-P", "usb"]) else: - bootloader_fuses = board.get("bootloader", {}) - if not bootloader_fuses: - sys.stderr.write("Error: missing bootloader configuration!\n") - env.Exit(1) + env.AutodetectUploadPort() + env.Append(FUSESUPLOADERFLAGS=["-P", '"$UPLOAD_PORT"']) - # Note: the index represents the fuse number - fuses = ( - bootloader_fuses.get("WDTCFG", ""), - bootloader_fuses.get("BODCFG", ""), - bootloader_fuses.get("OSCCFG", ""), - "", # Reserved - bootloader_fuses.get("TCD0CFG", ""), - bootloader_fuses.get("SYSCFG0", ""), - bootloader_fuses.get("SYSCFG1", ""), - bootloader_fuses.get("APPEND", ""), - bootloader_fuses.get("BOOTEND", ""), +if env.subst("$UPLOAD_PROTOCOL") != "custom": + env.Append(BOOTUPLOADERFLAGS=["-c", "$UPLOAD_PROTOCOL"]) +else: + print( + "Warning: The `custom` upload protocol is used! The upload and fuse flags may " + "conflict!\nMore information: " + "https://docs.platformio.org/en/latest/platforms/atmelavr.html" + "#overriding-default-bootloader-command\n" ) - lock_fuse = bootloader_fuses.get("LOCKBIT", "") - - fuses_cmd = [ - "avrdude", "-p", "$BOARD_MCU", "-C", - '"%s"' % os.path.join(AVRDUDE_PATH, "avrdude.conf"), - "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" - ] - - if int(ARGUMENTS.get("PIOVERBOSE", 0)): - fuses_cmd.append("-v") - - for idx, value in enumerate(fuses): - if value: - fuses_cmd.append("-Ufuse%d:w:%s:m" % (idx, value)) - - if lock_fuse: - fuses_cmd.append("-Ulock:w:%s:m" % lock_fuse) - - fuses_action = env.VerboseAction(" ".join(fuses_cmd), "Setting fuses") +fuses_action = env.SConscript("fuses.py", exports="env") bootloader_actions = [ fuses_action, - env.VerboseAction(" ".join(common_cmd + bootloader_flags), "Uploading bootloader") + env.VerboseAction("$UPLOADBOOTCMD", "Uploading bootloader"), ] Return("bootloader_actions") diff --git a/builder/fuses.py b/builder/fuses.py index 6072f6b..6a4398c 100644 --- a/builder/fuses.py +++ b/builder/fuses.py @@ -1,7 +1,7 @@ import sys import os -from SCons.Script import ARGUMENTS, Import, Return +from SCons.Script import ARGUMENTS, COMMAND_LINE_TARGETS, Import, Return Import("env") @@ -15,49 +15,77 @@ def print_fuses_info(fuses, lock_fuse): print("lock = %s" % lock_fuse) - board = env.BoardConfig() platform = env.PioPlatform() -board_fuses = board.get("fuses", {}) -if not board_fuses: +fuses_section = "fuses" +if "bootloader" in COMMAND_LINE_TARGETS or "UPLOADBOOTCMD" in env: + fuses_section = "bootloader" + +board_fuses = board.get(fuses_section, {}) +if not board_fuses and "FUSESFLAGS" not in env: sys.stderr.write("Error: No fuse values specified!\n") env.Exit(1) # Note: the index represents the fuse number fuses = ( - board_fuses.get("WDTCFG", ""), - board_fuses.get("BODCFG", ""), - board_fuses.get("OSCCFG", ""), - "", # Reserved - board_fuses.get("TCD0CFG", ""), - board_fuses.get("SYSCFG0", ""), - board_fuses.get("SYSCFG1", ""), - board_fuses.get("APPEND", ""), - board_fuses.get("BOOTEND", ""), + board_fuses.get("wdtcfg", ""), + board_fuses.get("bodcfg", ""), + board_fuses.get("osccfg", ""), + "", # reserved + board_fuses.get("tcd0cfg", ""), + board_fuses.get("syscfg0", ""), + board_fuses.get("syscfg1", ""), + board_fuses.get("append", ""), + board_fuses.get("bootend", ""), ) lock_fuse = board_fuses.get("LOCKBIT", "") -fuses_cmd = [ - "avrdude", "-p", "$BOARD_MCU", "-C", - '"%s"' % os.path.join(platform.get_package_dir( - "tool-avrdude-megaavr") or "", "avrdude.conf"), - "-c", "$UPLOAD_PROTOCOL", "$UPLOAD_FLAGS" -] - -if int(ARGUMENTS.get("PIOVERBOSE", 0)): - fuses_cmd.append("-v") +env.Append( + FUSESUPLOADER="avrdude", + FUSESUPLOADERFLAGS=[ + "-p", + "$BOARD_MCU", + "-C", + '"%s"' + % os.path.join(env.PioPlatform().get_package_dir( + "tool-avrdude-megaavr") or "", "avrdude.conf"), + ], + SETFUSESCMD="$FUSESUPLOADER $FUSESUPLOADERFLAGS $UPLOAD_FLAGS $FUSESFLAGS", +) -for idx, value in enumerate(fuses): - if value: - fuses_cmd.append("-Ufuse%d:w:%s:m" % (idx, value)) +env.Append( + FUSESFLAGS=[ + "-Ufuse%d:w:%s:m" % (idx, value) for idx, value in enumerate(fuses) if value + ] +) if lock_fuse: - fuses_cmd.append("-Ulock:w:%s:m" % lock_fuse) + env.Append(FUSESFLAGS=["-Ulock:w:%s:m" % lock_fuse]) + +if int(ARGUMENTS.get("PIOVERBOSE", 0)): + env.Append(FUSESUPLOADERFLAGS=["-v"]) + +if not env.BoardConfig().get("upload", {}).get("require_upload_port", False): + # upload methods via USB + env.Append(FUSESUPLOADERFLAGS=["-P", "usb"]) +else: + env.AutodetectUploadPort() + env.Append(FUSESUPLOADERFLAGS=["-P", '"$UPLOAD_PORT"']) + +if env.subst("$UPLOAD_PROTOCOL") != "custom": + env.Append(FUSESUPLOADERFLAGS=["-c", "$UPLOAD_PROTOCOL"]) +else: + print( + "Warning: The `custom` upload protocol is used! The upload and fuse flags may " + "conflict!\nMore information: " + "https://docs.platformio.org/en/latest/platforms/atmelavr.html" + "#overriding-default-fuses-command\n" + ) print_fuses_info(fuses, lock_fuse) -fuses_action = env.VerboseAction(" ".join(fuses_cmd), "Setting fuses") +fuses_action = env.VerboseAction("$SETFUSESCMD", "Setting fuses") Return("fuses_action") diff --git a/builder/main.py b/builder/main.py index 038c081..a4f7fb6 100644 --- a/builder/main.py +++ b/builder/main.py @@ -206,8 +206,8 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 if "upload" in COMMAND_LINE_TARGETS and "arduino" in env.subst("$PIOFRAMEWORK"): if board == "uno_wifi_rev2": # uno_wifi_rev2 requires bootloader to be uploaded in any case - upload_actions = env.SConscript( - "bootloader.py", exports="env") + upload_actions + upload_actions += env.SConscript("bootloader.py", exports="env") + elif board == "nano_every": # Program fuses after programming flash upload_actions.append(env.SConscript("fuses.py", exports="env")) From da06342fe62cf43dbaef403b179745521976ad15 Mon Sep 17 00:00:00 2001 From: valeros Date: Fri, 30 Oct 2020 19:03:28 +0200 Subject: [PATCH 18/18] Bump version to 1.2.0 --- platform.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.json b/platform.json index 9241a76..180ab0d 100644 --- a/platform.json +++ b/platform.json @@ -18,7 +18,7 @@ "type": "git", "url": "https://github.com/platformio/platform-atmelmegaavr.git" }, - "version": "1.1.1", + "version": "1.2.0", "frameworks": { "arduino": { "package": "framework-arduino-megaavr",