浏览代码

added custom pio task "Create UF2 file"

recrof 9 月之前
父节点
当前提交
24ed5b377f
共有 2 个文件被更改,包括 32 次插入0 次删除
  1. 31 0
      create-uf2.py
  2. 1 0
      platformio.ini

+ 31 - 0
create-uf2.py

@@ -0,0 +1,31 @@
+#!/usr/bin/python3
+
+# Adds PlatformIO post-processing to convert hex files to uf2 files
+
+import os
+
+Import("env")
+
+firmware_hex = "${BUILD_DIR}/${PROGNAME}.hex"
+uf2_file = os.environ.get("UF2_FILE_PATH", "${BUILD_DIR}/${PROGNAME}.uf2")
+
+def create_uf2_action(source, target, env):
+    uf2_cmd = " ".join(
+        [
+            '"$PYTHONEXE"',
+            '"$PROJECT_DIR/bin/uf2conv/uf2conv.py"',
+            '-f', '0xADA52840',
+            '-c', firmware_hex,
+            '-o', uf2_file,
+        ]
+    )
+    env.Execute(uf2_cmd)
+
+env.AddCustomTarget(
+    name="create_uf2",
+    dependencies=firmware_hex,
+    actions=create_uf2_action,
+    title="Create UF2 file",
+    description="Use uf2conv to convert hex binary into uf2",
+    always_build=True,
+)

+ 1 - 0
platformio.ini

@@ -76,6 +76,7 @@ platform = https://github.com/pioarduino/platform-espressif32/releases/download/
 [nrf52_base]
 extends = arduino_base
 platform = nordicnrf52
+extra_scripts = create-uf2.py
 build_flags = ${arduino_base.build_flags}
   -D NRF52_PLATFORM
   -D LFS_NO_ASSERT=1