rp2xxx: `pio.assembler.Output.get_define_by_name` does not compile (declared `u32`, breaks with a `Define`)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- zig
- Domain
- embedded-iot
Research direction
Read port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig around Output.get_define_by_name and its Define type. The issue includes a regression test example; add coverage for looking up T1 and run zig build test in port/raspberrypi/rp2xxx. Done means the function compiles, returns the define value, and the test passes.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Zig
- Stars
- 2.3k
- Forks
- 198
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 37
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ZigEmbeddedGroup/microzig
-
Difficulty 1/5 Under an hour Newbie friendliness 69/100
ZigEmbeddedGroup/microzig#1085 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ZigEmbeddedGroup/microzig#1061 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ZigEmbeddedGroup/microzig#1059 · 1 comment ·
Maintainers usually reply within 1 day
-
regz: AVR peripherals generated at address 0 when the register-group name matches the module (ATDF)Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
ZigEmbeddedGroup/microzig#1072 ·
Maintainers usually reply within 1 day
-
AVR (ATmega328P): UART/SPI HAL, drivers.zig, and nRF24L01+ driver (Emakefun RF-Nano V3.0)Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
ZigEmbeddedGroup/microzig#1069 · 3 comments ·
Maintainers usually reply within 1 day
All issues in ZigEmbeddedGroup/microzig
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
InfiniTimeOrg/InfiniTime#2492 ·
-
Arch: xtensa Area: Board support Area: Build system OS: Linux Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
device support request
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
zigpy/zha-device-handlers#5461 ·
Maintainers usually reply within 4 days
-
external converter
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Koenkk/zigbee2mqtt#33396 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day