Update to MicroZig Gen 2 build interface. (#21)

Co-authored-by: Felix "xq" Queißner <git@random-projects.net>
wch-ch32v003
Felix Queißner 1 year ago committed by GitHub
parent e539cce4e5
commit 7b528f9271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

3
.gitmodules vendored

@ -1,3 +0,0 @@
[submodule "deps/microzig"]
path = deps/microzig
url = https://github.com/ZigEmbeddedGroup/microzig.git

@ -1,38 +1,94 @@
const std = @import("std"); const std = @import("std");
const microzig = @import("deps/microzig/build.zig");
pub const boards = @import("src/boards.zig"); fn path(comptime suffix: []const u8) std.Build.LazyPath {
pub const chips = @import("src/chips.zig"); return .{
.cwd_relative = comptime ((std.fs.path.dirname(@src().file) orelse ".") ++ suffix),
};
}
pub fn build(b: *std.build.Builder) void { const hal = .{
const optimize = b.standardOptimizeOption(.{}); .source_file = path("/src/hals/GD32VF103.zig"),
inline for (@typeInfo(boards).Struct.decls) |decl| { };
if (!decl.is_pub)
continue; pub const chips = struct {
pub const gd32vf103xb = .{
const exe = microzig.addEmbeddedExecutable(b, .{ .preferred_format = .elf,
.name = @field(boards, decl.name).name ++ ".minimal", .chip = .{
.source_file = .{ .name = "GD32VF103",
.path = "test/programs/minimal.zig", .cpu = .riscv32_imac,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = 128 * 1024, .kind = .flash },
.{ .offset = 0x20000000, .length = 32 * 1024, .kind = .ram },
},
.register_definition = .{
.json = path("/src/chips/GD32VF103.json"),
},
},
.hal = hal,
};
pub const gd32vf103x8 = .{
.preferred_format = .elf,
.chip = .{
.name = "GD32VF103",
.cpu = .riscv32_imac,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = 64 * 1024, .kind = .flash },
.{ .offset = 0x20000000, .length = 20 * 1024, .kind = .ram },
},
.register_definition = .{
.json = path("/src/chips/GD32VF103.json"),
}, },
.backing = .{ .board = @field(boards, decl.name) },
.optimize = optimize,
});
exe.installArtifact(b);
}
inline for (@typeInfo(chips).Struct.decls) |decl| {
if (!decl.is_pub)
continue;
const exe = microzig.addEmbeddedExecutable(b, .{
.name = @field(chips, decl.name).name ++ ".minimal",
.source_file = .{
.path = "test/programs/minimal.zig",
}, },
.backing = .{ .chip = @field(chips, decl.name) }, .hal = hal,
.optimize = optimize, };
}); };
exe.installArtifact(b);
} pub const boards = struct {
pub const sipeed = struct {
pub const longan_nano = .{
.preferred_format = .elf,
.chip = chips.gd32vf103xb.chip,
.hal = hal,
.board = .{
.name = "Longan Nano",
.url = "https://longan.sipeed.com/en/",
.source_file = path("/src/boards/longan_nano.zig"),
},
};
};
};
pub fn build(b: *std.build.Builder) void {
_ = b;
// const optimize = b.standardOptimizeOption(.{});
// inline for (@typeInfo(boards).Struct.decls) |decl| {
// if (!decl.is_pub)
// continue;
// const exe = microzig.addEmbeddedExecutable(b, .{
// .name = @field(boards, decl.name).name ++ ".minimal",
// .source_file = .{
// .path = "test/programs/minimal.zig",
// },
// .backing = .{ .board = @field(boards, decl.name) },
// .optimize = optimize,
// });
// exe.installArtifact(b);
// }
// inline for (@typeInfo(chips).Struct.decls) |decl| {
// if (!decl.is_pub)
// continue;
// const exe = microzig.addEmbeddedExecutable(b, .{
// .name = @field(chips, decl.name).name ++ ".minimal",
// .source_file = .{
// .path = "test/programs/minimal.zig",
// },
// .backing = .{ .chip = @field(chips, decl.name) },
// .optimize = optimize,
// });
// exe.installArtifact(b);
// }
} }

1
deps/microzig vendored

@ -1 +0,0 @@
Subproject commit 9392fe0f7bddde26155c181ab80b70097b49c791

@ -1,13 +0,0 @@
const std = @import("std");
const micro = @import("../deps/microzig/build.zig");
const chips = @import("chips.zig");
fn root_dir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
pub const longan_nano = micro.Board{
.name = "Longan Nano",
.source = .{ .path = root_dir() ++ "/boards/longan_nano.zig" },
.chip = chips.gd32vf103xb,
};

@ -1,26 +0,0 @@
const std = @import("std");
const micro = @import("../deps/microzig/build.zig");
const Chip = micro.Chip;
const MemoryRegion = micro.MemoryRegion;
fn root_dir() []const u8 {
return std.fs.path.dirname(@src().file) orelse unreachable;
}
pub const gd32vf103xb = Chip.from_standard_paths(root_dir(), .{
.name = "GD32VF103",
.cpu = micro.cpus.riscv32_imac,
.memory_regions = &.{
MemoryRegion{ .offset = 0x08000000, .length = 128 * 1024, .kind = .flash },
MemoryRegion{ .offset = 0x20000000, .length = 32 * 1024, .kind = .ram },
},
});
pub const gd32vf103x8 = Chip.from_standard_paths(root_dir(), .{
.name = "GD32VF103",
.cpu = micro.cpus.riscv32_imac,
.memory_regions = &.{
MemoryRegion{ .offset = 0x08000000, .length = 64 * 1024, .kind = .flash },
MemoryRegion{ .offset = 0x20000000, .length = 20 * 1024, .kind = .ram },
},
});

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save