Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Microzig Generation 2 Build Interface #3

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.zig text=auto eol=lf
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0

- name: Build examples
run: zig build
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zig-cache/
dev-scripts/
zig-out
.envrc
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# microzig-examples

Examples for embedded zig!
84 changes: 84 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const std = @import("std");
const rp2040 = @import("rp2040");
const stm32 = @import("stm32");
const lpc = @import("lpc");
const gd32 = @import("gd32");
const nrf5x = @import("nrf5x");
const esp = @import("esp");
const atmega = @import("atmega");

pub fn build(b: *std.Build) void {
const microzig = @import("microzig").init(b, "microzig");
const optimize = b.standardOptimizeOption(.{});

const TargetDesc = struct {
target: @import("microzig").Target,
name: []const u8,
};

const available_targets = [_]TargetDesc{
// RP2040
.{ .name = "pico", .target = rp2040.boards.raspberry_pi.pico },
.{ .name = "rp2040-eth", .target = rp2040.boards.waveshare.rp2040_eth },
.{ .name = "rp2040-plus-4m", .target = rp2040.boards.waveshare.rp2040_plus_4m },
.{ .name = "rp2040-plus-16m", .target = rp2040.boards.waveshare.rp2040_plus_16m },
.{ .name = "rp2040-matrix", .target = rp2040.boards.waveshare.rp2040_matrix },

// STM32
.{ .name = "stm32f103x8", .target = stm32.chips.stm32f103x8 },
.{ .name = "stm32f303vc", .target = stm32.chips.stm32f303vc },
.{ .name = "stm32f407vg", .target = stm32.chips.stm32f407vg },
.{ .name = "stm32f429zit6u", .target = stm32.chips.stm32f429zit6u },
.{ .name = "stm32f3discovery", .target = stm32.boards.stm32f3discovery },
.{ .name = "stm32f4discovery", .target = stm32.boards.stm32f4discovery },
.{ .name = "stm3240geval", .target = stm32.boards.stm3240geval },
.{ .name = "stm32f429idiscovery", .target = stm32.boards.stm32f429idiscovery },

// NXP LPC
.{ .name = "lpc176x5x", .target = lpc.chips.lpc176x5x },
.{ .name = "mbed-lpc1768", .target = lpc.boards.mbed.lpc1768 },

// GigaDevice GD32
.{ .name = "gd32vf103xb", .target = gd32.chips.gd32vf103xb },
.{ .name = "gd32vf103x8", .target = gd32.chips.gd32vf103x8 },
.{ .name = "sipeed-longan_nano", .target = gd32.boards.sipeed.longan_nano },

// Nordic Nrf5x
.{ .name = "nrf52832", .target = nrf5x.chips.nrf52832 },
.{ .name = "nrf52840", .target = nrf5x.chips.nrf52840 },
.{ .name = "nrf52840-dongle", .target = nrf5x.boards.nordic.nRF52840_Dongle }, // TODO: Add support for DFU files!

// RISC-V Espressif ESP
.{ .name = "esp32-c3", .target = esp.chips.esp32_c3 }, // TODO: Add support for Espressif Update Binaries

// Microchip ATmega
// TODO: Fix compiler bugs
// - https://github.com/ziglang/zig/issues/17219
// .{ .name = "atmega328p", .target = atmega.chips.atmega328p },
// .{ .name = "arduino-nano", .target = atmega.boards.arduino.nano },
// .{ .name = "arduino-uno-rev3", .target = atmega.boards.arduino.uno_rev3 },
};

for (available_targets) |dest| {
// `addFirmware` basically works like addExecutable, but takes a
// `microzig.Target` for target instead of a `std.zig.CrossTarget`.
//
// The target will convey all necessary information on the chip,
// cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{
.name = b.fmt("empty-{s}", .{dest.name}),
.target = dest.target,
.optimize = optimize,
.source_file = .{ .path = "src/empty.zig" },
});

// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
// and allows installing the firmware as a typical firmware file.
//
// This will also install into `$prefix/firmware` instead of `$prefix/bin`.
microzig.installFirmware(b, firmware, .{});

// For debugging, we also always install the firmware as an ELF file
microzig.installFirmware(b, firmware, .{ .format = .elf });
}
}
38 changes: 38 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.{
.name = "microzig-examples",
.version = "0.1.0",
.dependencies = .{
.microzig = .{
.url = "https://github.com/ZigEmbeddedGroup/microzig/archive/c6c9ec4516f57638e751141085c9d76120990312.tar.gz",
.hash = "1220af58bdaa721b8189f3a7adfda660517dd354463463388e96d69fe4ceccf80b92",
},
.rp2040 = .{
.url = "https://github.com/ZigEmbeddedGroup/raspberrypi-rp2040/archive/67d36eebb0fbd89633db1a51d6d2bcb049f2066a.tar.gz",
.hash = "122094bf268f45b188f3916f9e5964f4257414afaafba98a455ac47d25389a456832",
},
.stm32 = .{
.url = "https://github.com/ZigEmbeddedGroup/stmicro-stm32/archive/cb2893707efa6aa289fa72f02959ad5f2d9db2a1.tar.gz",
.hash = "12208cab5f60ef97cac4165ad694f3ba0c7b28f279538c1539b74f7c152f34fe306d",
},
.lpc = .{
.url = "https://github.com/ZigEmbeddedGroup/nxp-lpc/archive/130a1316c0892415e7da958a5e9548ed87bba54d.tar.gz",
.hash = "1220165879f85a1d51656d35b3963a95f3585dc665fc7414f76aa6aad4e6635536cf",
},
.gd32 = .{
.url = "https://github.com/ZigEmbeddedGroup/gigadevice-gd32/archive/9324753cc3b8e7afe83fcda085bcfe76681a3be3.tar.gz",
.hash = "122043ff4dcbc342f25dbb936b0d9eaa701ac3509e2cbe6764be37b90d31c7a385d0",
},
.nrf5x = .{
.url = "https://github.com/ZigEmbeddedGroup/nordic-nrf5x/archive/0ab136860ccf7eb1d07969c3ef523f3cd898e2ff.tar.gz",
.hash = "1220980da06f9634dcff06afefa7aa111bd030018fea49f79e86657dab69621e1d08",
},
.esp = .{
.url = "https://github.com/ZigEmbeddedGroup/espressif-esp/archive/59b8ca028915c0d6224ec88dbf4db19afbb559c0.tar.gz",
.hash = "1220f6e5f22416fdc63442cd8869fcaa35f9abf30d878ea3d80073176677dc6f8a65",
},
.atmega = .{
.url = "https://github.com/ZigEmbeddedGroup/microchip-atmega/archive/feefcb87a63c0aae31afb783d4e388e90c4d922f.tar.gz",
.hash = "1220048dc5d22729ee119a496f8b8ca3556838af1f3bd32ce6acd5f76480ec942965",
},
},
}
13 changes: 13 additions & 0 deletions ezpkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

exec ezpkg \
microzig=/home/felix/projects/zeg/microzig \
microzig.uf2=/home/felix/projects/zeg/uf2 \
microzig.regz=/home/felix/projects/zeg/regz \
rp2040=/home/felix/projects/zeg/device-support-package/rp2040 \
stm32=/home/felix/projects/zeg/device-support-package/stmicro-stm32 \
lpc=/home/felix/projects/zeg/device-support-package/nxp-lpc \
gd32=/home/felix/projects/zeg/device-support-package/gigadevice-gd32 \
esp=/home/felix/projects/zeg/device-support-package/espressif-esp \
nrf5x=/home/felix/projects/zeg/device-support-package/nordic-nrf5x \
atmega=/home/felix/projects/zeg/device-support-package/microchip-atmega
9 changes: 9 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
nativeBuildInputs = [
pkgs.zig_0_11_0
pkgs.picotool
pkgs.llvmPackages_16.bintools
];
buildInputs = [];
}
20 changes: 20 additions & 0 deletions src/blinky.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const std = @import("std");
const microzig = @import("microzig");
const rp2040 = microzig.hal;
const time = rp2040.time;

const pin_config = rp2040.pins.GlobalConfiguration{
.GPIO25 = .{
.name = "led",
.direction = .out,
},
};

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

while (true) {
pins.led.toggle();
time.sleep_ms(250);
}
}
6 changes: 6 additions & 0 deletions src/empty.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const std = @import("std");
const microzig = @import("microzig");

pub fn main() void {
//
}
Loading