diff --git a/build.zig b/build.zig index 8cb289d..e04ab94 100644 --- a/build.zig +++ b/build.zig @@ -1,10 +1,10 @@ const std = @import("std"); -const microzig = @import("deps/microzig/build.zig"); +const microzig = @import("microzig"); pub const chips = @import("src/chips.zig"); pub const cpus = @import("src/cpus.zig"); -pub fn build(b: *std.build.Builder) void { +pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); var exe = microzig.addEmbeddedExecutable(b, .{ @@ -15,5 +15,16 @@ pub fn build(b: *std.build.Builder) void { .backing = .{ .chip = chips.esp32_c3 }, .optimize = optimize, }); - exe.installArtifact(b); + + const fw_objcopy = b.addObjCopy(exe.inner.getEmittedBin(), .{ + .format = .bin, + }); + + const fw_bin = fw_objcopy.getOutput(); + + const install_fw_bin = b.addInstallFile(fw_bin, "firmware/blinky.bin"); + + b.getInstallStep().dependOn(&install_fw_bin.step); + + b.installArtifact(exe.inner); } diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..e8787ef --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,10 @@ +.{ + .name = "microzig-espressif-esp", + .version = "0.1.0", + .dependencies = .{ + .microzig = .{ + .url = "https://github.com/ZigEmbeddedGroup/microzig/archive/0b3be0a4cc7e6d45714cb09961efc771e364723c.tar.gz", + .hash = "1220ada6d01db7b3d0aa8642df89b1af9ee71b681438249e9a7efb2275fc4cf32152", + }, + }, +} diff --git a/deps/microzig b/deps/microzig deleted file mode 160000 index 9392fe0..0000000 --- a/deps/microzig +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9392fe0f7bddde26155c181ab80b70097b49c791 diff --git a/src/chips.zig b/src/chips.zig index 14769f3..3baa05a 100644 --- a/src/chips.zig +++ b/src/chips.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const microzig = @import("../deps/microzig/build.zig"); +const microzig = @import("microzig"); const cpus = @import("cpus.zig"); fn root_dir() []const u8 { diff --git a/src/chips/ESP32_C3.zig b/src/chips/ESP32_C3.zig index 50a3263..8a632a0 100644 --- a/src/chips/ESP32_C3.zig +++ b/src/chips/ESP32_C3.zig @@ -33,77 +33,77 @@ pub const devices = struct { pub const peripherals = struct { /// UART (Universal Asynchronous Receiver-Transmitter) Controller - pub const UART0 = @intToPtr(*volatile types.peripherals.UART0, 0x60000000); + pub const UART0 = @as(*volatile types.peripherals.UART0, @ptrFromInt(0x60000000)); /// SPI (Serial Peripheral Interface) Controller - pub const SPI1 = @intToPtr(*volatile types.peripherals.SPI1, 0x60002000); + pub const SPI1 = @as(*volatile types.peripherals.SPI1, @ptrFromInt(0x60002000)); /// SPI (Serial Peripheral Interface) Controller - pub const SPI0 = @intToPtr(*volatile types.peripherals.SPI0, 0x60003000); + pub const SPI0 = @as(*volatile types.peripherals.SPI0, @ptrFromInt(0x60003000)); /// General Purpose Input/Output - pub const GPIO = @intToPtr(*volatile types.peripherals.GPIO, 0x60004000); + pub const GPIO = @as(*volatile types.peripherals.GPIO, @ptrFromInt(0x60004000)); /// Sigma-Delta Modulation - pub const GPIOSD = @intToPtr(*volatile types.peripherals.GPIOSD, 0x60004f00); + pub const GPIOSD = @as(*volatile types.peripherals.GPIOSD, @ptrFromInt(0x60004f00)); /// Real-Time Clock Control - pub const RTC_CNTL = @intToPtr(*volatile types.peripherals.RTC_CNTL, 0x60008000); + pub const RTC_CNTL = @as(*volatile types.peripherals.RTC_CNTL, @ptrFromInt(0x60008000)); /// eFuse Controller - pub const EFUSE = @intToPtr(*volatile types.peripherals.EFUSE, 0x60008800); + pub const EFUSE = @as(*volatile types.peripherals.EFUSE, @ptrFromInt(0x60008800)); /// Input/Output Multiplexer - pub const IO_MUX = @intToPtr(*volatile types.peripherals.IO_MUX, 0x60009000); + pub const IO_MUX = @as(*volatile types.peripherals.IO_MUX, @ptrFromInt(0x60009000)); /// Universal Host Controller Interface - pub const UHCI1 = @intToPtr(*volatile types.peripherals.UHCI0, 0x6000c000); + pub const UHCI1 = @as(*volatile types.peripherals.UHCI0, @ptrFromInt(0x6000c000)); /// UART (Universal Asynchronous Receiver-Transmitter) Controller - pub const UART1 = @intToPtr(*volatile types.peripherals.UART0, 0x60010000); + pub const UART1 = @as(*volatile types.peripherals.UART0, @ptrFromInt(0x60010000)); /// I2C (Inter-Integrated Circuit) Controller - pub const I2C0 = @intToPtr(*volatile types.peripherals.I2C0, 0x60013000); + pub const I2C0 = @as(*volatile types.peripherals.I2C0, @ptrFromInt(0x60013000)); /// Universal Host Controller Interface - pub const UHCI0 = @intToPtr(*volatile types.peripherals.UHCI0, 0x60014000); + pub const UHCI0 = @as(*volatile types.peripherals.UHCI0, @ptrFromInt(0x60014000)); /// Remote Control Peripheral - pub const RMT = @intToPtr(*volatile types.peripherals.RMT, 0x60016000); + pub const RMT = @as(*volatile types.peripherals.RMT, @ptrFromInt(0x60016000)); /// LED Control PWM (Pulse Width Modulation) - pub const LEDC = @intToPtr(*volatile types.peripherals.LEDC, 0x60019000); + pub const LEDC = @as(*volatile types.peripherals.LEDC, @ptrFromInt(0x60019000)); /// Timer Group - pub const TIMG0 = @intToPtr(*volatile types.peripherals.TIMG0, 0x6001f000); + pub const TIMG0 = @as(*volatile types.peripherals.TIMG0, @ptrFromInt(0x6001f000)); /// Timer Group - pub const TIMG1 = @intToPtr(*volatile types.peripherals.TIMG0, 0x60020000); + pub const TIMG1 = @as(*volatile types.peripherals.TIMG0, @ptrFromInt(0x60020000)); /// System Timer - pub const SYSTIMER = @intToPtr(*volatile types.peripherals.SYSTIMER, 0x60023000); + pub const SYSTIMER = @as(*volatile types.peripherals.SYSTIMER, @ptrFromInt(0x60023000)); /// SPI (Serial Peripheral Interface) Controller - pub const SPI2 = @intToPtr(*volatile types.peripherals.SPI2, 0x60024000); + pub const SPI2 = @as(*volatile types.peripherals.SPI2, @ptrFromInt(0x60024000)); /// Advanced Peripheral Bus Controller - pub const APB_CTRL = @intToPtr(*volatile types.peripherals.APB_CTRL, 0x60026000); + pub const APB_CTRL = @as(*volatile types.peripherals.APB_CTRL, @ptrFromInt(0x60026000)); /// Hardware random number generator - pub const RNG = @intToPtr(*volatile types.peripherals.RNG, 0x60026000); + pub const RNG = @as(*volatile types.peripherals.RNG, @ptrFromInt(0x60026000)); /// Two-Wire Automotive Interface - pub const TWAI = @intToPtr(*volatile types.peripherals.TWAI, 0x6002b000); + pub const TWAI = @as(*volatile types.peripherals.TWAI, @ptrFromInt(0x6002b000)); /// I2S (Inter-IC Sound) Controller - pub const I2S = @intToPtr(*volatile types.peripherals.I2S, 0x6002d000); + pub const I2S = @as(*volatile types.peripherals.I2S, @ptrFromInt(0x6002d000)); /// AES (Advanced Encryption Standard) Accelerator - pub const AES = @intToPtr(*volatile types.peripherals.AES, 0x6003a000); + pub const AES = @as(*volatile types.peripherals.AES, @ptrFromInt(0x6003a000)); /// SHA (Secure Hash Algorithm) Accelerator - pub const SHA = @intToPtr(*volatile types.peripherals.SHA, 0x6003b000); + pub const SHA = @as(*volatile types.peripherals.SHA, @ptrFromInt(0x6003b000)); /// RSA (Rivest Shamir Adleman) Accelerator - pub const RSA = @intToPtr(*volatile types.peripherals.RSA, 0x6003c000); + pub const RSA = @as(*volatile types.peripherals.RSA, @ptrFromInt(0x6003c000)); /// Digital Signature - pub const DS = @intToPtr(*volatile types.peripherals.DS, 0x6003d000); + pub const DS = @as(*volatile types.peripherals.DS, @ptrFromInt(0x6003d000)); /// HMAC (Hash-based Message Authentication Code) Accelerator - pub const HMAC = @intToPtr(*volatile types.peripherals.HMAC, 0x6003e000); + pub const HMAC = @as(*volatile types.peripherals.HMAC, @ptrFromInt(0x6003e000)); /// DMA (Direct Memory Access) Controller - pub const DMA = @intToPtr(*volatile types.peripherals.DMA, 0x6003f000); + pub const DMA = @as(*volatile types.peripherals.DMA, @ptrFromInt(0x6003f000)); /// Successive Approximation Register Analog to Digital Converter - pub const APB_SARADC = @intToPtr(*volatile types.peripherals.APB_SARADC, 0x60040000); + pub const APB_SARADC = @as(*volatile types.peripherals.APB_SARADC, @ptrFromInt(0x60040000)); /// Full-speed USB Serial/JTAG Controller - pub const USB_DEVICE = @intToPtr(*volatile types.peripherals.USB_DEVICE, 0x60043000); + pub const USB_DEVICE = @as(*volatile types.peripherals.USB_DEVICE, @ptrFromInt(0x60043000)); /// System - pub const SYSTEM = @intToPtr(*volatile types.peripherals.SYSTEM, 0x600c0000); + pub const SYSTEM = @as(*volatile types.peripherals.SYSTEM, @ptrFromInt(0x600c0000)); /// Sensitive - pub const SENSITIVE = @intToPtr(*volatile types.peripherals.SENSITIVE, 0x600c1000); + pub const SENSITIVE = @as(*volatile types.peripherals.SENSITIVE, @ptrFromInt(0x600c1000)); /// Interrupt Core - pub const INTERRUPT_CORE0 = @intToPtr(*volatile types.peripherals.INTERRUPT_CORE0, 0x600c2000); + pub const INTERRUPT_CORE0 = @as(*volatile types.peripherals.INTERRUPT_CORE0, @ptrFromInt(0x600c2000)); /// External Memory - pub const EXTMEM = @intToPtr(*volatile types.peripherals.EXTMEM, 0x600c4000); + pub const EXTMEM = @as(*volatile types.peripherals.EXTMEM, @ptrFromInt(0x600c4000)); /// XTS-AES-128 Flash Encryption - pub const XTS_AES = @intToPtr(*volatile types.peripherals.XTS_AES, 0x600cc000); + pub const XTS_AES = @as(*volatile types.peripherals.XTS_AES, @ptrFromInt(0x600cc000)); /// Debug Assist - pub const ASSIST_DEBUG = @intToPtr(*volatile types.peripherals.ASSIST_DEBUG, 0x600ce000); + pub const ASSIST_DEBUG = @as(*volatile types.peripherals.ASSIST_DEBUG, @ptrFromInt(0x600ce000)); }; }; }; diff --git a/src/cpus.zig b/src/cpus.zig index b087d90..c8bda91 100644 --- a/src/cpus.zig +++ b/src/cpus.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const microzig = @import("../deps/microzig/build.zig"); +const microzig = @import("microzig"); fn root_dir() []const u8 { return std.fs.path.dirname(@src().file) orelse unreachable; diff --git a/src/cpus/espressif-riscv.zig b/src/cpus/espressif-riscv.zig index dc2edb7..5aab92d 100644 --- a/src/cpus/espressif-riscv.zig +++ b/src/cpus/espressif-riscv.zig @@ -61,7 +61,7 @@ pub const startup_logic = struct { extern fn microzig_main() noreturn; - export fn _start() linksection("microzig_flash_start") callconv(.Naked) noreturn { + export fn _start() linksection("microzig_flash_start") callconv(.C) noreturn { microzig.cpu.disable_interrupts(); asm volatile ("mv sp, %[eos]" : diff --git a/src/example/blinky.zig b/src/example/blinky.zig index 5ee1eef..811b048 100644 --- a/src/example/blinky.zig +++ b/src/example/blinky.zig @@ -42,13 +42,13 @@ pub fn main() !void { while (true) { GPIO.OUT.modify(.{ .DATA_ORIG = (1 << LED_R_PIN) }); microzig.hal.uart.write(0, "R"); - microzig.core.experimental.debug.busy_sleep(1_000_000); + microzig.core.experimental.debug.busy_sleep(100_000); GPIO.OUT.modify(.{ .DATA_ORIG = (1 << LED_G_PIN) }); microzig.hal.uart.write(0, "G"); - microzig.core.experimental.debug.busy_sleep(1_000_000); + microzig.core.experimental.debug.busy_sleep(100_000); GPIO.OUT.modify(.{ .DATA_ORIG = (1 << LED_B_PIN) }); microzig.hal.uart.write(0, "B"); - microzig.core.experimental.debug.busy_sleep(1_000_000); + microzig.core.experimental.debug.busy_sleep(100_000); } } diff --git a/src/hals/ESP32_C3.zig b/src/hals/ESP32_C3.zig index 516ed15..a5e1bb9 100644 --- a/src/hals/ESP32_C3.zig +++ b/src/hals/ESP32_C3.zig @@ -21,9 +21,9 @@ pub const gpio = struct { assertRange(pin); GPIO.FUNC_OUT_SEL_CFG[pin].modify(.{ .OUT_SEL = config.function, - .INV_SEL = @boolToInt(config.invert_function), - .OEN_SEL = @boolToInt(config.direct_io), - .OEN_INV_SEL = @boolToInt(config.invert_direct_io), + .INV_SEL = @intFromBool(config.invert_function), + .OEN_SEL = @intFromBool(config.direct_io), + .OEN_INV_SEL = @intFromBool(config.invert_direct_io), }); switch (config.direction) { .input => GPIO.ENABLE.raw &= ~(@as(u32, 1) << pin), diff --git a/zpm.zig b/zpm.zig deleted file mode 100644 index 1dcd7b3..0000000 --- a/zpm.zig +++ /dev/null @@ -1,8 +0,0 @@ -//! This file is auto-generated by zpm-update and *should* -//! not be changed. This file can be checked into your VCS -//! and is able to work standalone. -const std = @import("std"); - -pub const sdks = struct { - pub const microzig = @import("vendor/microzig/src/main.zig"); -};