microzig icon indicating copy to clipboard operation
microzig copied to clipboard

Compiling for Arduino Nano does not work in examples or from a fresh project

Open JetpackJackson opened this issue 8 months ago • 5 comments

First I tried to compile the example in the microchip/avr directory, but I got these errors:

log.txt

So then I looked at the "getting started" page on the microzig website to try to adapt that to the nano: src/main.zig

const std = @import("std");
const microzig = @import("microzig");
const rp2xxx = microzig.hal;
const time = rp2xxx.time;

// Compile-time pin configuration
const pin_config = rp2xxx.pins.GlobalConfiguration{
    .GPIO25 = .{
        .name = "led",
        .direction = .out,
    },
};

const pins = pin_config.pins();

pub fn main() !void {
    pin_config.apply();

    while (true) {
        pins.led.toggle();
        time.sleep_ms(250);
    }
}

build.zig

const std = @import("std");
const microzig = @import("microzig");

const MicroBuild = microzig.MicroBuild(.{
    .avr = true,
});

pub fn build(b: *std.Build) void {
    const mz_dep = b.dependency("microzig", .{});
    const mb = MicroBuild.init(b, mz_dep) orelse return;

    const firmware = mb.add_firmware(.{
        .name = "blinky",
        .target = mb.ports.avr.boards.arduino.nano,
        .optimize = .ReleaseSmall,
        .root_source_file = b.path("src/main.zig"),
    });

    // We call this twice to demonstrate that the default binary output for
    // RP2040 is UF2, but we can also output other formats easily
    mb.install_firmware(firmware, .{});
    mb.install_firmware(firmware, .{ .format = .elf });
}

and i get this set of errors:

log.txt

Am i missing something? The getting started example compiles for the Pico, but i cant test it cause I don't have a pico. It's when I try to do anything related to the Nano that it doesn't compile. Thanks in advance!

JetpackJackson avatar Jul 01 '25 13:07 JetpackJackson

I'm currently facing the same problem. It seems that these errors aren’t specific to Microzig, but rather an upstream Zig issue: on AVR targets usize is 16 bits, whereas several compiler_rt routines (e.g. in int_from_float.zig) currently assume a 32-bit usize.

See upstream issue https://github.com/ziglang/zig/issues/22985 and the follow-up PR https://github.com/ziglang/zig/pull/23231. Once those patches land, the AVR build should succeed without manual workarounds. Until then, I guess applying manually the patches linked in that issue is the most reliable workaround.

riblanc avatar Jul 01 '25 23:07 riblanc

Alright, thank you so much for the info! I'll try building zig with those patches then.

JetpackJackson avatar Jul 02 '25 00:07 JetpackJackson

Hmm I applied the patches and built zig but now i get log.txt and log.txt. Did I do something wrong?

JetpackJackson avatar Jul 02 '25 17:07 JetpackJackson

hey @JetpackJackson have you been able to resolve the issue ?

abelkm99 avatar Jul 17 '25 14:07 abelkm99

No, I wasn't able to build the nano code.

JetpackJackson avatar Jul 17 '25 17:07 JetpackJackson