Skip to content
Open
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
8 changes: 8 additions & 0 deletions examples/raspberrypi/rp2xxx/src/board_id.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ pub fn main() !void {
});
rp2xxx.uart.init_logger(uart);

const chip_id = rp2xxx.get_chip_id();
log.info("chip id: part={t} revision={d} manufacturer={t} stop_bit={}", .{
chip_id.part,
chip_id.revision,
chip_id.manufacturer,
chip_id.stop_bit,
});

while (true) {
log.info("unique board id: {x}", .{rp2xxx.get_board_id()});
time.sleep_ms(1000);
Expand Down
27 changes: 27 additions & 0 deletions port/raspberrypi/rp2xxx/src/hal.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const builtin = @import("builtin");
const microzig = @import("microzig");
const SIO = microzig.chip.peripherals.SIO;
const SYSINFO = microzig.chip.peripherals.SYSINFO;

pub const adc = @import("hal/adc.zig");
pub const bootmeta = @import("hal/bootmeta.zig");
Expand Down Expand Up @@ -139,6 +140,32 @@ pub fn get_cpu_id() u32 {
return SIO.CPUID.read().CPUID;
}

pub const ChipId = packed struct(u32) {
/// The stop bit that terminates the JEP-106 manufacturer code.
stop_bit: bool,

/// JEP-106 manufacturer code.
manufacturer: enum(u11) {
RaspberryPiFoundation = 0x493,
_,
},

/// JEP-106 part number.
part: enum(u16) {
RP2040 = 0x0002,
RP2350 = 0x0004,
_,
},

/// Chip revision (2 for RP2040 B2, 3 for RP2350 A3, etc).
revision: u4,
};

/// Reads the `SYSINFO.CHIP_ID` register.
pub fn get_chip_id() ChipId {
return @bitCast(SYSINFO.CHIP_ID.raw);
}

var board_id: ?[8]u8 = null;

/// Unique board identifier.
Expand Down
Loading