From 09ea198205c1a9a543154fea9b2e41891360bab8 Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 2 Aug 2024 16:55:04 -0700 Subject: [PATCH] Automatically generate .uf2 files anytime we generate a .hex file for nrf52 (#4370) * Automatically generate .uf2 files (which are often used by nrf52 bootloaders for installing app loads) anytime we generate a new hex file. This tool takes very little time to run and it is handy for development * Remove an old custom target I had tried to add to autogen uf2 files (that never worked) Build output now looks like: $ pio run --environment tracker-t1000-e Processing tracker-t1000-e (board: tracker-t1000-e; platform: platformio/nordicnrf52@^10.5.0; framework: arduino) ... Generating UF2 file Converting to uf2, output size: 1395200, start address: 0x27000 Wrote 1395200 bytes to /home/kevinh/development/meshtastic/firmware/.pio/build/tracker-t1000-e/firmware.uf2 Building .pio/build/tracker-t1000-e/firmware.zip Zip created at .pio/build/tracker-t1000-e/firmware.zip =================================================================================== [SUCCESS] Took 9.33 seconds =================================================================================== Environment Status Duration --------------- -------- ------------ tracker-t1000-e SUCCESS 00:00:09.327 =================================================================================== 1 succeeded in 00:00:09.327 =================================================================================== Co-authored-by: Ben Meadors --- bin/platformio-custom.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index 065f1267b4..4f7ce55d07 100644 --- a/bin/platformio-custom.py +++ b/bin/platformio-custom.py @@ -78,6 +78,11 @@ def esp32_create_combined_bin(source, target, env): # For newer ESP32 targets, using newlib nano works better. env.Append(LINKFLAGS=["--specs=nano.specs", "-u", "_printf_float"]) +if platform.name == "nordicnrf52": + env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", + env.VerboseAction(f"python ./bin/uf2conv.py $BUILD_DIR/firmware.hex -c -f 0xADA52840 -o $BUILD_DIR/firmware.uf2", + "Generating UF2 file")) + Import("projenv") prefsLoc = projenv["PROJECT_DIR"] + "/version.properties" @@ -90,13 +95,4 @@ def esp32_create_combined_bin(source, target, env): "-DAPP_VERSION=" + verObj["long"], "-DAPP_VERSION_SHORT=" + verObj["short"], ] -) - -# Add a custom p.io project task to run the UF2 conversion script. -env.AddCustomTarget( - name="Convert Hex to UF2", - dependencies=None, - actions=["PYTHON .\\bin\\uf2conv.py $BUILD_DIR\$env\\firmware.hex -c -f 0xADA52840 -o $BUILD_DIR\$env\\firmware.uf2"], - title="Convert hex to uf2", - description="Runs the python script to convert an already-built .hex file into .uf2 for copying to a device" -) +) \ No newline at end of file