Skip to content
Draft
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
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
ZIG_VERSION: 0.15.1
ZIG_VERSION: master

jobs:
formatting-check:
Expand Down Expand Up @@ -170,7 +170,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
port_dir: [gigadevice/gd32, raspberrypi/rp2xxx, stmicro/stm32, wch/ch32v]
port_dir:
[gigadevice/gd32, raspberrypi/rp2xxx, stmicro/stm32, wch/ch32v]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -188,7 +189,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
example_dir: [
example_dir:
[
espressif/esp,
gigadevice/gd32,
microchip/atmega,
Expand Down Expand Up @@ -245,7 +247,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: master
- name: Build Website
run: zig build
working-directory: website
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: master

- name: Extract version
run: echo "MICROZIG_VERSION=$(zig build package -- get-version)" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/drivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: master

- name: Run Test Suite
working-directory: drivers
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: master

# Build linter from trusted base branch code
- name: Build linter
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/publish-github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: master

- name: Download and install GitHub CLI
run: |
Expand Down Expand Up @@ -65,8 +65,6 @@ jobs:
echo "Generating metadata.json"
echo "{ \"releases\": [$(IFS=,; echo "${releases_with_artifact[*]}")] }" > website/zig-out/downloads/microzig/metadata.json



- name: List Contents
run: tree zig-out
working-directory: website
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sim-aviron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
version: master

- name: Build
working-directory: sim/aviron
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## What version of Zig to use

Zig 0.15.1
Zig master

## Getting Started With MicroZig

Expand Down
74 changes: 39 additions & 35 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,27 @@ pub const PortSelect = struct {
// Don't know if this is required but it doesn't hurt either.
// Helps in case there are multiple microzig instances including the same ports (eg: examples).
pub const PortCache = blk: {
var fields: []const std.builtin.Type.StructField = &.{};
for (port_list) |port| {
const typ = ?(custom_lazy_import(port.dep_name) orelse struct {});
fields = fields ++ [_]std.builtin.Type.StructField{.{
.name = port.name,
.type = typ,
.default_value_ptr = @as(*const anyopaque, @ptrCast(&@as(typ, null))),
.is_comptime = false,
.alignment = @alignOf(typ),
}};
var field_names: [port_list.len][]const u8 = undefined;
var field_types: [port_list.len]type = undefined;
var field_attrs: [port_list.len]std.builtin.Type.StructField.Attributes = undefined;

for (port_list, 0..) |port, i| {
const typ = custom_lazy_import(port.dep_name) orelse struct {};
const default: ?typ = null;
field_names[i] = port.name;
field_types[i] = ?typ;
field_attrs[i] = .{
.default_value_ptr = &default,
};
}
break :blk @Type(.{
.@"struct" = .{
.layout = .auto,
.fields = fields,
.decls = &.{},
.is_tuple = false,
},
});

break :blk @Struct(
.auto,
null,
&field_names,
&field_types,
&field_attrs,
);
};

var port_cache: PortCache = .{};
Expand Down Expand Up @@ -172,29 +174,31 @@ pub fn MicroBuild(port_select: PortSelect) type {
const Self = @This();

const SelectedPorts = blk: {
var fields: []const std.builtin.Type.StructField = &.{};
var field_names: [port_list.len][]const u8 = undefined;
var field_types: [port_list.len]type = undefined;
var field_attrs: [port_list.len]std.builtin.Type.StructField.Attributes = undefined;

var count: usize = 0;
for (port_list) |port| {
if (@field(port_select, port.name)) {
const i = count;
const typ = custom_lazy_import(port.dep_name) orelse struct {};
fields = fields ++ [_]std.builtin.Type.StructField{.{
.name = port.name,
.type = typ,
.default_value_ptr = null,
.is_comptime = false,
.alignment = @alignOf(typ),
}};

field_names[i] = port.name;
field_types[i] = typ;
field_attrs[i] = .{};

count += 1;
}
}

break :blk @Type(.{
.@"struct" = .{
.layout = .auto,
.fields = fields,
.decls = &.{},
.is_tuple = false,
},
});
break :blk @Struct(
.auto,
null,
field_names[0..count],
field_types[0..count],
field_attrs[0..count],
);
};

const InitReturnType = blk: {
Expand Down Expand Up @@ -395,7 +399,7 @@ pub fn MicroBuild(port_select: PortSelect) type {
cpu_mod.addImport("microzig", core_mod);
core_mod.addImport("cpu", cpu_mod);

const regz_exe = b.dependency("tools/regz", .{ .optimize = .ReleaseSafe }).artifact("regz");
const regz_exe = b.dependency("tools/regz", .{ .optimize = .Debug }).artifact("regz");
const chip_source = switch (target.chip.register_definition) {
.atdf, .svd => |file| blk: {
const regz_run = b.addRunArtifact(regz_exe);
Expand Down
26 changes: 10 additions & 16 deletions core/src/core/usb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ pub fn DeviceController(config: Config) type {
var num_ep_out = 1;

var size = @sizeOf(descriptor.Configuration);
var fields: [driver_fields.len + 1]std.builtin.Type.StructField = undefined;

var field_names: [driver_fields.len + 1][]const u8 = undefined;
var field_types: [driver_fields.len + 1]type = undefined;
var field_attrs: [driver_fields.len + 1]std.builtin.Type.StructField.Attributes = undefined;
for (driver_fields, 1..) |drv, i| {
const payload = drv.type.Descriptor.create(num_interfaces, num_strings, num_ep_in, num_ep_out);
const Payload = @TypeOf(payload);
size += @sizeOf(Payload);

fields[i] = .{
.name = drv.name,
.type = Payload,
field_names[i] = drv.name;
field_types[i] = Payload;
field_attrs[i] = .{
.default_value_ptr = &payload,
.is_comptime = false,
.alignment = 1,
};

Expand Down Expand Up @@ -131,20 +131,14 @@ pub fn DeviceController(config: Config) type {
.max_current = .from_ma(config0.max_current_ma),
};

fields[0] = .{
.name = "__configuration_descriptor",
.type = descriptor.Configuration,
field_names[0] = "__configuration_descriptor";
field_types[0] = descriptor.Configuration;
field_attrs[0] = .{
.default_value_ptr = &desc_cfg,
.is_comptime = false,
.alignment = 1,
};

break :blk @Type(.{ .@"struct" = .{
.decls = &.{},
.fields = &fields,
.is_tuple = false,
.layout = .auto,
} }){};
break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);
};

/// When the host sets the device address, the acknowledgement
Expand Down
32 changes: 10 additions & 22 deletions core/src/cpus/cortex_m.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,19 @@ pub const ExternalInterrupt = blk: {

if (result_len == 0) break :blk enum {};

var fields: [result_len]std.builtin.Type.EnumField = undefined;
var field_names: [result_len][]const u8 = undefined;
var field_values: [result_len]u8 = undefined;
var field_index: usize = 0;

for (microzig.chip.interrupts) |intr| {
if (intr.index >= 0) {
fields[field_index] = .{
.name = intr.name,
.value = intr.index,
};
field_names[field_index] = intr.name;
field_values[field_index] = intr.index;
field_index += 1;
}
}

break :blk @Type(.{ .@"enum" = .{
.tag_type = u8,
.fields = &fields,
.decls = &.{},
.is_exhaustive = true,
} });
break :blk @Enum(u8, .exhaustive, field_names, field_values);
};

/// Machine exceptions.
Expand All @@ -105,25 +99,19 @@ pub const Exception = blk: {

if (result_len == 0) break :blk enum {};

var fields: [result_len]std.builtin.Type.EnumField = undefined;
var field_names: [result_len][]const u8 = undefined;
var field_values: [result_len]u4 = undefined;
var field_index: usize = 0;

for (microzig.chip.interrupts) |intr| {
if (intr.index < 0) {
fields[field_index] = .{
.name = intr.name,
.value = 16 + intr.index, // Cortex-M exceptions are mapped to vector table slots 0 - 15
};
field_names[field_index] = intr.name;
field_values[field_index] = 16 + intr.index; // Cortex-M exceptions are mapped to vector table slots 0 - 15
field_index += 1;
}
}

break :blk @Type(.{ .@"enum" = .{
.tag_type = u4,
.fields = &fields,
.decls = &.{},
.is_exhaustive = true,
} });
break :blk @Enum(u4, .exhaustive, field_names, field_values);
};

pub const interrupt = struct {
Expand Down
16 changes: 11 additions & 5 deletions core/src/microzig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ pub const panic = std.debug.FullPanic(struct {
var frame_index: usize = 0;
if (@errorReturnTrace()) |trace| frame_index = utilities.dump_stack_trace(trace);

var iter = std.debug.StackIterator.init(first_trace_address orelse @returnAddress(), null);
while (iter.next()) |address| : (frame_index += 1) {
std.log.err("{d: >3}: 0x{X:0>8}", .{ frame_index, address });
}
var addr_buf: [20]usize = undefined;
var stacktrace = std.debug.captureCurrentStackTrace(.{
.first_address = first_trace_address orelse @returnAddress(),
}, &addr_buf);

_ = utilities.dump_stack_trace(&stacktrace);
//var iter = std.debug.StackIterator.init(first_trace_address orelse @returnAddress(), null);
//while (iter.next()) |address| : (frame_index += 1) {
// std.log.err("{d: >3}: 0x{X:0>8}", .{ frame_index, address });
//}

// Attach a breakpoint. this might trigger another panic internally, so
// only do that if requested.
Expand Down Expand Up @@ -77,7 +83,7 @@ pub const Options = struct {
) void = struct {
fn log(
comptime message_level: std.log.Level,
comptime scope: @Type(.enum_literal),
comptime scope: @EnumLiteral(),
comptime format: []const u8,
args: anytype,
) void {
Expand Down
Loading
Loading