diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-25 12:40:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-25 12:46:51 -0300 |
| commit | f5f8068fac59b4f16046c2022c2fc7c7e447ef4c (patch) | |
| tree | 2731a3ed4e51cae09e184e25778eded5fc37d1f5 /examples/minimal.zig | |
| download | esp32p4-f5f8068fac59b4f16046c2022c2fc7c7e447ef4c.tar.gz esp32p4-f5f8068fac59b4f16046c2022c2fc7c7e447ef4c.zip | |
zig-p4: pure-Zig ESP32-P4 toolchain
build.zig generates the linker script and drives Zig's own LLD; tools/image.zig
turns the ELF into a flashable image and tools/{rom,serial}.zig speak the mask
ROM loader over the UART. No CMake, ninja, idf.py, esptool, or external linker.
src/soc.zig is a comptime register model over ESP-IDF's own *_reg.h headers;
src/hal/ adds peripheral sequences; src/io/ implements std.Io for the chip;
src/oracle/ diffs this HAL against ESP-IDF's on the die.
Diffstat (limited to 'examples/minimal.zig')
| -rw-r--r-- | examples/minimal.zig | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/minimal.zig b/examples/minimal.zig new file mode 100644 index 0000000..a70f0ef --- /dev/null +++ b/examples/minimal.zig @@ -0,0 +1,42 @@ +//! The floor: the smallest thing that can boot on this chip and prove it is alive. +//! No printing, no descriptor text - just a pin that toggles. Build it with +//! zig build -Dapp=examples/minimal.zig size + +const std = @import("std"); +const config = @import("config"); +const soc = @import("soc"); + +/// Even the floor needs a panic handler: the default one formats and would pull in half of std. +pub const panic = std.debug.FullPanic(struct { + fn call(_: []const u8, _: ?usize) noreturn { + while (true) {} + } +}.call); +const led: u6 = @intCast(config.led_pin); + +export fn zig_main() noreturn { + soc.gpio.configureOutput(led); + while (true) { + soc.gpio.setHigh(led); + soc.rom.ets_delay_us(100_000); + soc.gpio.setLow(led); + soc.rom.ets_delay_us(100_000); + } +} + +export fn _start() linksection(".text.entry") callconv(.naked) noreturn { + asm volatile ( + \\ li t0, 1 << 13 + \\ csrs mstatus, t0 + \\ la sp, __stack_top + \\ la t0, __bss_start + \\ la t1, __bss_end + \\ bgeu t0, t1, 2f + \\1: + \\ sw zero, 0(t0) + \\ addi t0, t0, 4 + \\ bltu t0, t1, 1b + \\2: + \\ j zig_main + ); +} |
