You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Matt Knight 9ef67246e0 fix build pkg (#14) 7 months ago
..
deps update zig build api and family enum 7 months ago
src helper function in build pkg (#13) 7 months ago
.gitignore parsing elf and saving uf2 files 7 months ago
.gitmodules parsing elf and saving uf2 files 7 months ago
README.md fix build pkg (#14) 7 months ago
build.zig fix build pkg (#14) 7 months ago
build.zig.zon update to master, use zig package manager (#11) 7 months ago

README.md

uf2

USB Flashing Format (UF2) for your build.zig

This package is for assembling uf2 files from ELF binaries. This format is used for flashing a microcontroller over a mass storage interface, such as the Pi Pico.

See https://github.com/microsoft/uf2#file-containers for how we're going to embed file source into the format.

For use in a build.zig:

const uf2 = @import("uf2");

pub fn build(b: *Build) void {
    // ...
    const uf2_dep = b.dependency("uf2", .{});

    const uf2_file = uf2.from_elf(uf2_dep, exe, .{ .family_id = .RP2040 });
    _ = b.addInstallFile(uf2_file, "bin/test.uf2");
}

Manually Executing elf2uf2

pub fn build(b: *Build) void {
    // ...

    const uf2_dep = b.dependency("uf2", .{});

    const elf2uf2_run = b.addRunArtifact(uf2_dep.artifact("elf2uf2"));

    // family id
    elf2uf2_run.addArgs(&.{"--family-id", "RP2040"});

    // elf file
    elf2uf2_run.addArg("--elf-path");
    elf2uf2_run.addArtifactArg(exe);

    // output file
    const uf2_file = elf2uf2_run.addPrefixedOutputFileArg("--output-path", "test.uf2");
    _ = b.addInstallFile(uf2_file, "bin/test.uf2");
}