diff --git a/boards/nrf52840_dongle.json b/boards/nrf52840_dongle.json new file mode 100644 index 0000000..49dbabb --- /dev/null +++ b/boards/nrf52840_dongle.json @@ -0,0 +1,34 @@ +{ + "build": { + "core": "nRF5", + "cpu": "cortex-m4", + "f_cpu": "64000000L", + "mcu": "nrf52840", + "variant": "nRF52840DONGLE", + "zephyr": { + "variant": "nrf52840dongle_nrf52840" + } + }, + "connectivity": [ + "bluetooth" + ], + "debug": { + "jlink_device": "nRF52840_xxAA", + "svd_path": "nrf52840.svd" + }, + "frameworks": [ + "zephyr" + ], + "name": "Nordic nRF52840 Dongle", + "upload": { + "maximum_ram_size": 262144, + "maximum_size": 1048576, + "protocol": "nrfutil", + "protocols": [ + "nrfutil" + ] + }, + "url": "https://www.nordicsemi.com/Products/Development-hardware/nRF52840-Dongle", + "vendor": "Nordic" + } + \ No newline at end of file diff --git a/builder/main.py b/builder/main.py index 0d94143..a8deeb4 100644 --- a/builder/main.py +++ b/builder/main.py @@ -56,6 +56,8 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 use_adafruit = board.get( "build.bsp.name", "nrf5") == "adafruit" and "arduino" in env.get("PIOFRAMEWORK", []) +target_dongle = board.get("build.variant") == "nRF52840DONGLE" + env.Replace( AR="arm-none-eabi-ar", AS="arm-none-eabi-as", @@ -171,6 +173,28 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 ) ) +if target_dongle: + env.Append( + BUILDERS=dict( + PackageDfu=Builder( + action=env.VerboseAction(" ".join([ + "nrfutil", + "pkg", + "generate", + "--hw-version", + "52", + "--sd-req", + "0x00", + "--application-version", + "0", + "--application", + "$SOURCES", + "$TARGET" + ]), "Building $TARGET"), + suffix=".zip" + ) + ) + ) if not env.get("PIOFRAMEWORK"): env.SConscript("frameworks/_bare.py") @@ -198,7 +222,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 target_firm = env.MergeHex( join("$BUILD_DIR", "${PROGNAME}"), env.ElfToHex(join("$BUILD_DIR", "userfirmware"), target_elf)) - elif "nrfutil" == upload_protocol and use_adafruit: + elif "nrfutil" == upload_protocol and (use_adafruit or target_dongle): target_firm = env.PackageDfu( join("$BUILD_DIR", "${PROGNAME}"), env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), target_elf)) @@ -318,7 +342,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 ) upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] -elif upload_protocol == "nrfutil": +elif upload_protocol == "nrfutil" and use_adafruit: env.Replace( UPLOADER=join(platform.get_package_dir( "tool-adafruit-nrfutil") or "", "adafruit-nrfutil.py"), @@ -338,6 +362,22 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") ] +elif upload_protocol == "nrfutil" and target_dongle: + env.Replace( + UPLOADER="nrfutil", + UPLOADERFLAGS=[ + "dfu", + "serial", + "-p", + "$UPLOAD_PORT" + ], + UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS -pkg $SOURCE' + ) + upload_actions = [ + env.VerboseAction(BeforeUpload, "Looking for upload port..."), + env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") + ] + elif upload_protocol == "sam-ba": env.Replace( UPLOADER="bossac",