Compiling for Arduino Nano does not work in examples or from a fresh project
First I tried to compile the example in the microchip/avr directory, but I got these errors:
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:
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!
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.
Alright, thank you so much for the info! I'll try building zig with those patches then.
Hmm I applied the patches and built zig but now i get log.txt and log.txt. Did I do something wrong?
hey @JetpackJackson have you been able to resolve the issue ?
No, I wasn't able to build the nano code.