Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

rp2xxx: `pio.assembler.Output.get_define_by_name` does not compile (declared `u32`, breaks with a `Define`)

未关闭 适合新手
#1,086 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
zig
领域
embedded-iot

调研方向

阅读 port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig 中 Output.get_define_by_name 及其 Define 类型附近的代码。Issue 包含一个回归测试示例;请添加查找 T1 的测试覆盖,并在 port/raspberrypi/rp2xxx 中运行 zig build test。函数能够编译、返回 define 值且测试通过,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Summary

Output.get_define_by_name (port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig:58-66 on
master) is declared to return u32, but its loop does break define;, which is a
Define{ name, value: i64 }. Every call fails inside the package:

assembler.zig:64:23: error: expected type 'u32', found 'hal.pio.assembler.Define'

Nothing in the tree calls it (grep -rn get_define_by_name finds only the
declaration), so CI never compiles it. The function has been in this shape since at
least 185e906e5 (2024-02-25). Users who want a define by name end up indexing
.defines[i] by position, and that silently reads the wrong constant once the
program's .define lines are reordered.

Versions
tree toolchain result
microzig 0.15.1 release zig 0.15.2 compile error (rc=1), assembler.zig:66:23
microzig master f36d59fb7b22 (tag 0.17.17, 2026-10-10) zig 0.17.0 compile error (rc=1), assembler.zig:64:23
master + the fix below zig 0.17.0 builds (rc=0)
Repro

A minimal firmware with microzig as a path dependency, built for boards.raspberrypi.pico:

const microzig = @import("microzig");
const hal = microzig.hal;

const out = hal.pio.assemble(
    \\.define PUBLIC T1 3
    \\.program p
    \\    nop
, .{});

comptime {
    if (@hasDecl(microzig, "export_startup")) _ = microzig.export_startup();
}

pub fn main() void {
    const t1 = comptime out.get_define_by_name("T1");
    if (t1 != 3) @compileError("expected T1 == 3");
    while (true) {}
}

Expected: builds; T1 == 3.
Actual (master, zig 0.17.0):

deps/microzig/port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig:64:23: error: expected type 'u32', found 'hal.pio.assembler.Define'
                break define;
                      ^~~~~~
repro.zig:18:47: note: called at comptime here
    const t1 = comptime out.get_define_by_name("T1");
Fix

Return the define's value, typed as Define.value is (i64), so no cast or range
check is needed. The patch also adds a test, so CI compiles the function from now on:

-    ) u32 {
+    ) i64 {
         return for (output.defines) |define| {
             if (std.mem.eql(u8, name, define.name))
-                break define;
+                break define.value;
test "get_define_by_name" {
    const output = comptime assemble(.RP2040,
        \\.define PUBLIC T1 3
        \\.program testprog
        \\    nop
    , .{});
    try std.testing.expectEqual(@as(i64, 3), comptime output.get_define_by_name("T1"));
}

zig build test in port/raspberrypi/rp2xxx: master gives 135/135 passed; with the
patch it gives 136/136 passed (rc=0).

(Alternative, if you would rather mirror get_program_by_name: return Define
and have callers write .value. The patch keeps the name's promise of a value.)

I have the patch ready and can open it as a PR if you'd like.

主要语言
Zig
星标
2.3k
派生
198
平均合并
1 天 8 小时
30 天内合并 PR
37

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ZigEmbeddedGroup/microzig 的其他 Issue

查看 ZigEmbeddedGroup/microzig 的全部 Issue

相似的 Issue

更多 Embedded & IoT Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。