From 29481b850f05ee2c6edef230b916fe0455582451 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Fri, 24 Apr 2026 13:12:28 -0700 Subject: [PATCH 01/19] core: make the user's main.zig the executable root The firmware executable's root module is now the user's application source, not microzig's start.zig shim. This aligns microzig with the standard Zig build idiom: `@import("root")` from any module resolves to user code, `pub const panic` / `pub const std_options` live where Zig expects to find them, and tooling that assumes root-is-the-app now works naturally. Core changes: - microzig.zig reads `microzig_options` via `@import("root")` instead of the injected `app` module, and drops the `pub const app` alias. - utilities.install_startup / core/src/start.zig are replaced by a single user-facing primitive, `microzig.export_startup()`, which the application opts into from a comptime block. It emits the CPU startup symbols and the `microzig_main` wrapper that the CPU `_start` calls once `.data`/`.bss` are initialized. - Startup logic (HAL init / root init / error-returning main / panic wrapping) moves out of start.zig into microzig_main, with identical semantics. - A new `microzig.std_options()` helper returns a `std.Options` with microzig's freestanding-safe defaults (the critical one being a no-op `logFn` that replaces stdlib's stderr-writing default, which fails to link on freestanding). The accompanying `StdOptions` struct documents which std.Options fields are exposed and which are intentionally excluded as hosted-only. - The log-related fields (`log_level`, `log_scope_levels`, `logFn`) are removed from `microzig.Options`; they now live exclusively in `std.Options` via the helper. Build system: - `add_firmware` sets `exe.root_module = app_mod` directly. The separate start.zig root module and the "app"-import plumbing on `core_mod` / `cpu_mod` / `chip_mod` / `hal_mod` / `board_mod` are all gone. Example boilerplate (now two re-exports and one comptime line): pub const panic = microzig.panic; pub const std_options = microzig.std_options(.{}); comptime { _ = microzig.export_startup(); } All 131 example main.zig files have been migrated. Examples that previously declared `pub const microzig_options` with log-related fields have had those fields moved into `microzig.std_options(...)`, with any remaining microzig-specific fields (interrupts, hal, cpu, etc.) kept in a trimmed `pub const microzig_options`. The website getting-started snippet is updated to match. This commit only performs the structural move. It is NOT expected to build against 0.15.x or current 0.16.x compilers as-is; the separate 0.16 migration work comes next. Co-Authored-By: Claude Opus 4.7 (1M context) --- build.zig | 27 +- core/src/cpus/cortex_m.zig | 1 - core/src/microzig.zig | 148 +++++- core/src/start.zig | 95 ---- examples/espressif/esp/src/blinky.zig | 10 +- .../espressif/esp/src/custom_clock_config.zig | 10 +- examples/espressif/esp/src/gpio_input.zig | 8 + examples/espressif/esp/src/i2c_bus_scan.zig | 10 +- .../espressif/esp/src/i2c_display_sh1106.zig | 10 +- examples/espressif/esp/src/i2c_temp.zig | 10 +- examples/espressif/esp/src/ledc_pwm_servo.zig | 8 + examples/espressif/esp/src/rtos.zig | 13 +- examples/espressif/esp/src/stepper_driver.zig | 10 +- .../espressif/esp/src/stepper_driver_dumb.zig | 10 +- examples/espressif/esp/src/systimer.zig | 11 +- examples/espressif/esp/src/tcp_server.zig | 11 +- examples/espressif/esp/src/ws2812_blinky.zig | 10 +- examples/gigadevice/gd32/src/blinky.zig | 8 + examples/gigadevice/gd32/src/empty.zig | 8 + examples/microchip/atmega/src/blinky.zig | 8 + examples/microchip/samd51/src/blinky.zig | 8 + examples/no_hal/stm32_l031/src/blinky.zig | 8 + examples/nordic/nrf5x/src/blinky.zig | 8 + examples/nordic/nrf5x/src/i2c_accel.zig | 10 +- examples/nordic/nrf5x/src/i2c_bus_scan.zig | 10 +- examples/nordic/nrf5x/src/i2c_hall_effect.zig | 10 +- .../nordic/nrf5x/src/i2c_position_sensor.zig | 10 +- examples/nordic/nrf5x/src/i2c_temp.zig | 10 +- .../nordic/nrf5x/src/microbit/display.zig | 8 + examples/nordic/nrf5x/src/rtt_log.zig | 16 +- examples/nordic/nrf5x/src/semihosting.zig | 8 + examples/nordic/nrf5x/src/spi_master.zig | 10 +- examples/nordic/nrf5x/src/uart.zig | 10 +- examples/nxp/lpc/src/blinky.zig | 8 + examples/nxp/mcx/src/gpio_input.zig | 10 +- examples/nxp/mcx/src/lp_i2c.zig | 8 + examples/nxp/mcx/src/lp_uart.zig | 8 + examples/nxp/mcx/src/mcxa153_blinky.zig | 8 + examples/nxp/mcx/src/mcxn947_blinky.zig | 8 + examples/raspberrypi/rp2xxx/src/adc.zig | 10 +- examples/raspberrypi/rp2xxx/src/allocator.zig | 12 +- examples/raspberrypi/rp2xxx/src/blinky.zig | 8 + .../raspberrypi/rp2xxx/src/blinky_core1.zig | 8 + .../raspberrypi/rp2xxx/src/board_blinky.zig | 8 + examples/raspberrypi/rp2xxx/src/board_id.zig | 15 +- .../rp2xxx/src/changing_system_clocks.zig | 8 + .../rp2xxx/src/custom_clock_config.zig | 8 + examples/raspberrypi/rp2xxx/src/cyw43.zig | 10 +- .../raspberrypi/rp2xxx/src/cyw43/blinky.zig | 8 + .../rp2xxx/src/cyw43/wifi_connect.zig | 10 +- .../rp2xxx/src/cyw43/wifi_scan.zig | 10 +- examples/raspberrypi/rp2xxx/src/dma.zig | 16 +- examples/raspberrypi/rp2xxx/src/ds18b20.zig | 8 + .../raspberrypi/rp2xxx/src/flash_program.zig | 16 +- .../rp2xxx/src/freertos/hello_task.zig | 11 +- .../rp2xxx/src/freertos/multitask_demo.zig | 11 +- .../rp2xxx/src/freertos/queue_demo.zig | 11 +- .../rp2xxx/src/gpio_clock_output.zig | 8 + examples/raspberrypi/rp2xxx/src/gpio_irq.zig | 12 +- examples/raspberrypi/rp2xxx/src/i2c_accel.zig | 10 +- .../raspberrypi/rp2xxx/src/i2c_bus_scan.zig | 10 +- .../rp2xxx/src/i2c_hall_effect.zig | 10 +- examples/raspberrypi/rp2xxx/src/mlx90640.zig | 10 +- .../rp2xxx/src/mlx90640_hottest_point.zig | 10 +- .../raspberrypi/rp2xxx/src/mlx90640_image.zig | 10 +- examples/raspberrypi/rp2xxx/src/net/irq.zig | 8 + examples/raspberrypi/rp2xxx/src/net/pong.zig | 11 +- examples/raspberrypi/rp2xxx/src/net/scan.zig | 11 +- .../raspberrypi/rp2xxx/src/net/tcp_client.zig | 11 +- .../raspberrypi/rp2xxx/src/net/tcp_server.zig | 11 +- examples/raspberrypi/rp2xxx/src/net/udp.zig | 11 +- examples/raspberrypi/rp2xxx/src/pwm.zig | 8 + .../rp2xxx/src/rp2040_only/hd44780.zig | 8 + .../rp2xxx/src/rp2040_only/i2c_slave.zig | 11 +- .../rp2xxx/src/rp2040_only/pcf8574.zig | 8 + .../rp2xxx/src/rp2040_only/random.zig | 16 +- .../rp2xxx/src/rp2040_only/rtc.zig | 10 +- .../rp2xxx/src/rp2040_only/tiles.zig | 8 + .../src/rp2350_only/always_on_timer.zig | 10 +- .../rp2xxx/src/rp2350_only/random_data.zig | 10 +- examples/raspberrypi/rp2xxx/src/rtt_log.zig | 16 +- .../rp2xxx/src/spi_loopback_dma.zig | 10 +- .../raspberrypi/rp2xxx/src/spi_master.zig | 8 + examples/raspberrypi/rp2xxx/src/spi_slave.zig | 10 +- .../raspberrypi/rp2xxx/src/squarewave.zig | 8 + .../raspberrypi/rp2xxx/src/ssd1306_oled.zig | 8 + .../raspberrypi/rp2xxx/src/st7789_lcd.zig | 10 +- .../raspberrypi/rp2xxx/src/stepper_driver.zig | 14 +- .../rp2xxx/src/stepper_driver_dumb.zig | 14 +- .../raspberrypi/rp2xxx/src/system_timer.zig | 8 + examples/raspberrypi/rp2xxx/src/uart_echo.zig | 8 + examples/raspberrypi/rp2xxx/src/uart_log.zig | 16 +- examples/raspberrypi/rp2xxx/src/usb_cdc.zig | 20 +- examples/raspberrypi/rp2xxx/src/usb_hid.zig | 26 +- .../raspberrypi/rp2xxx/src/watchdog_timer.zig | 8 + examples/raspberrypi/rp2xxx/src/ws2812.zig | 8 + examples/stmicro/stm32/src/blinky.zig | 8 + examples/stmicro/stm32/src/hts221.zig | 11 +- examples/stmicro/stm32/src/semihosting.zig | 8 + examples/stmicro/stm32/src/stm32f1xx/EXTI.zig | 8 + examples/stmicro/stm32/src/stm32f1xx/adc.zig | 10 +- .../stm32/src/stm32f1xx/adc_dualmode.zig | 10 +- .../stm32/src/stm32f1xx/advanced_adc.zig | 11 +- examples/stmicro/stm32/src/stm32f1xx/gpio.zig | 8 + .../stmicro/stm32/src/stm32f1xx/hd44780.zig | 8 + examples/stmicro/stm32/src/stm32f1xx/i2c.zig | 10 +- .../stm32/src/stm32f1xx/i2c_bus_scan.zig | 10 +- examples/stmicro/stm32/src/stm32f1xx/rcc.zig | 10 +- examples/stmicro/stm32/src/stm32f1xx/rtc.zig | 10 +- examples/stmicro/stm32/src/stm32f1xx/spi.zig | 8 + .../stmicro/stm32/src/stm32f1xx/ssd1306.zig | 10 +- .../stmicro/stm32/src/stm32f1xx/timer.zig | 13 +- .../stm32/src/stm32f1xx/timer_capture.zig | 11 +- .../stmicro/stm32/src/stm32f1xx/uart_echo.zig | 8 + .../stmicro/stm32/src/stm32f1xx/uart_log.zig | 10 +- .../stmicro/stm32/src/stm32f1xx/usb_cdc.zig | 8 + .../stmicro/stm32/src/stm32f1xx/usb_hid.zig | 6 + .../stm32/src/stm32f1xx/usb_remote_hid.zig | 463 ++++++++++++++++++ examples/stmicro/stm32/src/stm32l476/lcd.zig | 8 + .../texasinstruments/msp430/src/blinky.zig | 7 + .../texasinstruments/msp430/src/empty.zig | 9 + examples/texasinstruments/tm4c/src/empty.zig | 10 + examples/wch/ch32v/src/blinky.zig | 8 + examples/wch/ch32v/src/blinky_systick.zig | 8 + examples/wch/ch32v/src/board_blinky.zig | 8 + examples/wch/ch32v/src/dma.zig | 10 +- examples/wch/ch32v/src/empty.zig | 8 + examples/wch/ch32v/src/i2c_bus_scan.zig | 10 +- examples/wch/ch32v/src/i2c_eeprom.zig | 10 +- .../wch/ch32v/src/i2c_position_sensor.zig | 10 +- examples/wch/ch32v/src/sharp_niceview.zig | 10 +- examples/wch/ch32v/src/spi_flash_w25q.zig | 10 +- examples/wch/ch32v/src/spi_loopback.zig | 10 +- examples/wch/ch32v/src/uart_log.zig | 10 +- examples/wch/ch32v/src/ws2812.zig | 8 + website/content/docs/getting-started.smd | 7 + 136 files changed, 1715 insertions(+), 319 deletions(-) delete mode 100644 core/src/start.zig create mode 100644 examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig diff --git a/build.zig b/build.zig index 1a3159776..1de33fb15 100644 --- a/build.zig +++ b/build.zig @@ -476,13 +476,24 @@ pub fn MicroBuild(port_select: PortSelect) type { core_mod.addImport("board", board_mod); } + // The user's main.zig is the executable's root module. The + // application opts into microzig's startup via + // comptime { _ = microzig.export_startup(); } + // in its root source file, and re-exports microzig's `panic`. + // microzig's core module reads the root via `@import("root")`, + // so there's no "app" import to wire. const app_mod = mb.builder.createModule(.{ .root_source_file = options.root_source_file, .imports = options.imports, .target = zig_resolved_target, + .optimize = options.optimize, + .single_threaded = options.single_threaded orelse target.single_threaded, + .strip = options.strip, + .unwind_tables = options.unwind_tables, + .error_tracing = options.error_tracing, + .dwarf_format = options.dwarf_format, }); app_mod.addImport("microzig", core_mod); - core_mod.addImport("app", app_mod); const fw = mb.builder.allocator.create(Firmware) catch @panic("out of memory"); fw.* = .{ @@ -490,16 +501,7 @@ pub fn MicroBuild(port_select: PortSelect) type { .core_mod = core_mod, .artifact = mb.builder.addExecutable(.{ .name = options.name, - .root_module = b.createModule(.{ - .optimize = options.optimize, - .target = zig_resolved_target, - .root_source_file = mb.core_dep.path("src/start.zig"), - .single_threaded = options.single_threaded orelse target.single_threaded, - .strip = options.strip, - .unwind_tables = options.unwind_tables, - .error_tracing = options.error_tracing, - .dwarf_format = options.dwarf_format, - }), + .root_module = app_mod, .linkage = .static, }), .app_mod = app_mod, @@ -515,9 +517,6 @@ pub fn MicroBuild(port_select: PortSelect) type { fw.artifact.link_data_sections = options.strip_unused_symbols; fw.artifact.entry = options.entry orelse target.entry orelse .default; - fw.artifact.root_module.addImport("microzig", core_mod); - fw.artifact.root_module.addImport("app", app_mod); - const linker_script_options = options.linker_script orelse target.linker_script; const linker_script = blk: { const GenerateLinkerScriptArgs = @import("tools/generate_linker_script.zig").Args; diff --git a/core/src/cpus/cortex_m.zig b/core/src/cpus/cortex_m.zig index 2a8e2e425..d483b861a 100644 --- a/core/src/cpus/cortex_m.zig +++ b/core/src/cpus/cortex_m.zig @@ -2,7 +2,6 @@ const std = @import("std"); const builtin = @import("builtin"); const microzig = @import("microzig"); const mmio = microzig.mmio; -const app = microzig.app; const shared = @import("cortex_m/shared_types.zig"); const VectorTable = microzig.chip.VectorTable; diff --git a/core/src/microzig.zig b/core/src/microzig.zig index b761913df..bb70d9558 100644 --- a/core/src/microzig.zig +++ b/core/src/microzig.zig @@ -7,9 +7,6 @@ const std = @import("std"); const root = @import("root"); const builtin = @import("builtin"); -/// The app that is currently built. -pub const app = @import("app"); - /// Contains build-time generated configuration options for microzig. /// Contains a CPU target description, chip, board and cpu information /// and so on. @@ -67,26 +64,6 @@ pub const CPU_Options = if (@hasDecl(cpu, "CPU_Options")) cpu.CPU_Options else s pub const HAL_Options = if (config.has_hal and @hasDecl(hal, "HAL_Options")) hal.HAL_Options else struct {}; pub const Options = struct { - log_level: std.log.Level = std.log.default_level, - log_scope_levels: []const std.log.ScopeLevel = &.{}, - logFn: fn ( - comptime message_level: std.log.Level, - comptime scope: @TypeOf(.enum_literal), - comptime format: []const u8, - args: anytype, - ) void = struct { - fn log( - comptime message_level: std.log.Level, - comptime scope: @Type(.enum_literal), - comptime format: []const u8, - args: anytype, - ) void { - _ = message_level; - _ = scope; - _ = format; - _ = args; - } - }.log, interrupts: InterruptOptions = .{}, overwrite_hal_interrupts: bool = false, //force overwrite the Hal default interrupts cpu: CPU_Options = .{}, @@ -103,7 +80,71 @@ pub const Options = struct { simple_panic_if_main_errors: bool = false, }; -pub const options: Options = if (@hasDecl(app, "microzig_options")) app.microzig_options else .{}; +pub const options: Options = if (@hasDecl(root, "microzig_options")) root.microzig_options else .{}; + +/// Overrides accepted by `microzig.std_options`. Mirrors only the subset of +/// `std.Options` fields that are meaningful on freestanding/embedded targets. +/// +/// Included fields (and why): +/// * `log_level` — controls verbosity of `std.log` calls. +/// * `log_scope_levels` — per-scope filtering for fine-grained logging. +/// * `logFn` — the logging callback. This is the *critical* one: stdlib's +/// default writes to stderr, which doesn't exist on freestanding targets +/// and causes link failures whenever any reachable code touches +/// `std.log.*`. Microzig defaults this to a no-op. +/// +/// Fields from `std.Options` that are intentionally NOT exposed here: +/// * `enable_segfault_handler`, `signal_stack_size` — POSIX signal +/// plumbing; no OS-level signals on freestanding. +/// * `page_size_min`, `page_size_max`, `queryPageSize` — OS virtual-memory +/// page-size configuration; embedded firmware doesn't have VM. +/// * `fmt_max_depth` — stdlib fmt recursion bound; rarely customized and +/// orthogonal to embedded concerns. +/// * `http_disable_tls`, `http_enable_ssl_key_log_file` — `std.http.Client` +/// tuning; the HTTP client is hosted-only. +/// * `side_channels_mitigations` — `std.crypto` side-channel mitigations; +/// hosted-oriented, and embedded projects typically select crypto at +/// the module level. +/// * `allow_stack_tracing` — pulls in `std.debug.ElfFile` / debug-info +/// loaders that assume a hosted filesystem. +/// * `networking` — gates `std.Io` networking; hosted-only. (Microzig +/// embedded networking is in `modules/network`.) +/// * `unexpected_error_tracing` — default debug-mode tracing that relies +/// on stderr. +/// +/// Users who genuinely need one of the excluded fields can still declare +/// their own `pub const std_options = std.Options{ ... }` directly and skip +/// this helper. +pub const StdOptions = struct { + log_level: std.log.Level = std.log.default_level, + log_scope_levels: []const std.log.ScopeLevel = &.{}, + logFn: fn ( + comptime message_level: std.log.Level, + comptime scope: @EnumLiteral(), + comptime format: []const u8, + args: anytype, + ) void = no_op_log, +}; + +/// Build a `std.Options` with microzig's freestanding-safe defaults. Users +/// re-export from their root source file: +/// +/// pub const std_options = microzig.std_options(.{}); // defaults only +/// pub const std_options = microzig.std_options(.{ .log_level = .info }); // with overrides +pub fn std_options(comptime overrides: StdOptions) std.Options { + return .{ + .log_level = overrides.log_level, + .log_scope_levels = overrides.log_scope_levels, + .logFn = overrides.logFn, + }; +} + +fn no_op_log( + comptime _: std.log.Level, + comptime _: @EnumLiteral(), + comptime _: []const u8, + _: anytype, +) void {} /// Hangs the processor and will stop doing anything useful. Use with caution! pub fn hang() noreturn { @@ -114,6 +155,65 @@ pub fn hang() noreturn { } } +/// Emit microzig's firmware startup symbols. Must be invoked from a +/// `comptime` block in the root source file of every firmware: +/// +/// comptime { _ = microzig.export_startup(); } +/// +/// Emits the CPU-specific `_start` symbol (and vector table where +/// applicable) and the `microzig_main` wrapper that the CPU startup calls +/// once `.data`/`.bss` have been initialized. +pub fn export_startup() void { + cpu.export_startup_logic(); + @export(µzig_main, .{ .name = "microzig_main" }); +} + +/// Called from the CPU-specific `_start` once `.data`/`.bss` are live. Reads +/// `main` from the root source file and supports HAL `init` / root `init` / +/// error-returning `main`. +fn microzig_main() callconv(.c) noreturn { + // A HAL may define `init` (e.g. clocks, PLL) that runs before main. The + // user's root source file may define its own `init` to override the HAL + // default. + if (@hasDecl(root, "init")) + root.init() + else if (hal != void and @hasDecl(hal, "init")) + hal.init(); + + const main = @field(root, "main"); + const return_type = @typeInfo(@TypeOf(main)).@"fn".return_type orelse + @compileError("microzig: `main` must have a return type"); + + if (@typeInfo(return_type) == .error_union) { + main() catch |err| { + const msg_base = "main() returned error."; + + if (!options.simple_panic_if_main_errors) { + const max_error_size = comptime blk: { + var max: usize = 0; + const err_type = @typeInfo(return_type).error_union.error_set; + if (@typeInfo(err_type).error_set) |err_set| { + for (err_set) |current_err| { + max = @max(max, current_err.name.len); + } + } + break :blk max; + }; + + var buf: [msg_base.len + max_error_size]u8 = undefined; + const msg = std.fmt.bufPrint(&buf, "{s}{s}", .{ msg_base, @errorName(err) }) catch @panic(msg_base); + @panic(msg); + } else { + @panic(msg_base); + } + }; + } else { + main(); + } + + hang(); +} + test { _ = utilities; _ = Allocator; diff --git a/core/src/start.zig b/core/src/start.zig deleted file mode 100644 index 004e20a5f..000000000 --- a/core/src/start.zig +++ /dev/null @@ -1,95 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const microzig = @import("microzig"); -const app = @import("app"); - -// Use microzig panic handler if not defined by an application -pub const panic = if (!@hasDecl(app, "panic")) microzig.panic else app.panic; - -// Conditionally provide a default no-op logFn if app does not have one -// defined. Parts of microzig use the stdlib logging facility and -// compilations will now fail on freestanding systems that use it but do -// not explicitly set `root.std_options.logFn` -pub const std_options: std.Options = .{ - .log_level = microzig.options.log_level, - .log_scope_levels = microzig.options.log_scope_levels, - .logFn = microzig.options.logFn, -}; - -// Startup logic: -comptime { - // Instantiate the startup logic for the given CPU type. - // This usually implements the `_start` symbol that will populate - // the sections .data and .bss with the correct data. - // .rodata is not always necessary to be populated (flash based systems - // can just index flash, while harvard or flash-less architectures need - // to copy .rodata into RAM). - microzig.cpu.export_startup_logic(); -} - -/// This is the logical entry point for microzig. -/// It will invoke the main function from the root source file -/// and provides error return handling as well as a event loop if requested. -/// -/// Why is this function exported? -/// This is due to the modular design of microzig to allow the "chip" dependency of microzig -/// to call into our main function here. If we would use a normal function call, we'd have a -/// circular dependency between the `microzig` and `chip` package. This function is also likely -/// to be invoked from assembly, so it's also convenient in that regard. -export fn microzig_main() noreturn { - if (!@hasDecl(app, "main")) - @compileError("The root source file must provide a public function main!"); - - const main = @field(app, "main"); - const info: std.builtin.Type = @typeInfo(@TypeOf(main)); - - const invalid_main_msg = "main must be either 'pub fn main() void' or 'pub fn main() !void'."; - if (info != .@"fn" or info.@"fn".params.len > 0) - @compileError(invalid_main_msg); - - const return_type = info.@"fn".return_type orelse @compileError(invalid_main_msg); - - // A hal can export a default init function that runs before main for - // procedures like clock configuration. The user may override and customize - // this functionality by providing their own init function. - // function. - if (@hasDecl(app, "init")) - app.init() - else if (microzig.hal != void and @hasDecl(microzig.hal, "init")) - microzig.hal.init(); - - if (@typeInfo(return_type) == .error_union) { - main() catch |err| { - // Although here we could use @errorReturnTrace similar to - // `std.start` and just dump the trace (without panic), the user - // might not use logging and have the panic handler just blink an - // led. - - const msg_base = "main() returned error."; - - if (!microzig.options.simple_panic_if_main_errors) { - const max_error_size = comptime blk: { - var max_error_size: usize = 0; - const err_type = @typeInfo(return_type).error_union.error_set; - if (@typeInfo(err_type).error_set) |err_set| { - for (err_set) |current_err| { - max_error_size = @max(max_error_size, current_err.name.len); - } - } - break :blk max_error_size; - }; - - var buf: [msg_base.len + max_error_size]u8 = undefined; - const msg = std.fmt.bufPrint(&buf, "{s}{s}", .{ msg_base, @errorName(err) }) catch @panic(msg_base); - @panic(msg); - } else { - @panic(msg_base); - } - }; - } else { - main(); - } - - // Main returned, just hang around here a bit. - microzig.hang(); -} diff --git a/examples/espressif/esp/src/blinky.zig b/examples/espressif/esp/src/blinky.zig index 5256f0473..093aead0b 100644 --- a/examples/espressif/esp/src/blinky.zig +++ b/examples/espressif/esp/src/blinky.zig @@ -5,9 +5,15 @@ const gpio = hal.gpio; const usb_serial_jtag = hal.usb_serial_jtag; const time = hal.time; -pub const microzig_options: microzig.Options = .{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { const pin_config: gpio.Pin.Config = .{ diff --git a/examples/espressif/esp/src/custom_clock_config.zig b/examples/espressif/esp/src/custom_clock_config.zig index 08fb0e90d..e9f37140c 100644 --- a/examples/espressif/esp/src/custom_clock_config.zig +++ b/examples/espressif/esp/src/custom_clock_config.zig @@ -4,9 +4,15 @@ const hal = microzig.hal; const clocks = hal.clocks; const usb_serial_jtag = hal.usb_serial_jtag; -pub const microzig_options: microzig.Options = .{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} // Clock config with a cpu speed of 20mhz. const clock_config: clocks.Config = .init_comptime(20_000_000); diff --git a/examples/espressif/esp/src/gpio_input.zig b/examples/espressif/esp/src/gpio_input.zig index e913c7d54..2e74f99b6 100644 --- a/examples/espressif/esp/src/gpio_input.zig +++ b/examples/espressif/esp/src/gpio_input.zig @@ -3,6 +3,14 @@ const microzig = @import("microzig"); const esp = microzig.hal; const gpio = esp.gpio; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { var input_pin = gpio.num(0); input_pin.apply(.{ diff --git a/examples/espressif/esp/src/i2c_bus_scan.zig b/examples/espressif/esp/src/i2c_bus_scan.zig index e1de06057..f4214419e 100644 --- a/examples/espressif/esp/src/i2c_bus_scan.zig +++ b/examples/espressif/esp/src/i2c_bus_scan.zig @@ -10,9 +10,15 @@ var i2c0 = i2c.instance.num(0); const usb_serial_jtag = esp.usb_serial_jtag; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { const sda_pin = gpio.num(5); diff --git a/examples/espressif/esp/src/i2c_display_sh1106.zig b/examples/espressif/esp/src/i2c_display_sh1106.zig index 222dc8ff9..76989076c 100644 --- a/examples/espressif/esp/src/i2c_display_sh1106.zig +++ b/examples/espressif/esp/src/i2c_display_sh1106.zig @@ -12,9 +12,15 @@ var i2c0 = i2c.instance.num(0); const usb_serial_jtag = esp.usb_serial_jtag; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { const sda_pin = gpio.num(5); diff --git a/examples/espressif/esp/src/i2c_temp.zig b/examples/espressif/esp/src/i2c_temp.zig index f2bab100b..2a2ee3a08 100644 --- a/examples/espressif/esp/src/i2c_temp.zig +++ b/examples/espressif/esp/src/i2c_temp.zig @@ -12,9 +12,15 @@ var i2c0 = i2c.instance.num(0); const usb_serial_jtag = esp.usb_serial_jtag; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { const sda_pin = gpio.num(5); diff --git a/examples/espressif/esp/src/ledc_pwm_servo.zig b/examples/espressif/esp/src/ledc_pwm_servo.zig index bae40572a..b5c534f70 100644 --- a/examples/espressif/esp/src/ledc_pwm_servo.zig +++ b/examples/espressif/esp/src/ledc_pwm_servo.zig @@ -14,6 +14,14 @@ const PWM_MAX_DUTY = std.math.pow(u32, 2, PWM_PRECISION_BITS) - 1; const PWM_MIN_LEVEL: u16 = @trunc(@as(f32, 1.0) / PWM_PERIOD_MS * PWM_MAX_DUTY); const PWM_MAX_LEVEL: u16 = @trunc(@as(f32, 2.0) / PWM_PERIOD_MS * PWM_MAX_DUTY); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { // pwm servo driver diff --git a/examples/espressif/esp/src/rtos.zig b/examples/espressif/esp/src/rtos.zig index 60b6e4a4e..37acdd0fc 100644 --- a/examples/espressif/esp/src/rtos.zig +++ b/examples/espressif/esp/src/rtos.zig @@ -5,12 +5,21 @@ const esp = microzig.hal; const usb_serial_jtag = esp.usb_serial_jtag; const rtos = esp.rtos; -pub const microzig_options: microzig.Options = .{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, + .log_level = .debug, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .interrupt31 = rtos.interrupt_handler, }, - .log_level = .debug, .cpu = .{ .interrupt_stack = .{ .enable = true, diff --git a/examples/espressif/esp/src/stepper_driver.zig b/examples/espressif/esp/src/stepper_driver.zig index a68e710db..e8e8e10a1 100644 --- a/examples/espressif/esp/src/stepper_driver.zig +++ b/examples/espressif/esp/src/stepper_driver.zig @@ -9,9 +9,15 @@ const A4988 = microzig.drivers.stepper.A4988; const usb_serial_jtag = hal.usb_serial_jtag; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { // Setup all pins for the stepper driver diff --git a/examples/espressif/esp/src/stepper_driver_dumb.zig b/examples/espressif/esp/src/stepper_driver_dumb.zig index 5ef35de9f..7892e268e 100644 --- a/examples/espressif/esp/src/stepper_driver_dumb.zig +++ b/examples/espressif/esp/src/stepper_driver_dumb.zig @@ -9,9 +9,15 @@ const ULN2003 = microzig.drivers.stepper.ULN2003; const usb_serial_jtag = hal.usb_serial_jtag; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { // Setup all pins for the stepper driver diff --git a/examples/espressif/esp/src/systimer.zig b/examples/espressif/esp/src/systimer.zig index 4638e7712..d4bcbea3a 100644 --- a/examples/espressif/esp/src/systimer.zig +++ b/examples/espressif/esp/src/systimer.zig @@ -4,8 +4,17 @@ const hal = microzig.hal; const systimer = hal.systimer; const usb_serial_jtag = hal.usb_serial_jtag; -pub const microzig_options: microzig.Options = .{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = usb_serial_jtag.logger.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .interrupt1 = .{ .c = timer_interrupt }, }, diff --git a/examples/espressif/esp/src/tcp_server.zig b/examples/espressif/esp/src/tcp_server.zig index e185a6277..ca57b29da 100644 --- a/examples/espressif/esp/src/tcp_server.zig +++ b/examples/espressif/esp/src/tcp_server.zig @@ -13,7 +13,9 @@ comptime { _ = exports; } -pub const microzig_options: microzig.Options = .{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .log_scope_levels = &.{ .{ .scope = .esp_radio, .level = .err }, @@ -22,6 +24,13 @@ pub const microzig_options: microzig.Options = .{ .{ .scope = .esp_radio_osi, .level = .err }, }, .logFn = usb_serial_jtag.logger.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .interrupt30 = radio.interrupt_handler, .interrupt31 = rtos.interrupt_handler, diff --git a/examples/espressif/esp/src/ws2812_blinky.zig b/examples/espressif/esp/src/ws2812_blinky.zig index bb08776cb..19ffb22f8 100644 --- a/examples/espressif/esp/src/ws2812_blinky.zig +++ b/examples/espressif/esp/src/ws2812_blinky.zig @@ -5,9 +5,15 @@ const Color = microzig.drivers.led.ws2812.Color; const hal = microzig.hal; const gpio = hal.gpio; -pub const microzig_options: microzig.Options = .{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = hal.usb_serial_jtag.logger.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const led_pin = gpio.num(8); const spi_bus = hal.spi.instance.SPI2; diff --git a/examples/gigadevice/gd32/src/blinky.zig b/examples/gigadevice/gd32/src/blinky.zig index 88bd5cd6a..ea3b6e06f 100644 --- a/examples/gigadevice/gd32/src/blinky.zig +++ b/examples/gigadevice/gd32/src/blinky.zig @@ -12,6 +12,14 @@ const pin_config = gd32.pins.GlobalConfiguration{ }, }; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const pins = pin_config.apply(); pins.green.put(0); diff --git a/examples/gigadevice/gd32/src/empty.zig b/examples/gigadevice/gd32/src/empty.zig index 7c6dbbe42..dd929d740 100644 --- a/examples/gigadevice/gd32/src/empty.zig +++ b/examples/gigadevice/gd32/src/empty.zig @@ -1,6 +1,14 @@ const std = @import("std"); const microzig = @import("microzig"); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void { // } diff --git a/examples/microchip/atmega/src/blinky.zig b/examples/microchip/atmega/src/blinky.zig index 887498a58..4908113bc 100644 --- a/examples/microchip/atmega/src/blinky.zig +++ b/examples/microchip/atmega/src/blinky.zig @@ -4,6 +4,14 @@ const gpio = microzig.hal.gpio; const led_pin = gpio.pin(.b, 5); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void { led_pin.set_direction(.output); diff --git a/examples/microchip/samd51/src/blinky.zig b/examples/microchip/samd51/src/blinky.zig index db1529a0a..a907f4419 100644 --- a/examples/microchip/samd51/src/blinky.zig +++ b/examples/microchip/samd51/src/blinky.zig @@ -1,6 +1,14 @@ const std = @import("std"); const microzig = @import("microzig"); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { // TODO: Implement the blinky } diff --git a/examples/no_hal/stm32_l031/src/blinky.zig b/examples/no_hal/stm32_l031/src/blinky.zig index 6438e5927..9795b72c4 100644 --- a/examples/no_hal/stm32_l031/src/blinky.zig +++ b/examples/no_hal/stm32_l031/src/blinky.zig @@ -5,6 +5,14 @@ const RCC = chip.peripherals.RCC; const GPIOB = chip.peripherals.GPIOB; const GPIO_TYPE = chip.types.peripherals.gpio_v2; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { RCC.GPIOENR.modify(.{ .GPIOBEN = 1 }); GPIOB.MODER.modify(.{ .@"MODER[3]" = GPIO_TYPE.MODER.Output }); diff --git a/examples/nordic/nrf5x/src/blinky.zig b/examples/nordic/nrf5x/src/blinky.zig index 594b3b5b5..4b219819a 100644 --- a/examples/nordic/nrf5x/src/blinky.zig +++ b/examples/nordic/nrf5x/src/blinky.zig @@ -4,6 +4,14 @@ const board = microzig.board; const nrf = microzig.hal; const time = nrf.time; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { board.init(); diff --git a/examples/nordic/nrf5x/src/i2c_accel.zig b/examples/nordic/nrf5x/src/i2c_accel.zig index e038f770e..e6d995cde 100644 --- a/examples/nordic/nrf5x/src/i2c_accel.zig +++ b/examples/nordic/nrf5x/src/i2c_accel.zig @@ -12,10 +12,16 @@ const ICM_20948 = microzig.drivers.sensor.ICM_20948; const uart = nrf.uart.num(0); const i2c0 = i2c.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = nrf.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const sleep_ms = nrf.time.sleep_ms; diff --git a/examples/nordic/nrf5x/src/i2c_bus_scan.zig b/examples/nordic/nrf5x/src/i2c_bus_scan.zig index ef816cf83..cc43f2190 100644 --- a/examples/nordic/nrf5x/src/i2c_bus_scan.zig +++ b/examples/nordic/nrf5x/src/i2c_bus_scan.zig @@ -14,10 +14,16 @@ const i2c0dma = i2cdma.num(0); const sleep_ms = nrf.time.sleep_ms; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = nrf.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { board.init(); diff --git a/examples/nordic/nrf5x/src/i2c_hall_effect.zig b/examples/nordic/nrf5x/src/i2c_hall_effect.zig index b814ca964..2d67f6bd8 100644 --- a/examples/nordic/nrf5x/src/i2c_hall_effect.zig +++ b/examples/nordic/nrf5x/src/i2c_hall_effect.zig @@ -16,10 +16,16 @@ const TLV493D = microzig.drivers.sensor.TLV493D; const sleep_ms = nrf.time.sleep_ms; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = nrf.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { board.init(); diff --git a/examples/nordic/nrf5x/src/i2c_position_sensor.zig b/examples/nordic/nrf5x/src/i2c_position_sensor.zig index 1ffc3eb06..9eaf881ac 100644 --- a/examples/nordic/nrf5x/src/i2c_position_sensor.zig +++ b/examples/nordic/nrf5x/src/i2c_position_sensor.zig @@ -16,10 +16,16 @@ const AS5600 = microzig.drivers.sensor.AS5600; const sleep_ms = nrf.time.sleep_ms; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = nrf.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { board.init(); diff --git a/examples/nordic/nrf5x/src/i2c_temp.zig b/examples/nordic/nrf5x/src/i2c_temp.zig index fee04dc40..060f29ca8 100644 --- a/examples/nordic/nrf5x/src/i2c_temp.zig +++ b/examples/nordic/nrf5x/src/i2c_temp.zig @@ -18,10 +18,16 @@ const i2c0dma = i2cdma.num(0); const sleep_ms = nrf.time.sleep_ms; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = nrf.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { board.init(); diff --git a/examples/nordic/nrf5x/src/microbit/display.zig b/examples/nordic/nrf5x/src/microbit/display.zig index 7cd851c17..87bbc4263 100644 --- a/examples/nordic/nrf5x/src/microbit/display.zig +++ b/examples/nordic/nrf5x/src/microbit/display.zig @@ -4,6 +4,14 @@ const nrf = microzig.hal; const time = nrf.time; const microbit = microzig.board; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub const heart: [5][5]u1 = .{ .{ 0, 1, 0, 1, 0 }, .{ 1, 0, 1, 0, 1 }, diff --git a/examples/nordic/nrf5x/src/rtt_log.zig b/examples/nordic/nrf5x/src/rtt_log.zig index 425ed145a..93feae80b 100644 --- a/examples/nordic/nrf5x/src/rtt_log.zig +++ b/examples/nordic/nrf5x/src/rtt_log.zig @@ -12,6 +12,17 @@ const rtt_instance = rtt.RTT(.{}); // Set up RTT channel 0 as a logger var rtt_logger: ?rtt_instance.Writer = null; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn log( comptime level: std.log.Level, comptime scope: @TypeOf(.EnumLiteral), @@ -34,11 +45,6 @@ pub fn log( } } -pub const microzig_options = microzig.Options{ - .log_level = .debug, - .logFn = log, -}; - pub fn main() !void { board.init(); diff --git a/examples/nordic/nrf5x/src/semihosting.zig b/examples/nordic/nrf5x/src/semihosting.zig index 0f73c84a0..6878800b9 100644 --- a/examples/nordic/nrf5x/src/semihosting.zig +++ b/examples/nordic/nrf5x/src/semihosting.zig @@ -5,6 +5,14 @@ const nrf = microzig.hal; const semihosting = microzig.core.arm_semihosting; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void { board.init(); const path = ""; diff --git a/examples/nordic/nrf5x/src/spi_master.zig b/examples/nordic/nrf5x/src/spi_master.zig index 2b22457d5..3bb4dd2c0 100644 --- a/examples/nordic/nrf5x/src/spi_master.zig +++ b/examples/nordic/nrf5x/src/spi_master.zig @@ -11,10 +11,16 @@ const uart = nrf.uart.num(0); const BUF_LEN = 0x100; const spi = nrf.spim.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = nrf.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { board.init(); diff --git a/examples/nordic/nrf5x/src/uart.zig b/examples/nordic/nrf5x/src/uart.zig index 8532cc253..6b15eb7aa 100644 --- a/examples/nordic/nrf5x/src/uart.zig +++ b/examples/nordic/nrf5x/src/uart.zig @@ -5,10 +5,16 @@ const nrf = microzig.hal; const uart = nrf.uart.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = nrf.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { board.init(); diff --git a/examples/nxp/lpc/src/blinky.zig b/examples/nxp/lpc/src/blinky.zig index 34d73383f..b7fb809ac 100644 --- a/examples/nxp/lpc/src/blinky.zig +++ b/examples/nxp/lpc/src/blinky.zig @@ -19,6 +19,14 @@ const led_mask = [4]u32{ }; const all_mask = led_mask[0] | led_mask[1] | led_mask[2] | led_mask[3]; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { conn.PINSEL3.modify(.{ .P1_18 = .GPIO_P1, diff --git a/examples/nxp/mcx/src/gpio_input.zig b/examples/nxp/mcx/src/gpio_input.zig index 06c9b9d16..ce0bd11e5 100644 --- a/examples/nxp/mcx/src/gpio_input.zig +++ b/examples/nxp/mcx/src/gpio_input.zig @@ -1,7 +1,15 @@ const microzig = @import("microzig"); const hal = microzig.hal; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .GPIO3 = .{ .c = gpio3_irq_handler } }, }; diff --git a/examples/nxp/mcx/src/lp_i2c.zig b/examples/nxp/mcx/src/lp_i2c.zig index c5e2b06a2..8146d5b5d 100644 --- a/examples/nxp/mcx/src/lp_i2c.zig +++ b/examples/nxp/mcx/src/lp_i2c.zig @@ -25,6 +25,14 @@ fn init_lpi2c_pins() void { .done(); } +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { hal.Port.num(1).init(); // we init port 1 to edit the pin's config init_lpi2c_pins(); diff --git a/examples/nxp/mcx/src/lp_uart.zig b/examples/nxp/mcx/src/lp_uart.zig index 85b266fb7..7068e52f7 100644 --- a/examples/nxp/mcx/src/lp_uart.zig +++ b/examples/nxp/mcx/src/lp_uart.zig @@ -23,6 +23,14 @@ fn init_pins() void { .done(); } +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { hal.Port.num(1).init(); // we init port 1 to edit the pin's config init_pins(); diff --git a/examples/nxp/mcx/src/mcxa153_blinky.zig b/examples/nxp/mcx/src/mcxa153_blinky.zig index f3a2eb3eb..8d162978a 100644 --- a/examples/nxp/mcx/src/mcxa153_blinky.zig +++ b/examples/nxp/mcx/src/mcxa153_blinky.zig @@ -4,6 +4,14 @@ const hal = microzig.hal; const port3 = hal.port.num(3); const pin_led_red = port3.get_gpio(12); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void { port3.init(); diff --git a/examples/nxp/mcx/src/mcxn947_blinky.zig b/examples/nxp/mcx/src/mcxn947_blinky.zig index 2b5d8a143..522f33321 100644 --- a/examples/nxp/mcx/src/mcxn947_blinky.zig +++ b/examples/nxp/mcx/src/mcxn947_blinky.zig @@ -3,6 +3,14 @@ const hal = microzig.hal; const pin_led_red = hal.GPIO.num(3, 12); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void { pin_led_red.init(); pin_led_red.set_direction(.out); diff --git a/examples/raspberrypi/rp2xxx/src/adc.zig b/examples/raspberrypi/rp2xxx/src/adc.zig index 7fa78fc88..569e9b147 100644 --- a/examples/raspberrypi/rp2xxx/src/adc.zig +++ b/examples/raspberrypi/rp2xxx/src/adc.zig @@ -10,9 +10,15 @@ const time = rp2xxx.time; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { // init uart logging diff --git a/examples/raspberrypi/rp2xxx/src/allocator.zig b/examples/raspberrypi/rp2xxx/src/allocator.zig index 3f8fcdc65..8bedcc0c5 100644 --- a/examples/raspberrypi/rp2xxx/src/allocator.zig +++ b/examples/raspberrypi/rp2xxx/src/allocator.zig @@ -34,11 +34,15 @@ const baud_rate = 115200; // ---- MicroZig Options -------------------------------- -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, - //.logFn = hal.uart.logFn, - .logFn = hal.uart.log_threadsafe, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { diff --git a/examples/raspberrypi/rp2xxx/src/blinky.zig b/examples/raspberrypi/rp2xxx/src/blinky.zig index a6b937cd6..d62e935ae 100644 --- a/examples/raspberrypi/rp2xxx/src/blinky.zig +++ b/examples/raspberrypi/rp2xxx/src/blinky.zig @@ -10,6 +10,14 @@ const pin_config: rp2xxx.pins.GlobalConfiguration = .{ }, }; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const pins = pin_config.apply(); diff --git a/examples/raspberrypi/rp2xxx/src/blinky_core1.zig b/examples/raspberrypi/rp2xxx/src/blinky_core1.zig index 10755ed37..c64dd4462 100644 --- a/examples/raspberrypi/rp2xxx/src/blinky_core1.zig +++ b/examples/raspberrypi/rp2xxx/src/blinky_core1.zig @@ -18,6 +18,14 @@ fn core1() void { } } +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { _ = board.pin_config.apply(); diff --git a/examples/raspberrypi/rp2xxx/src/board_blinky.zig b/examples/raspberrypi/rp2xxx/src/board_blinky.zig index 770a42614..13240cd89 100644 --- a/examples/raspberrypi/rp2xxx/src/board_blinky.zig +++ b/examples/raspberrypi/rp2xxx/src/board_blinky.zig @@ -3,6 +3,14 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const board = microzig.board; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const pins = board.pin_config.apply(); diff --git a/examples/raspberrypi/rp2xxx/src/board_id.zig b/examples/raspberrypi/rp2xxx/src/board_id.zig index 6581fcd70..eb6e8ec34 100644 --- a/examples/raspberrypi/rp2xxx/src/board_id.zig +++ b/examples/raspberrypi/rp2xxx/src/board_id.zig @@ -8,16 +8,23 @@ const gpio = rp2xxx.gpio; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { std.log.err("panic: {s}", .{message}); @breakpoint(); while (true) {} } -pub const microzig_options = microzig.Options{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, -}; const log = std.log.scoped(.main); pub fn main() !void { diff --git a/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig b/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig index 097ccc6be..718ad0bfe 100644 --- a/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig +++ b/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig @@ -21,6 +21,14 @@ const system_clock_cfg = clocks.config.preset.system( ); // Have to override init() so we can apply our own custom pre-main startup procedure +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn init() void { // The default init_sequence works fine here, we just want to swap in our own clock config rp2xxx.init_sequence(system_clock_cfg); diff --git a/examples/raspberrypi/rp2xxx/src/custom_clock_config.zig b/examples/raspberrypi/rp2xxx/src/custom_clock_config.zig index 950df80c3..70c389af4 100644 --- a/examples/raspberrypi/rp2xxx/src/custom_clock_config.zig +++ b/examples/raspberrypi/rp2xxx/src/custom_clock_config.zig @@ -110,6 +110,14 @@ const system_clock_cfg: GlobalConfig = val: { }; // Have to override init() so we can apply our own custom pre-main startup procedure +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn init() void { // The default init_sequence works fine here, we just want to swap in our own clock config rp2xxx.init_sequence(system_clock_cfg); diff --git a/examples/raspberrypi/rp2xxx/src/cyw43.zig b/examples/raspberrypi/rp2xxx/src/cyw43.zig index 8fe38ed4b..d9da52e6a 100644 --- a/examples/raspberrypi/rp2xxx/src/cyw43.zig +++ b/examples/raspberrypi/rp2xxx/src/cyw43.zig @@ -14,10 +14,16 @@ var wifi_driver: drivers.WiFi = .{}; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const log = std.log.scoped(.main); diff --git a/examples/raspberrypi/rp2xxx/src/cyw43/blinky.zig b/examples/raspberrypi/rp2xxx/src/cyw43/blinky.zig index a8a042f5b..8d25f45d5 100644 --- a/examples/raspberrypi/rp2xxx/src/cyw43/blinky.zig +++ b/examples/raspberrypi/rp2xxx/src/cyw43/blinky.zig @@ -4,6 +4,14 @@ const rp2xxx = microzig.hal; const cyw43 = rp2xxx.cyw43; const time = rp2xxx.time; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { try cyw43.init(); diff --git a/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig b/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig index 0e5db7e2c..164793b1a 100644 --- a/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig +++ b/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig @@ -13,10 +13,16 @@ const Runner = cyw43.Runner; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .info, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} // WiFi credentials - change these for your network const WIFI_SSID = "YOUR_SSID"; diff --git a/examples/raspberrypi/rp2xxx/src/cyw43/wifi_scan.zig b/examples/raspberrypi/rp2xxx/src/cyw43/wifi_scan.zig index 61cdd5c27..9db5e01dc 100644 --- a/examples/raspberrypi/rp2xxx/src/cyw43/wifi_scan.zig +++ b/examples/raspberrypi/rp2xxx/src/cyw43/wifi_scan.zig @@ -10,10 +10,16 @@ const Wifi = cyw43.Wifi; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .info, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { uart_tx_pin.set_function(.uart); diff --git a/examples/raspberrypi/rp2xxx/src/dma.zig b/examples/raspberrypi/rp2xxx/src/dma.zig index f0ad6f907..c179c360e 100644 --- a/examples/raspberrypi/rp2xxx/src/dma.zig +++ b/examples/raspberrypi/rp2xxx/src/dma.zig @@ -19,17 +19,23 @@ fn transfer_from_slices(channel: dma.Channel, write_buf: []u8, read_buf: []const }); } +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { std.log.err("panic: {s}", .{message}); @breakpoint(); while (true) {} } -pub const microzig_options = microzig.Options{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, -}; - pub fn main() !void { uart_tx_pin.set_function(.uart); diff --git a/examples/raspberrypi/rp2xxx/src/ds18b20.zig b/examples/raspberrypi/rp2xxx/src/ds18b20.zig index d24ed073a..4f9410e06 100644 --- a/examples/raspberrypi/rp2xxx/src/ds18b20.zig +++ b/examples/raspberrypi/rp2xxx/src/ds18b20.zig @@ -18,6 +18,14 @@ const pin_config: rp2xxx.pins.GlobalConfiguration = .{ }, }; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const pins = pin_config.apply(); diff --git a/examples/raspberrypi/rp2xxx/src/flash_program.zig b/examples/raspberrypi/rp2xxx/src/flash_program.zig index 4416ebf24..64b59e79b 100644 --- a/examples/raspberrypi/rp2xxx/src/flash_program.zig +++ b/examples/raspberrypi/rp2xxx/src/flash_program.zig @@ -12,17 +12,23 @@ const uart_tx_pin = gpio.num(0); const flash_target_offset: u32 = 256 * 1024; const flash_target_contents = @as([*]const u8, @ptrFromInt(rp2xxx.flash.XIP_BASE + flash_target_offset)); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { std.log.err("panic: {s}", .{message}); @breakpoint(); while (true) {} } -pub const microzig_options = microzig.Options{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, -}; - pub fn main() !void { // init uart logging uart_tx_pin.set_function(.uart); diff --git a/examples/raspberrypi/rp2xxx/src/freertos/hello_task.zig b/examples/raspberrypi/rp2xxx/src/freertos/hello_task.zig index 614eb0dcd..3ac13f2aa 100644 --- a/examples/raspberrypi/rp2xxx/src/freertos/hello_task.zig +++ b/examples/raspberrypi/rp2xxx/src/freertos/hello_task.zig @@ -23,9 +23,18 @@ const gpio = rp2xxx.gpio; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .cpu = .{ .ram_vector_table = true, }, diff --git a/examples/raspberrypi/rp2xxx/src/freertos/multitask_demo.zig b/examples/raspberrypi/rp2xxx/src/freertos/multitask_demo.zig index 99130411b..2a621ba43 100644 --- a/examples/raspberrypi/rp2xxx/src/freertos/multitask_demo.zig +++ b/examples/raspberrypi/rp2xxx/src/freertos/multitask_demo.zig @@ -20,9 +20,18 @@ const gpio = rp2xxx.gpio; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .cpu = .{ .ram_vector_table = true, }, diff --git a/examples/raspberrypi/rp2xxx/src/freertos/queue_demo.zig b/examples/raspberrypi/rp2xxx/src/freertos/queue_demo.zig index 1b5dae39d..b553e3a65 100644 --- a/examples/raspberrypi/rp2xxx/src/freertos/queue_demo.zig +++ b/examples/raspberrypi/rp2xxx/src/freertos/queue_demo.zig @@ -15,9 +15,18 @@ const gpio = rp2xxx.gpio; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .cpu = .{ .ram_vector_table = true, }, diff --git a/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig b/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig index 69e14112f..7dc3e991e 100644 --- a/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig +++ b/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig @@ -8,6 +8,14 @@ const Pin = rp2xxx.gpio.Pin; const gpout0_pin = gpio.num(21); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { // Don't forget to bring a blinky! const led_gpio = rp2xxx.gpio.num(25); diff --git a/examples/raspberrypi/rp2xxx/src/gpio_irq.zig b/examples/raspberrypi/rp2xxx/src/gpio_irq.zig index af1c8ea92..024841cf7 100644 --- a/examples/raspberrypi/rp2xxx/src/gpio_irq.zig +++ b/examples/raspberrypi/rp2xxx/src/gpio_irq.zig @@ -13,12 +13,16 @@ const uart_rx_pin = gpio.num(1); const MAGICREBOOTCODE: u8 = 0xAB; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, - // This function has to handle both cpus if BANK0 interrupts are enabled on both. - .interrupts = .{ .IO_IRQ_BANK0 = .{ .c = callback_alt } }, -}; +}); + +comptime { + _ = microzig.export_startup(); +} // used as event flag to keep IRQ handler fast var event: ?gpio.IrqTrigger = null; diff --git a/examples/raspberrypi/rp2xxx/src/i2c_accel.zig b/examples/raspberrypi/rp2xxx/src/i2c_accel.zig index e7526654d..3e9bac819 100644 --- a/examples/raspberrypi/rp2xxx/src/i2c_accel.zig +++ b/examples/raspberrypi/rp2xxx/src/i2c_accel.zig @@ -13,10 +13,16 @@ const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); const i2c0 = i2c.instance.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .info, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const sleep_ms = rp2xxx.time.sleep_ms; diff --git a/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig b/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig index 541375aa8..5a9a56469 100644 --- a/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig +++ b/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig @@ -9,10 +9,16 @@ const gpio = rp2xxx.gpio; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .info, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const i2c0 = i2c.instance.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig b/examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig index 76086144c..1e756d82e 100644 --- a/examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig +++ b/examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig @@ -17,10 +17,16 @@ const TLV493D = microzig.drivers.sensor.TLV493D; const sleep_ms = rp2xxx.time.sleep_ms; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { // init uart logging diff --git a/examples/raspberrypi/rp2xxx/src/mlx90640.zig b/examples/raspberrypi/rp2xxx/src/mlx90640.zig index 5740759e2..1f9108ce1 100644 --- a/examples/raspberrypi/rp2xxx/src/mlx90640.zig +++ b/examples/raspberrypi/rp2xxx/src/mlx90640.zig @@ -18,10 +18,16 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ .GPIO0 = .{ .name = "gpio0", .function = .UART0_TX }, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { try init(); diff --git a/examples/raspberrypi/rp2xxx/src/mlx90640_hottest_point.zig b/examples/raspberrypi/rp2xxx/src/mlx90640_hottest_point.zig index 16a922405..edf2f532a 100644 --- a/examples/raspberrypi/rp2xxx/src/mlx90640_hottest_point.zig +++ b/examples/raspberrypi/rp2xxx/src/mlx90640_hottest_point.zig @@ -19,10 +19,16 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ .GPIO0 = .{ .name = "gpio0", .function = .UART0_TX }, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { try init(); diff --git a/examples/raspberrypi/rp2xxx/src/mlx90640_image.zig b/examples/raspberrypi/rp2xxx/src/mlx90640_image.zig index 399a89117..fdf628f68 100644 --- a/examples/raspberrypi/rp2xxx/src/mlx90640_image.zig +++ b/examples/raspberrypi/rp2xxx/src/mlx90640_image.zig @@ -19,10 +19,16 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ .GPIO0 = .{ .name = "gpio0", .function = .UART0_TX }, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { try init(); diff --git a/examples/raspberrypi/rp2xxx/src/net/irq.zig b/examples/raspberrypi/rp2xxx/src/net/irq.zig index ecc135764..dfdca9349 100644 --- a/examples/raspberrypi/rp2xxx/src/net/irq.zig +++ b/examples/raspberrypi/rp2xxx/src/net/irq.zig @@ -20,6 +20,14 @@ const chip = rp2xxx.compatibility.chip; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub const rp2040_options: microzig.Options = .{ .log_level = .debug, .logFn = rp2xxx.uart.log, diff --git a/examples/raspberrypi/rp2xxx/src/net/pong.zig b/examples/raspberrypi/rp2xxx/src/net/pong.zig index b360bd2df..45dee2218 100644 --- a/examples/raspberrypi/rp2xxx/src/net/pong.zig +++ b/examples/raspberrypi/rp2xxx/src/net/pong.zig @@ -8,10 +8,17 @@ const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} + const log = std.log.scoped(.main); comptime { diff --git a/examples/raspberrypi/rp2xxx/src/net/scan.zig b/examples/raspberrypi/rp2xxx/src/net/scan.zig index 9a6433310..a201d6ead 100644 --- a/examples/raspberrypi/rp2xxx/src/net/scan.zig +++ b/examples/raspberrypi/rp2xxx/src/net/scan.zig @@ -8,10 +8,17 @@ const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} + const log = std.log.scoped(.main); comptime { diff --git a/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig b/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig index eebc006e4..bb19efac9 100644 --- a/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig +++ b/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig @@ -8,10 +8,17 @@ const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} + const log = std.log.scoped(.main); comptime { diff --git a/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig b/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig index 8fcfa396b..f28beaa20 100644 --- a/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig +++ b/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig @@ -8,10 +8,17 @@ const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} + const log = std.log.scoped(.main); comptime { diff --git a/examples/raspberrypi/rp2xxx/src/net/udp.zig b/examples/raspberrypi/rp2xxx/src/net/udp.zig index 25ff47736..4a214e2c4 100644 --- a/examples/raspberrypi/rp2xxx/src/net/udp.zig +++ b/examples/raspberrypi/rp2xxx/src/net/udp.zig @@ -8,10 +8,17 @@ const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} + const log = std.log.scoped(.main); comptime { diff --git a/examples/raspberrypi/rp2xxx/src/pwm.zig b/examples/raspberrypi/rp2xxx/src/pwm.zig index aea051ef4..dc7564396 100644 --- a/examples/raspberrypi/rp2xxx/src/pwm.zig +++ b/examples/raspberrypi/rp2xxx/src/pwm.zig @@ -11,6 +11,14 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ .GPIO25 = .{ .name = "led", .function = .PWM4_B }, }; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const pins = pin_config.apply(); pins.led.slice().set_wrap(100); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig index 2758bceea..59b215a94 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig @@ -16,6 +16,14 @@ const i2c0 = i2c.instance.num(0); const i2c_device = I2C_Device.init(i2c0, null); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn delay_us(time_delay: u32) void { timer.sleep_us(time_delay); } diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_slave.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_slave.zig index 4f5f998b0..05ec9ab3e 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_slave.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/i2c_slave.zig @@ -22,8 +22,17 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ }, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .I2C0_IRQ = .{ .c = i2c.slave.isr1 } }, }; diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig index 051022538..283a6479a 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig @@ -15,6 +15,14 @@ const i2c0 = i2c.instance.num(0); const i2c_device = I2C_Device.init(i2c0, null); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const scl_pin = gpio.num(5); const sda_pin = gpio.num(4); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig index 32bf16a68..0d6649bce 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig @@ -13,17 +13,23 @@ const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { std.log.err("panic: {s}", .{message}); @breakpoint(); while (true) {} } -pub const microzig_options = microzig.Options{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, -}; - pub fn main() !void { // init uart logging uart_tx_pin.set_function(.uart); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig index 0d5f815fb..7b6c04682 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig @@ -10,7 +10,15 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ }, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .RTC_IRQ = .{ .c = rtc_isr }, }, diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/tiles.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/tiles.zig index e92c1741b..cec23653b 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/tiles.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/tiles.zig @@ -70,6 +70,14 @@ inline fn float_to_bright(f: f32) u8 { ]; } +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { pio.gpio_init(led_pin); sm_set_consecutive_pindirs(pio, sm, @intFromEnum(led_pin), 1, true); diff --git a/examples/raspberrypi/rp2xxx/src/rp2350_only/always_on_timer.zig b/examples/raspberrypi/rp2xxx/src/rp2350_only/always_on_timer.zig index 2980b3582..574f39bb5 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2350_only/always_on_timer.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2350_only/always_on_timer.zig @@ -16,10 +16,16 @@ const pin_config = hal.pins.GlobalConfiguration{ .GPIO0 = .{ .name = "gpio0", .function = .UART0_TX }, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { var buffer: [128]u8 = undefined; diff --git a/examples/raspberrypi/rp2xxx/src/rp2350_only/random_data.zig b/examples/raspberrypi/rp2xxx/src/rp2350_only/random_data.zig index 80142241d..5ec0b0b9d 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2350_only/random_data.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2350_only/random_data.zig @@ -15,10 +15,16 @@ const pin_config = hal.pins.GlobalConfiguration{ .GPIO0 = .{ .name = "gpio0", .function = .UART0_TX }, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { _ = pin_config.apply(); diff --git a/examples/raspberrypi/rp2xxx/src/rtt_log.zig b/examples/raspberrypi/rp2xxx/src/rtt_log.zig index 074e0b38a..7e8051767 100644 --- a/examples/raspberrypi/rp2xxx/src/rtt_log.zig +++ b/examples/raspberrypi/rp2xxx/src/rtt_log.zig @@ -52,6 +52,17 @@ const rtt_instance = rtt.RTT(.{}); var rtt_logger: ?rtt_instance.Writer = null; // var rtt_write_buffer: [64]u8 = undefined; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn log( comptime level: std.log.Level, comptime scope: @TypeOf(.EnumLiteral), @@ -74,11 +85,6 @@ pub fn log( } } -pub const microzig_options = microzig.Options{ - .log_level = .debug, - .logFn = log, -}; - pub fn main() !void { // Don't forget to bring a blinky! diff --git a/examples/raspberrypi/rp2xxx/src/spi_loopback_dma.zig b/examples/raspberrypi/rp2xxx/src/spi_loopback_dma.zig index 9c5de5a6a..cb518068e 100644 --- a/examples/raspberrypi/rp2xxx/src/spi_loopback_dma.zig +++ b/examples/raspberrypi/rp2xxx/src/spi_loopback_dma.zig @@ -12,10 +12,16 @@ const uart_tx_pin = gpio.num(0); const BUF_LEN = 0x100; const spi = rp2xxx.spi.instance.SPI0; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { uart_tx_pin.set_function(.uart); diff --git a/examples/raspberrypi/rp2xxx/src/spi_master.zig b/examples/raspberrypi/rp2xxx/src/spi_master.zig index a0f9cb8d1..16e6c6a25 100644 --- a/examples/raspberrypi/rp2xxx/src/spi_master.zig +++ b/examples/raspberrypi/rp2xxx/src/spi_master.zig @@ -17,6 +17,14 @@ const SCK_PIN = 18; const TX_PIN = 19; // Communicate with another RP2040 over spi +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { // Set pin functions for CS, SCK, RX const csn = rp2xxx.gpio.num(CS_PIN); diff --git a/examples/raspberrypi/rp2xxx/src/spi_slave.zig b/examples/raspberrypi/rp2xxx/src/spi_slave.zig index 3f8a79458..f448e1e56 100644 --- a/examples/raspberrypi/rp2xxx/src/spi_slave.zig +++ b/examples/raspberrypi/rp2xxx/src/spi_slave.zig @@ -9,10 +9,16 @@ const chip = rp2xxx.compatibility.chip; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const BUF_LEN = 0x100; const spi = rp2xxx.spi.instance.SPI0; diff --git a/examples/raspberrypi/rp2xxx/src/squarewave.zig b/examples/raspberrypi/rp2xxx/src/squarewave.zig index 99a5c904c..1eda31051 100644 --- a/examples/raspberrypi/rp2xxx/src/squarewave.zig +++ b/examples/raspberrypi/rp2xxx/src/squarewave.zig @@ -30,6 +30,14 @@ const pio: Pio = rp2xxx.pio.num(0); const sm: StateMachine = .sm0; const pin = gpio.num(2); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { pio.gpio_init(pin); pio.sm_load_and_start_program(sm, squarewave_program, .{ diff --git a/examples/raspberrypi/rp2xxx/src/ssd1306_oled.zig b/examples/raspberrypi/rp2xxx/src/ssd1306_oled.zig index c8cf53308..c55683084 100644 --- a/examples/raspberrypi/rp2xxx/src/ssd1306_oled.zig +++ b/examples/raspberrypi/rp2xxx/src/ssd1306_oled.zig @@ -10,6 +10,14 @@ const i2c0 = i2c.instance.num(0); const empty_row: []const u8 = " " ** 16; const four_rows = empty_row ** 4; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void { // Safe buffer size for rp2xxx to allocate, value can change for other chips const buffer_size = 200 * 1024; // 200 KB diff --git a/examples/raspberrypi/rp2xxx/src/st7789_lcd.zig b/examples/raspberrypi/rp2xxx/src/st7789_lcd.zig index 82ad22711..2b6c4aaf9 100644 --- a/examples/raspberrypi/rp2xxx/src/st7789_lcd.zig +++ b/examples/raspberrypi/rp2xxx/src/st7789_lcd.zig @@ -33,10 +33,16 @@ const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); const uart_rx_pin = gpio.num(1); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const led = gpio.num(DISPLAY_BACKLIGHT_PIN); const led_pwm = pwm.get_pwm(DISPLAY_BACKLIGHT_PIN); diff --git a/examples/raspberrypi/rp2xxx/src/stepper_driver.zig b/examples/raspberrypi/rp2xxx/src/stepper_driver.zig index c47fc6376..e8d26f1f8 100644 --- a/examples/raspberrypi/rp2xxx/src/stepper_driver.zig +++ b/examples/raspberrypi/rp2xxx/src/stepper_driver.zig @@ -10,16 +10,22 @@ const A4988 = microzig.drivers.stepper.A4988; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { std.log.err("panic: {s}", .{message}); @breakpoint(); while (true) {} } -pub const microzig_options = microzig.Options{ - .logFn = rp2xxx.uart.log, -}; - pub fn main() !void { // init uart logging uart_tx_pin.set_function(.uart); diff --git a/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig b/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig index 761b8e941..795896f1d 100644 --- a/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig +++ b/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig @@ -10,16 +10,22 @@ const ULN2003 = microzig.drivers.stepper.ULN2003; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { std.log.err("panic: {s}", .{message}); @breakpoint(); while (true) {} } -pub const microzig_options = microzig.Options{ - .logFn = rp2xxx.uart.log, -}; - pub fn main() !void { // init uart logging uart_tx_pin.set_function(.uart); diff --git a/examples/raspberrypi/rp2xxx/src/system_timer.zig b/examples/raspberrypi/rp2xxx/src/system_timer.zig index edea29444..b6a033acb 100644 --- a/examples/raspberrypi/rp2xxx/src/system_timer.zig +++ b/examples/raspberrypi/rp2xxx/src/system_timer.zig @@ -12,6 +12,14 @@ const timer = system_timer.num(0); const timer_irq = if (chip == .RP2040) .TIMER_IRQ_0 else .TIMER0_IRQ_0; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub const rp2040_options: microzig.Options = .{ .log_level = .debug, .logFn = rp2xxx.uart.log, diff --git a/examples/raspberrypi/rp2xxx/src/uart_echo.zig b/examples/raspberrypi/rp2xxx/src/uart_echo.zig index 9a5e9d51b..0a22a72a5 100644 --- a/examples/raspberrypi/rp2xxx/src/uart_echo.zig +++ b/examples/raspberrypi/rp2xxx/src/uart_echo.zig @@ -11,6 +11,14 @@ const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); const uart_rx_pin = gpio.num(1); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { led.set_function(.sio); led.set_direction(.out); diff --git a/examples/raspberrypi/rp2xxx/src/uart_log.zig b/examples/raspberrypi/rp2xxx/src/uart_log.zig index 48f1fa85d..9aab8b9fe 100644 --- a/examples/raspberrypi/rp2xxx/src/uart_log.zig +++ b/examples/raspberrypi/rp2xxx/src/uart_log.zig @@ -8,17 +8,23 @@ const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { std.log.err("panic: {s}", .{message}); @breakpoint(); while (true) {} } -pub const microzig_options = microzig.Options{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, -}; - pub fn main() !void { led.set_function(.sio); led.set_direction(.out); diff --git a/examples/raspberrypi/rp2xxx/src/usb_cdc.zig b/examples/raspberrypi/rp2xxx/src/usb_cdc.zig index eca1a1c65..1d0554b74 100644 --- a/examples/raspberrypi/rp2xxx/src/usb_cdc.zig +++ b/examples/raspberrypi/rp2xxx/src/usb_cdc.zig @@ -32,13 +32,9 @@ var usb_controller: usb.DeviceController(.{ .reset = "", }}) = .init; -pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { - std.log.err("panic: {s}", .{message}); - @breakpoint(); - while (true) {} -} +pub const panic = microzig.panic; -pub const microzig_options = microzig.Options{ +pub const std_options = microzig.std_options(.{ .log_level = .debug, .log_scope_levels = &.{ .{ .scope = .usb_dev, .level = .warn }, @@ -46,7 +42,17 @@ pub const microzig_options = microzig.Options{ .{ .scope = .usb_cdc, .level = .warn }, }, .logFn = rp2xxx.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} + +pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { + std.log.err("panic: {s}", .{message}); + @breakpoint(); + while (true) {} +} const pin_config: rp2xxx.pins.GlobalConfiguration = .{ .GPIO0 = .{ .function = .UART0_TX }, diff --git a/examples/raspberrypi/rp2xxx/src/usb_hid.zig b/examples/raspberrypi/rp2xxx/src/usb_hid.zig index 39eda917d..ebd49e247 100644 --- a/examples/raspberrypi/rp2xxx/src/usb_hid.zig +++ b/examples/raspberrypi/rp2xxx/src/usb_hid.zig @@ -6,6 +6,22 @@ const time = rp2xxx.time; const usb = microzig.core.usb; const USB_Device = rp2xxx.usb.Polled(.{}); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .log_scope_levels = &.{ + .{ .scope = .usb_dev, .level = .warn }, + .{ .scope = .usb_ctrl, .level = .warn }, + .{ .scope = .usb_hid_int_driver, .level = .warn }, + }, + .logFn = rp2xxx.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + pub const Modifiers = packed struct(u8) { lctrl: bool, lshift: bool, @@ -130,16 +146,6 @@ pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noretu while (true) {} } -pub const microzig_options = microzig.Options{ - .log_level = .debug, - .log_scope_levels = &.{ - .{ .scope = .usb_dev, .level = .warn }, - .{ .scope = .usb_ctrl, .level = .warn }, - .{ .scope = .usb_hid_int_driver, .level = .warn }, - }, - .logFn = rp2xxx.uart.log, -}; - const pin_config: rp2xxx.pins.GlobalConfiguration = .{ .GPIO0 = .{ .function = .UART0_TX }, .GPIO25 = .{ .name = "led", .direction = .out }, diff --git a/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig b/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig index 975b74c98..4294ca256 100644 --- a/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig +++ b/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig @@ -10,6 +10,14 @@ const pin_config = rp2xxx.pins.GlobalConfiguration{ .direction = .out, }, }; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const pins = pin_config.apply(); diff --git a/examples/raspberrypi/rp2xxx/src/ws2812.zig b/examples/raspberrypi/rp2xxx/src/ws2812.zig index 9946d4bb3..747b2fa57 100644 --- a/examples/raspberrypi/rp2xxx/src/ws2812.zig +++ b/examples/raspberrypi/rp2xxx/src/ws2812.zig @@ -36,6 +36,14 @@ const pio: Pio = rp2xxx.pio.num(0); const sm: StateMachine = .sm0; const led_pin = gpio.num(23); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { pio.gpio_init(led_pin); try pio.sm_set_pindir(sm, led_pin, 1, .out); diff --git a/examples/stmicro/stm32/src/blinky.zig b/examples/stmicro/stm32/src/blinky.zig index 74968ec62..0b159f3d6 100644 --- a/examples/stmicro/stm32/src/blinky.zig +++ b/examples/stmicro/stm32/src/blinky.zig @@ -11,6 +11,14 @@ fn delay() void { } } +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const pins, const all_leds = res: { if (comptime std.mem.eql(u8, microzig.config.chip_name, "STM32F103C8")) { diff --git a/examples/stmicro/stm32/src/hts221.zig b/examples/stmicro/stm32/src/hts221.zig index e28ea9cb6..a8d476a6a 100644 --- a/examples/stmicro/stm32/src/hts221.zig +++ b/examples/stmicro/stm32/src/hts221.zig @@ -5,8 +5,17 @@ const systick = stm32.systick; const board = microzig.board; const HTS221 = microzig.drivers.sensor.HTS221; -pub const microzig_options: microzig.Options = .{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = microzig.board.uart_logger.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .cpu = .{ .ram_vector_table = true, }, diff --git a/examples/stmicro/stm32/src/semihosting.zig b/examples/stmicro/stm32/src/semihosting.zig index c05a09db0..b679549e4 100644 --- a/examples/stmicro/stm32/src/semihosting.zig +++ b/examples/stmicro/stm32/src/semihosting.zig @@ -2,6 +2,14 @@ const std = @import("std"); const microzig = @import("microzig"); const semihosting = microzig.core.arm_semihosting; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void { const path = ""; const file_name = path ++ "foo.txt"; diff --git a/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig b/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig index 90c1f231c..d942d3064 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig @@ -12,6 +12,14 @@ const led = hal.gpio.Pin.from_port(.B, 2); const input = hal.gpio.Pin.from_port(.B, 9); //define the EXTI handler +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub const microzig_options: microzig.Options = .{ .interrupts = .{ .EXTI9_5 = .{ .c = EXTI_handler }, diff --git a/examples/stmicro/stm32/src/stm32f1xx/adc.zig b/examples/stmicro/stm32/src/stm32f1xx/adc.zig index 427c5ecf5..260d6050b 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/adc.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/adc.zig @@ -21,9 +21,15 @@ fn adc_to_temp(val: usize) f32 { return ((v25 - temp_mv) / avg_slope) + 25; //convert to celsius } -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { rcc.enable_clock(.TIM2); diff --git a/examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig b/examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig index ef49d5392..8243de3fd 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/adc_dualmode.zig @@ -18,9 +18,15 @@ const TX = gpio.Pin.from_port(.A, 9); const ADC_pin1 = gpio.Pin.from_port(.A, 1); const ADC_pin2 = gpio.Pin.from_port(.A, 2); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const AdcData = packed struct(u32) { adc1: u16, diff --git a/examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig b/examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig index f3882df00..0f1fdd2a4 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/advanced_adc.zig @@ -28,8 +28,17 @@ const ADC_pin1 = gpio.Pin.from_port(.A, 1); const ADC_pin2 = gpio.Pin.from_port(.A, 2); const ADC_pin3 = gpio.Pin.from_port(.A, 3); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .ADC1_2 = .{ .c = watchdog_handler } }, }; diff --git a/examples/stmicro/stm32/src/stm32f1xx/gpio.zig b/examples/stmicro/stm32/src/stm32f1xx/gpio.zig index 87969fc55..a46614b7f 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/gpio.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/gpio.zig @@ -5,6 +5,14 @@ const rcc = stm32.rcc; const gpio = stm32.gpio; const time = stm32.time; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { _ = try rcc.apply(.{ .SYSCLKSource = .PLL1_P, diff --git a/examples/stmicro/stm32/src/stm32f1xx/hd44780.zig b/examples/stmicro/stm32/src/stm32f1xx/hd44780.zig index f844242dc..5ddc6f787 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/hd44780.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/hd44780.zig @@ -31,6 +31,14 @@ fn delay_us(delay: u32) void { time.sleep_us(delay); } +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { rcc.enable_clock(.GPIOB); rcc.enable_clock(.GPIOC); diff --git a/examples/stmicro/stm32/src/stm32f1xx/i2c.zig b/examples/stmicro/stm32/src/stm32f1xx/i2c.zig index 86e968381..8bb1719b0 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/i2c.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/i2c.zig @@ -22,9 +22,15 @@ const config = i2c.Config{ .mode = .standard, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { rcc.enable_clock(.GPIOB); diff --git a/examples/stmicro/stm32/src/stm32f1xx/i2c_bus_scan.zig b/examples/stmicro/stm32/src/stm32f1xx/i2c_bus_scan.zig index c3261e283..88c2ff9b9 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/i2c_bus_scan.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/i2c_bus_scan.zig @@ -21,9 +21,15 @@ const config = I2c.Config{ .mode = .standard, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { rcc.enable_clock(.GPIOB); diff --git a/examples/stmicro/stm32/src/stm32f1xx/rcc.zig b/examples/stmicro/stm32/src/stm32f1xx/rcc.zig index e24d503cd..924dd0c4c 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/rcc.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/rcc.zig @@ -9,9 +9,15 @@ const MCO = gpio.Pin.from_port(.A, 8); const uart = stm32.uart.UART.init(.USART1); const TX = gpio.Pin.from_port(.A, 9); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const clk_config = rcc.Config{ .PLLSourceVirtual = .HSE_Div_PREDIV, diff --git a/examples/stmicro/stm32/src/stm32f1xx/rtc.zig b/examples/stmicro/stm32/src/stm32f1xx/rtc.zig index 5ef71dc91..c4ca7cb7a 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/rtc.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/rtc.zig @@ -5,7 +5,15 @@ const rcc = hal.rcc; const bkp = hal.backup; const gpio = hal.gpio; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .RTC = .{ .c = rtc_handler } }, }; diff --git a/examples/stmicro/stm32/src/stm32f1xx/spi.zig b/examples/stmicro/stm32/src/stm32f1xx/spi.zig index 6d69ff7e3..2e6d2aae8 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/spi.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/spi.zig @@ -14,6 +14,14 @@ const MOSI = gpio.Pin.from_port(.B, 15); const MISO = gpio.Pin.from_port(.B, 14); const SCK = gpio.Pin.from_port(.B, 13); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void { rcc.enable_clock(.GPIOB); rcc.enable_clock(.SPI2); diff --git a/examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig b/examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig index 587e69e1f..c7d47f570 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig @@ -25,9 +25,15 @@ const config = I2C.Config{ .mode = .standard, }; -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} const i2c_device = I2C_Datagram_Device.init(i2c, I2C.Address.new(0x3c), null); diff --git a/examples/stmicro/stm32/src/stm32f1xx/timer.zig b/examples/stmicro/stm32/src/stm32f1xx/timer.zig index 0ad45249d..e8051947a 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/timer.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/timer.zig @@ -9,10 +9,7 @@ const gpio = stm32.gpio; const GPTimer = stm32.timer.GPTimer; const time = stm32.time; -//pub const microzig_options: microzig.Options = .{ -// .interrupts = .{ .TIM3 = .{ .c = time.TIM_handler } }, -//}; - +// //gpios const ch1 = gpio.Pin.from_port(.A, 0); const ch2 = gpio.Pin.from_port(.A, 1); @@ -21,6 +18,14 @@ const ch4 = gpio.Pin.from_port(.A, 3); //timers const pwm = GPTimer.init(.TIM2).into_pwm_mode(); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { //first we need to enable the clocks for the GPIO and TIM peripherals diff --git a/examples/stmicro/stm32/src/stm32f1xx/timer_capture.zig b/examples/stmicro/stm32/src/stm32f1xx/timer_capture.zig index cc3c9b609..9a8c4cf32 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/timer_capture.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/timer_capture.zig @@ -20,8 +20,17 @@ const ch1 = gpio.Pin.from_port(.A, 0); const uart = stm32.uart.UART.init(.USART1); const TX = gpio.Pin.from_port(.A, 9); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, +}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ .interrupts = .{ .TIM2 = .{ .c = isr_tim2 } }, .overwrite_hal_interrupts = true, }; diff --git a/examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig b/examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig index 9844186fd..48e94b26f 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig @@ -11,6 +11,14 @@ const gpio = stm32.gpio; const TX = gpio.Pin.from_port(.A, 9); const RX = gpio.Pin.from_port(.A, 10); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { rcc.enable_clock(.GPIOA); rcc.enable_clock(.TIM2); diff --git a/examples/stmicro/stm32/src/stm32f1xx/uart_log.zig b/examples/stmicro/stm32/src/stm32f1xx/uart_log.zig index 6ca63e4c7..0c277d328 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/uart_log.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/uart_log.zig @@ -8,9 +8,15 @@ const uart = stm32.uart.UART.init(.USART1); const gpio = stm32.gpio; const TX = gpio.Pin.from_port(.A, 9); -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .logFn = stm32.uart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { rcc.enable_clock(.GPIOA); diff --git a/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig b/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig index 56beed85e..9b172045c 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig @@ -14,10 +14,18 @@ const descriptor = microzig.core.usb.descriptor; const EpControl = usb_ll.EpControl; +var Counter: stm32.drivers.CounterDevice = undefined; + +pub const panic = microzig.panic; +pub const std_options = microzig.std_options(.{}); pub const microzig_options: microzig.Options = .{ .interrupts = .{ .USB_LP_CAN1_RX0 = .{ .c = usb_ll.usb_handler } }, }; +comptime { + _ = microzig.export_startup(); +} + // ============== HID Descriptor ================ const DeviceDescriptor = [_]u8{ 0x12, // bLength diff --git a/examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig b/examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig index 539de5783..9e20f1f40 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/usb_hid.zig @@ -14,12 +14,18 @@ const descriptor = microzig.core.usb.descriptor; const EpControl = usb_ll.EpControl; +pub const panic = microzig.panic; +pub const std_options = microzig.std_options(.{}); pub const microzig_options: microzig.Options = .{ .interrupts = .{ .USB_LP_CAN1_RX0 = .{ .c = usb_ll.usb_handler }, }, }; +comptime { + _ = microzig.export_startup(); +} + // ============== HID Descriptor ================ const DeviceDescriptor = [18]u8{ 0x12, // bLength diff --git a/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig b/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig new file mode 100644 index 000000000..a588713f5 --- /dev/null +++ b/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig @@ -0,0 +1,463 @@ +//NOTE: This is just an experimental test, USB HAL for the F1 family is not complete. + +const std = @import("std"); +const microzig = @import("microzig"); + +const host = microzig.core.arm_semihosting; + +const RCC = microzig.chip.peripherals.RCC; +const flash = microzig.chip.peripherals.FLASH; +const rcc_v1 = microzig.chip.types.peripherals.rcc_f1; +const flash_v1 = microzig.chip.types.peripherals.flash_f1; + +const stm32 = microzig.hal; +const gpio = stm32.gpio; +const timer = stm32.timer.GPTimer.init(.TIM2).into_counter_mode(); +const usb_ll = stm32.usb.usb_ll; +const descriptor = microzig.core.usb.descriptor; + +const EpControl = usb_ll.EpControl; + +const interrupt = microzig.interrupt; +var Counter: stm32.drivers.CounterDevice = undefined; +const IR_pin = gpio.Pin.from_port(.B, 0); +const peri = microzig.chip.peripherals; +const t_types = microzig.chip.types.peripherals.timer_v1; + +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + +pub const microzig_options: microzig.Options = .{ + .interrupts = .{ + .USB_LP_CAN1_RX0 = .{ .c = usb_ll.usb_handler }, + .EXTI0 = .{ .c = IR_handler }, + .TIM3 = .{ .c = IR_timer_handler }, + }, +}; + +// ============== HID Descriptor ================ +const DeviceDescriptor = [18]u8{ + 0x12, // bLength + 0x01, // bDescriptorType (Device) + 0x10, 0x01, // bcdUSB (USB 1.1) + 0x00, // bDeviceClass (Defined at Interface) + 0x00, // bDeviceSubClass + 0x00, // bDeviceProtocol + 0x40, // bMaxPacketSize0 (64 bytes) + 0x55, 0xF0, // idVendor FOSS + 0x01, 0x98, // idProduct (0x9801) HID + 0x00, 0x01, // bcdDevice (1.00) + 0x01, // iManufacturer (String Index 1) + 0x02, // iProduct (String Index 2) + 0x00, // iSerialNumber (None) + 0x01, // bNumConfigurations +}; + +const ConfigurationDescriptor = [34]u8{ + // Configuration Descriptor (9 bytes) + 0x09, // bLength + 0x02, // bDescriptorType (Configuration) + 0x22, 0x00, // wTotalLength (34 bytes) + 0x01, // bNumInterfaces + 0x01, // bConfigurationValue + 0x00, // iConfiguration (None) + 0x80, // bmAttributes (Bus Powered) + 0x32, // bMaxPower (100 mA) + + // Interface Descriptor (9 bytes) + 0x09, // bLength + 0x04, // bDescriptorType (Interface) + 0x00, // bInterfaceNumber + 0x00, // bAlternateSetting + 0x01, // bNumEndpoints + 0x03, // bInterfaceClass (HID) + 0x01, // bInterfaceSubClass (Boot Interface) + 0x01, // bInterfaceProtocol (Keyboard) + 0x00, // iInterface (None) + + // HID Descriptor (9 bytes) + 0x09, // bLength + 0x21, // bDescriptorType (HID) + 0x11, 0x01, // bcdHID (1.11) + 0x00, // bCountryCode (Not Supported) + 0x01, // bNumDescriptors + 0x22, // bDescriptorType (Report) + 0x3F, 0x00, // wDescriptorLength (62 bytes) + + // Endpoint Descriptor (7 bytes) + 0x07, // bLength + 0x05, // bDescriptorType (Endpoint) + 0x81, // bEndpointAddress (EP1 IN) + 0x03, // bmAttributes (Interrupt) + 0x08, 0x00, // wMaxPacketSize (8 bytes) + 0x0A, // bInterval (10 ms) +}; + +const ReportDescriptor = [63]u8{ + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x06, // Usage (Keyboard) + 0xA1, 0x01, // Collection (Application) + + // Modifier Keys (Shift, Ctrl, Alt, etc) + 0x05, 0x07, // Usage Page (Key Codes) + 0x19, 0xE0, // Usage Minimum (0xE0) + 0x29, 0xE7, // Usage Maximum (0xE7) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x75, 0x01, // Report Size (1 bit) + 0x95, 0x08, // Report Count (8 bits) + 0x81, 0x02, // Input (Data, Var, Abs) + + // Reserved (1 byte) + 0x95, 0x01, // Report Count (1) + 0x75, 0x08, // Report Size (8) + 0x81, 0x01, // Input (Const) + + // Key Array (6 bytes) + 0x95, 0x06, // Report Count (6) + 0x75, 0x08, // Report Size (8) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x65, // Logical Maximum (101) + 0x05, 0x07, // Usage Page (Key Codes) + 0x19, 0x00, // Usage Minimum (0) + 0x29, 0x65, // Usage Maximum (101) + 0x81, 0x00, // Input (Data, Array) + + // Output (LEDs: Caps Lock, Num Lock, etc) + 0x95, 0x05, // Report Count (5) + 0x75, 0x01, // Report Size (1) + 0x05, 0x08, // Usage Page (LEDs) + 0x19, 0x01, // Usage Minimum (1) + 0x29, 0x05, // Usage Maximum (5) + 0x91, 0x02, // Output (Data, Var, Abs) + + // Reserved (3 bits) + 0x95, 0x01, // Report Count (1) + 0x75, 0x03, // Report Size (3) + 0x91, 0x01, // Output (Const) + 0xC0, // End Collection +}; + +// ============== HID Descriptor ================ + +//=============== USB DATA ================= +var EP0_RX_BUFFER: [64]u8 = undefined; +var HID_send: [8]u8 = .{0} ** 8; +var to_report: bool = false; +var device_addr: ?u7 = null; +var config: bool = false; +//=============== USB DATA ================= +//==========IR NEC ========== +const NecPkg = packed struct(u32) { + addr_h: u8, + addr_l: u8, + cmd: u8, + inv_cmd: u8, +}; +//==========IR NEC ========== + +const lang_id: descriptor.String = .from_lang(.English); +const prod_id: descriptor.String = .from_str("Zig Keyboard"); +const manu_id: descriptor.String = .from_str("RecursiveError"); +fn get_string(index: usize) []const u8 { + return switch (index) { + 0 => &lang_id.data, + 1 => &manu_id.data, + 2 => &prod_id.data, + else => &[_]u8{}, + }; +} + +//TODO port USB driver from RPxxxx USB HAL +fn get_descriptor(setup: []const u8, epc: EpControl) void { + const descriptor_type = setup[3]; + const descriptor_length: u16 = @as(u16, setup[6]) | (@as(u16, setup[7]) << 8); + + const buffer: []const u8 = switch (descriptor_type) { + 0x01 => &DeviceDescriptor, + 0x02 => &ConfigurationDescriptor, + 0x03 => get_string(setup[2]), + 0x22 => &ReportDescriptor, + else => { + return; + }, + }; + + const length = @min(buffer.len, descriptor_length); + epc.write_buffer(buffer[0..length]) catch unreachable; + epc.set_status(.TX, .Valid, .force_data1) catch unreachable; +} + +fn set_addr(recive_addr: u7, epc: EpControl) void { + device_addr = recive_addr; + epc.ZLP() catch unreachable; + epc.set_status(.TX, .Valid, .force_data1) catch unreachable; +} + +fn ep0_setup(epc: EpControl, _: ?*anyopaque) void { + epc.set_status(.RX, .Valid, .no_change) catch unreachable; + + const setup = epc.read_buffer(&EP0_RX_BUFFER) catch unreachable; + if (setup.len == 0) { + return; + } + + switch (setup[1]) { + 0x06 => get_descriptor(setup, epc), + 0x05 => set_addr(@intCast(setup[2]), epc), + 0x09 => { + epc.ZLP() catch unreachable; + epc.set_status(.TX, .Valid, .force_data1) catch unreachable; + config = true; + to_report = false; + }, + else => { + epc.ZLP() catch unreachable; + epc.set_status(.TX, .Valid, .force_data1) catch unreachable; + }, + } +} + +fn ep0_rx(epc: EpControl, _: ?*anyopaque) void { + epc.set_status(.RX, .Valid, .no_change) catch unreachable; +} + +fn ep0_tx(epc: EpControl, _: ?*anyopaque) void { + if (device_addr) |addr| { + usb_ll.set_addr(addr); + } + epc.set_status(.RX, .Valid, .endpoint_ctr) catch unreachable; +} + +fn ep1_tx(epc: EpControl, _: ?*anyopaque) void { + to_report = false; + epc.set_status(.TX, .Nak, .no_change) catch unreachable; +} + +//set clock to 72Mhz and USB to 48Mhz +//NOTE: USB clock must be exactly 48Mhz +fn config_clock() void { + RCC.CR.modify(.{ + .HSEON = 1, + }); + while (RCC.CR.read().HSERDY == 0) { + asm volatile ("nop"); + } + + RCC.CFGR.modify(.{ + .PLLSRC = rcc_v1.PLLSRC.HSE_Div_PREDIV, + .PLLMUL = rcc_v1.PLLMUL.Mul9, + }); + + RCC.CR.modify(.{ + .PLLON = 1, + }); + + while (RCC.CR.read().PLLRDY == 0) { + asm volatile ("nop"); + } + + flash.ACR.modify(.{ + .LATENCY = flash_v1.LATENCY.WS2, + .PRFTBE = 1, + }); + + RCC.CFGR.modify(.{ + .PPRE1 = rcc_v1.PPRE.Div2, + .USBPRE = rcc_v1.USBPRE.Div1_5, + }); + + RCC.CFGR.modify(.{ + .SW = rcc_v1.SW.PLL1_P, + }); + + while (RCC.CFGR.read().SWS != rcc_v1.SW.PLL1_P) { + asm volatile ("nop"); + } +} + +const endpoint0 = usb_ll.Endpoint{ + .ep_control = .EPC0, + .endpoint = 0, + .ep_type = .Control, + .ep_kind = false, + .rx_reset_state = .Valid, + .tx_reset_state = .Nak, + .rx_buffer_size = .{ .block_qtd = 2, .block_size = .@"32bytes" }, + .tx_buffer_size = 64, + .rx_callback = ep0_rx, + .tx_callback = ep0_tx, + .setup_callback = ep0_setup, +}; + +const endpoint1 = usb_ll.Endpoint{ + .ep_control = .EPC1, + .endpoint = 1, + .ep_type = .Interrupt, + .ep_kind = false, + .rx_reset_state = .Nak, + .tx_reset_state = .Nak, + .rx_buffer_size = .{ .block_qtd = 1, .block_size = .@"2bytes" }, + .tx_buffer_size = 16, + .tx_callback = ep1_tx, +}; + +//TODO: full HID report function +fn report(keys: []const u8) void { + const len = @min(keys.len, 6); + const epc = usb_ll.EpControl.EPC1; + const report_flag: *volatile bool = &to_report; + if (!config) return; + while (report_flag.*) {} + std.mem.copyForwards(u8, HID_send[3..], keys[0..len]); + epc.write_buffer(&HID_send) catch unreachable; + epc.set_status(.TX, .Valid, .endpoint_ctr) catch unreachable; + report_flag.* = true; +} + +fn init_IR() void { + + //enable IR EXTI + IR_pin.set_input_mode(.pull); + IR_pin.set_pull(.up); + peri.AFIO.EXTICR[0].modify(.{ .@"EXTI[0]" = 1 }); + peri.EXTI.IMR.modify(.{ .@"LINE[0]" = 1 }); + peri.EXTI.FTSR.modify(.{ .@"LINE[0]" = 1 }); + peri.EXTI.RTSR.modify(.{ .@"LINE[0]" = 1 }); + peri.EXTI.PR.modify(.{ .@"LINE[0]" = 1 }); + + //enable timer + peri.TIM3.CR1.raw = 0; + peri.TIM3.CR2.raw = 0; + peri.TIM3.SR.raw = 0; + + peri.TIM3.CR1.modify(.{ .CEN = 0 }); + peri.TIM3.CR1.modify(.{ + .URS = t_types.URS.CounterOnly, + .OPM = 1, + .DIR = t_types.DIR.Down, + .ARPE = 1, + }); + peri.TIM3.PSC = 72; + peri.TIM3.DIER.modify(.{ .UIE = 1 }); + + interrupt.enable(.EXTI0); + interrupt.enable(.TIM3); +} + +fn start_IR_timer() void { + peri.TIM3.SR.raw = 0; + peri.TIM3.CR1.modify(.{ .CEN = 0 }); + peri.TIM3.PSC = 72; + peri.TIM3.ARR.modify(.{ .ARR = @as(u16, 25_000) }); + peri.TIM3.EGR.modify(.{ .UG = 1 }); + peri.TIM3.CR1.modify(.{ .CEN = 1 }); +} + +fn stop_IR_timer() usize { + peri.TIM3.CR1.modify(.{ .CEN = 0 }); + const val = peri.TIM3.CNT.read().CNT; + peri.TIM3.SR.raw = 0; + return val; +} + +var ir_val: u64 = 0; +var ir_index: u6 = 0; + +fn IR_handler() callconv(.c) void { + const pin_state = IR_pin.read(); + if (pin_state == 0) { + const val = stop_IR_timer(); + if (val != 0) { + const bit = 25_000 - val; + switch (bit) { + 200...800 => { + ir_val &= ~(@as(u64, 0) << ir_index); + ir_index += 1; + ir_index = ir_index % 63; + }, + 1200...1900 => { + ir_val |= (@as(u64, 1) << ir_index); + ir_index += 1; + ir_index = ir_index % 63; + }, + 4200...4800 => { + ir_val = 0; + ir_index = 0; + }, + else => {}, + } + } + } else if (pin_state == 1) { + start_IR_timer(); + } + peri.EXTI.PR.modify(.{ .@"LINE[0]" = 1 }); +} + +var nec_report: NecPkg = undefined; +var nec_send: bool = false; +fn IR_timer_handler() callconv(.c) void { + const val: u32 = @truncate(ir_val); + const nec: NecPkg = @bitCast(val); + if (val == 0) { + nec_send = true; + } else { + nec_report = nec; + nec_send = true; + } + ir_index = 0; + ir_val = 0; + peri.TIM3.SR.raw = 0; +} + +fn nec_to_hid(nec_cmd: u8) u8 { + return switch (nec_cmd) { + 0x1D => 0x52, //arrow up + 0x45 => 0x51, //arrow down + 0x40 => 0x50, //arrow left + 0x43 => 0x4F, //arrow right + 0x41 => 0x20, //enter + 0x0e => 0x29, //esc + else => nec_cmd, + }; +} + +pub fn main() !void { + config_clock(); + + RCC.APB2ENR.modify(.{ + .AFIOEN = 1, + .GPIOAEN = 1, + .GPIOBEN = 1, + .GPIOCEN = 1, + }); + + RCC.APB1ENR.modify(.{ + .TIM2EN = 1, + .TIM3EN = 1, + .USBEN = 1, + }); + Counter = timer.counter_device(72_000_000); + + //NOTE: the stm32f103 does not have an internal 1.5k pull-up resistor for USB, you must add one externally + interrupt.enable_interrupts(); + usb_ll.usb_init(&.{ endpoint0, endpoint1 }, Counter.make_ms_timeout(25)) catch unreachable; + init_IR(); + //interrupt.enable(.USB_LP_CAN1_RX0); + const nec: *volatile bool = &nec_send; + const n_report: *volatile NecPkg = &nec_report; + while (true) { + if (nec.*) { + report(&.{n_report.cmd}); + nec_send = false; + } else { + report(&.{ 0, 0, 0, 0, 0 }); + } + Counter.sleep_ms(10); + } +} diff --git a/examples/stmicro/stm32/src/stm32l476/lcd.zig b/examples/stmicro/stm32/src/stm32l476/lcd.zig index 5ea7a127d..66bb44a2c 100644 --- a/examples/stmicro/stm32/src/stm32l476/lcd.zig +++ b/examples/stmicro/stm32/src/stm32l476/lcd.zig @@ -11,6 +11,14 @@ fn delay() void { } } +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn init() void { hal.rcc.enable_rtc_lcd(); } diff --git a/examples/texasinstruments/msp430/src/blinky.zig b/examples/texasinstruments/msp430/src/blinky.zig index f98471b3b..b08a8dbdf 100644 --- a/examples/texasinstruments/msp430/src/blinky.zig +++ b/examples/texasinstruments/msp430/src/blinky.zig @@ -4,6 +4,13 @@ const watchdog = microzig.hal.watchdog; const launchpad = microzig.board; const green_led = launchpad.green_led; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub const panic = std.debug.no_panic; pub fn main() void { diff --git a/examples/texasinstruments/msp430/src/empty.zig b/examples/texasinstruments/msp430/src/empty.zig index e27dda337..a63cc8215 100644 --- a/examples/texasinstruments/msp430/src/empty.zig +++ b/examples/texasinstruments/msp430/src/empty.zig @@ -1,4 +1,13 @@ const std = @import("std"); +const microzig = @import("microzig"); + + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub const panic = std.debug.no_panic; pub fn main() void {} diff --git a/examples/texasinstruments/tm4c/src/empty.zig b/examples/texasinstruments/tm4c/src/empty.zig index 902b554db..3134c2159 100644 --- a/examples/texasinstruments/tm4c/src/empty.zig +++ b/examples/texasinstruments/tm4c/src/empty.zig @@ -1 +1,11 @@ +const microzig = @import("microzig"); + +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void {} diff --git a/examples/wch/ch32v/src/blinky.zig b/examples/wch/ch32v/src/blinky.zig index 4ea8ae75d..05c4b9c67 100644 --- a/examples/wch/ch32v/src/blinky.zig +++ b/examples/wch/ch32v/src/blinky.zig @@ -17,6 +17,14 @@ const pin_config = hal.pins.GlobalConfiguration{ }, }; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { const pins = pin_config.apply(); diff --git a/examples/wch/ch32v/src/blinky_systick.zig b/examples/wch/ch32v/src/blinky_systick.zig index f24515a02..d2fbff730 100644 --- a/examples/wch/ch32v/src/blinky_systick.zig +++ b/examples/wch/ch32v/src/blinky_systick.zig @@ -9,6 +9,14 @@ const led = if (cpu.cpu_name == .@"qingkev2-rv32ec") else hal.gpio.Pin.init(0, 3); // PA3 +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub const microzig_options: microzig.Options = .{ .overwrite_hal_interrupts = true, .interrupts = .{ diff --git a/examples/wch/ch32v/src/board_blinky.zig b/examples/wch/ch32v/src/board_blinky.zig index 3ca9a0dda..037eeb142 100644 --- a/examples/wch/ch32v/src/board_blinky.zig +++ b/examples/wch/ch32v/src/board_blinky.zig @@ -12,6 +12,14 @@ const board = microzig.board; // }, // }; +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { // Board brings up clocks and time board.init(); diff --git a/examples/wch/ch32v/src/dma.zig b/examples/wch/ch32v/src/dma.zig index b11168832..ddb72f2a9 100644 --- a/examples/wch/ch32v/src/dma.zig +++ b/examples/wch/ch32v/src/dma.zig @@ -9,10 +9,16 @@ const time = hal.time; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = hal.usart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} // Should be in flash .rodata const rbuf: [1024]u32 = .{0x12345678} ** 1024; diff --git a/examples/wch/ch32v/src/empty.zig b/examples/wch/ch32v/src/empty.zig index 79359fc54..53a194ebb 100644 --- a/examples/wch/ch32v/src/empty.zig +++ b/examples/wch/ch32v/src/empty.zig @@ -1,5 +1,13 @@ const microzig = @import("microzig"); +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { asm volatile ("nop"); // while (true) { diff --git a/examples/wch/ch32v/src/i2c_bus_scan.zig b/examples/wch/ch32v/src/i2c_bus_scan.zig index 2ce5e3937..cae0c9f07 100644 --- a/examples/wch/ch32v/src/i2c_bus_scan.zig +++ b/examples/wch/ch32v/src/i2c_bus_scan.zig @@ -8,10 +8,16 @@ const i2c = hal.i2c; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = hal.usart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { // Board brings up clocks and time diff --git a/examples/wch/ch32v/src/i2c_eeprom.zig b/examples/wch/ch32v/src/i2c_eeprom.zig index 535837ec3..e91b879c7 100644 --- a/examples/wch/ch32v/src/i2c_eeprom.zig +++ b/examples/wch/ch32v/src/i2c_eeprom.zig @@ -8,10 +8,16 @@ const i2c = hal.i2c; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = hal.usart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} fn hex_dump(data: []const u8) void { var offset: usize = 0; diff --git a/examples/wch/ch32v/src/i2c_position_sensor.zig b/examples/wch/ch32v/src/i2c_position_sensor.zig index 0c056bb45..68b1a6280 100644 --- a/examples/wch/ch32v/src/i2c_position_sensor.zig +++ b/examples/wch/ch32v/src/i2c_position_sensor.zig @@ -12,10 +12,16 @@ const AS5600 = microzig.drivers.sensor.AS5600; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .info, .logFn = hal.usart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { // Board brings up clocks and time diff --git a/examples/wch/ch32v/src/sharp_niceview.zig b/examples/wch/ch32v/src/sharp_niceview.zig index 34d386636..2b7feb2e0 100644 --- a/examples/wch/ch32v/src/sharp_niceview.zig +++ b/examples/wch/ch32v/src/sharp_niceview.zig @@ -38,10 +38,16 @@ const spi = hal.spi; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .info, .logFn = hal.usart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} // Pin definitions const sck_pin = gpio.Pin.init(0, 5); // PA5 diff --git a/examples/wch/ch32v/src/spi_flash_w25q.zig b/examples/wch/ch32v/src/spi_flash_w25q.zig index b087e7290..5f6e27b78 100644 --- a/examples/wch/ch32v/src/spi_flash_w25q.zig +++ b/examples/wch/ch32v/src/spi_flash_w25q.zig @@ -28,10 +28,16 @@ const spi = hal.spi; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = hal.usart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} // W25Q128 Commands const W25Q_CMD = struct { diff --git a/examples/wch/ch32v/src/spi_loopback.zig b/examples/wch/ch32v/src/spi_loopback.zig index 1635141b9..1b79afe14 100644 --- a/examples/wch/ch32v/src/spi_loopback.zig +++ b/examples/wch/ch32v/src/spi_loopback.zig @@ -23,10 +23,16 @@ const spi = hal.spi; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = hal.usart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { // Board brings up clocks and time diff --git a/examples/wch/ch32v/src/uart_log.zig b/examples/wch/ch32v/src/uart_log.zig index d99db5a1c..cb2bc7dc8 100644 --- a/examples/wch/ch32v/src/uart_log.zig +++ b/examples/wch/ch32v/src/uart_log.zig @@ -10,10 +10,16 @@ const AFIO = microzig.chip.peripherals.AFIO; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 -pub const microzig_options = microzig.Options{ +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = hal.usart.log, -}; +}); + +comptime { + _ = microzig.export_startup(); +} pub fn main() !void { // Board brings up clocks and time diff --git a/examples/wch/ch32v/src/ws2812.zig b/examples/wch/ch32v/src/ws2812.zig index 1f5cfc493..4ae43df13 100644 --- a/examples/wch/ch32v/src/ws2812.zig +++ b/examples/wch/ch32v/src/ws2812.zig @@ -5,6 +5,14 @@ const cpu = microzig.cpu; // Taken from https://github.com/robinjanssens/WCH-Toolchain +pub const panic = microzig.panic; + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() !void { // Board brings up clocks and time board.init(); diff --git a/website/content/docs/getting-started.smd b/website/content/docs/getting-started.smd index 2e1cd454e..2d352d3f4 100644 --- a/website/content/docs/getting-started.smd +++ b/website/content/docs/getting-started.smd @@ -79,6 +79,13 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; +pub const panic = microzig.panic; +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + // Compile-time pin configuration const pin_config = rp2xxx.pins.GlobalConfiguration{ .GPIO25 = .{ From ec0db399f94825eaa242f3c26d1fb299ee9a879a Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Mon, 27 Apr 2026 09:45:26 -0700 Subject: [PATCH 02/19] Remove accidental 0.16 --- core/src/microzig.zig | 4 ++-- examples/texasinstruments/msp430/src/blinky.zig | 1 - examples/texasinstruments/msp430/src/empty.zig | 1 - tools/package-test/src/empty.zig | 9 +++++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/src/microzig.zig b/core/src/microzig.zig index bb70d9558..b375dac86 100644 --- a/core/src/microzig.zig +++ b/core/src/microzig.zig @@ -120,7 +120,7 @@ pub const StdOptions = struct { log_scope_levels: []const std.log.ScopeLevel = &.{}, logFn: fn ( comptime message_level: std.log.Level, - comptime scope: @EnumLiteral(), + comptime scope: @TypeOf(.enum_literal), comptime format: []const u8, args: anytype, ) void = no_op_log, @@ -141,7 +141,7 @@ pub fn std_options(comptime overrides: StdOptions) std.Options { fn no_op_log( comptime _: std.log.Level, - comptime _: @EnumLiteral(), + comptime _: @TypeOf(.enum_literal), comptime _: []const u8, _: anytype, ) void {} diff --git a/examples/texasinstruments/msp430/src/blinky.zig b/examples/texasinstruments/msp430/src/blinky.zig index b08a8dbdf..210f9c47d 100644 --- a/examples/texasinstruments/msp430/src/blinky.zig +++ b/examples/texasinstruments/msp430/src/blinky.zig @@ -4,7 +4,6 @@ const watchdog = microzig.hal.watchdog; const launchpad = microzig.board; const green_led = launchpad.green_led; - pub const std_options = microzig.std_options(.{}); comptime { diff --git a/examples/texasinstruments/msp430/src/empty.zig b/examples/texasinstruments/msp430/src/empty.zig index a63cc8215..afe74bf57 100644 --- a/examples/texasinstruments/msp430/src/empty.zig +++ b/examples/texasinstruments/msp430/src/empty.zig @@ -2,7 +2,6 @@ const std = @import("std"); const microzig = @import("microzig"); - pub const std_options = microzig.std_options(.{}); comptime { diff --git a/tools/package-test/src/empty.zig b/tools/package-test/src/empty.zig index 902b554db..6dfe7b420 100644 --- a/tools/package-test/src/empty.zig +++ b/tools/package-test/src/empty.zig @@ -1 +1,10 @@ +const microzig = @import("microzig"); + +pub const panic = microzig.panic; +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + pub fn main() void {} From e5d6ad22302ef9c5d0db9095a65a79524090816b Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Mon, 27 Apr 2026 11:32:21 -0700 Subject: [PATCH 03/19] log fn fixes --- examples/raspberrypi/rp2xxx/src/board_id.zig | 2 -- examples/raspberrypi/rp2xxx/src/dma.zig | 2 -- examples/raspberrypi/rp2xxx/src/flash_program.zig | 2 -- examples/raspberrypi/rp2xxx/src/net/irq.zig | 9 ++++----- examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig | 2 -- examples/raspberrypi/rp2xxx/src/stepper_driver.zig | 2 -- examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig | 2 -- examples/raspberrypi/rp2xxx/src/system_timer.zig | 9 ++++----- examples/raspberrypi/rp2xxx/src/uart_log.zig | 2 -- examples/raspberrypi/rp2xxx/src/usb_cdc.zig | 2 -- examples/raspberrypi/rp2xxx/src/usb_hid.zig | 2 -- 11 files changed, 8 insertions(+), 28 deletions(-) diff --git a/examples/raspberrypi/rp2xxx/src/board_id.zig b/examples/raspberrypi/rp2xxx/src/board_id.zig index eb6e8ec34..1c5ab22a0 100644 --- a/examples/raspberrypi/rp2xxx/src/board_id.zig +++ b/examples/raspberrypi/rp2xxx/src/board_id.zig @@ -8,8 +8,6 @@ const gpio = rp2xxx.gpio; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, diff --git a/examples/raspberrypi/rp2xxx/src/dma.zig b/examples/raspberrypi/rp2xxx/src/dma.zig index c179c360e..cb83fe190 100644 --- a/examples/raspberrypi/rp2xxx/src/dma.zig +++ b/examples/raspberrypi/rp2xxx/src/dma.zig @@ -19,8 +19,6 @@ fn transfer_from_slices(channel: dma.Channel, write_buf: []u8, read_buf: []const }); } -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, diff --git a/examples/raspberrypi/rp2xxx/src/flash_program.zig b/examples/raspberrypi/rp2xxx/src/flash_program.zig index 64b59e79b..68c35899f 100644 --- a/examples/raspberrypi/rp2xxx/src/flash_program.zig +++ b/examples/raspberrypi/rp2xxx/src/flash_program.zig @@ -12,8 +12,6 @@ const uart_tx_pin = gpio.num(0); const flash_target_offset: u32 = 256 * 1024; const flash_target_contents = @as([*]const u8, @ptrFromInt(rp2xxx.flash.XIP_BASE + flash_target_offset)); -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, diff --git a/examples/raspberrypi/rp2xxx/src/net/irq.zig b/examples/raspberrypi/rp2xxx/src/net/irq.zig index dfdca9349..57ffbc369 100644 --- a/examples/raspberrypi/rp2xxx/src/net/irq.zig +++ b/examples/raspberrypi/rp2xxx/src/net/irq.zig @@ -22,23 +22,22 @@ const uart_tx_pin = gpio.num(0); pub const panic = microzig.panic; -pub const std_options = microzig.std_options(.{}); +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = rp2xxx.uart.log, +}); comptime { _ = microzig.export_startup(); } pub const rp2040_options: microzig.Options = .{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, .interrupts = .{ .IO_IRQ_BANK0 = .{ .c = gpio_interrupt }, .TIMER_IRQ_0 = .{ .c = timer_interrupt }, }, }; pub const rp2350_options: microzig.Options = .{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, .interrupts = .{ .IO_IRQ_BANK0 = .{ .c = gpio_interrupt }, .TIMER0_IRQ_0 = .{ .c = timer_interrupt }, diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig index 0d6649bce..ee388fe99 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig @@ -13,8 +13,6 @@ const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, diff --git a/examples/raspberrypi/rp2xxx/src/stepper_driver.zig b/examples/raspberrypi/rp2xxx/src/stepper_driver.zig index e8d26f1f8..efd9f4fcf 100644 --- a/examples/raspberrypi/rp2xxx/src/stepper_driver.zig +++ b/examples/raspberrypi/rp2xxx/src/stepper_driver.zig @@ -10,8 +10,6 @@ const A4988 = microzig.drivers.stepper.A4988; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .logFn = rp2xxx.uart.log, }); diff --git a/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig b/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig index 795896f1d..3066ad83c 100644 --- a/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig +++ b/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig @@ -10,8 +10,6 @@ const ULN2003 = microzig.drivers.stepper.ULN2003; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .logFn = rp2xxx.uart.log, }); diff --git a/examples/raspberrypi/rp2xxx/src/system_timer.zig b/examples/raspberrypi/rp2xxx/src/system_timer.zig index b6a033acb..44a905563 100644 --- a/examples/raspberrypi/rp2xxx/src/system_timer.zig +++ b/examples/raspberrypi/rp2xxx/src/system_timer.zig @@ -14,21 +14,20 @@ const timer_irq = if (chip == .RP2040) .TIMER_IRQ_0 else .TIMER0_IRQ_0; pub const panic = microzig.panic; -pub const std_options = microzig.std_options(.{}); +pub const std_options = microzig.std_options(.{ + .log_level = .debug, + .logFn = rp2xxx.uart.log, +}); comptime { _ = microzig.export_startup(); } pub const rp2040_options: microzig.Options = .{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, .interrupts = .{ .TIMER_IRQ_0 = .{ .c = timer_interrupt } }, }; pub const rp2350_options: microzig.Options = .{ - .log_level = .debug, - .logFn = rp2xxx.uart.log, .interrupts = .{ .TIMER0_IRQ_0 = .{ .c = timer_interrupt } }, }; diff --git a/examples/raspberrypi/rp2xxx/src/uart_log.zig b/examples/raspberrypi/rp2xxx/src/uart_log.zig index 9aab8b9fe..a271c066b 100644 --- a/examples/raspberrypi/rp2xxx/src/uart_log.zig +++ b/examples/raspberrypi/rp2xxx/src/uart_log.zig @@ -8,8 +8,6 @@ const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .log_level = .debug, .logFn = rp2xxx.uart.log, diff --git a/examples/raspberrypi/rp2xxx/src/usb_cdc.zig b/examples/raspberrypi/rp2xxx/src/usb_cdc.zig index 1d0554b74..edb307f0b 100644 --- a/examples/raspberrypi/rp2xxx/src/usb_cdc.zig +++ b/examples/raspberrypi/rp2xxx/src/usb_cdc.zig @@ -32,8 +32,6 @@ var usb_controller: usb.DeviceController(.{ .reset = "", }}) = .init; -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .log_level = .debug, .log_scope_levels = &.{ diff --git a/examples/raspberrypi/rp2xxx/src/usb_hid.zig b/examples/raspberrypi/rp2xxx/src/usb_hid.zig index ebd49e247..e1a331624 100644 --- a/examples/raspberrypi/rp2xxx/src/usb_hid.zig +++ b/examples/raspberrypi/rp2xxx/src/usb_hid.zig @@ -6,8 +6,6 @@ const time = rp2xxx.time; const usb = microzig.core.usb; const USB_Device = rp2xxx.usb.Polled(.{}); -pub const panic = microzig.panic; - pub const std_options = microzig.std_options(.{ .log_level = .debug, .log_scope_levels = &.{ From e5a81e3932feaa6b58d70a951e8c56759808478d Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Mon, 27 Apr 2026 19:55:39 -0700 Subject: [PATCH 04/19] Remove unused imports --- core/src/cpus/cortex_m.zig | 2 -- core/src/microzig.zig | 1 - examples/gigadevice/gd32/src/blinky.zig | 1 - examples/gigadevice/gd32/src/empty.zig | 1 - examples/microchip/samd51/src/blinky.zig | 1 - examples/no_hal/stm32_l031/src/blinky.zig | 1 - examples/nordic/nrf5x/src/blinky.zig | 1 - examples/nordic/nrf5x/src/i2c_bus_scan.zig | 3 --- examples/nordic/nrf5x/src/i2c_hall_effect.zig | 1 - examples/nordic/nrf5x/src/i2c_position_sensor.zig | 1 - examples/nordic/nrf5x/src/i2c_temp.zig | 2 -- examples/nordic/nrf5x/src/microbit/display.zig | 1 - examples/nordic/nrf5x/src/semihosting.zig | 2 -- examples/raspberrypi/rp2xxx/src/allocator.zig | 1 - examples/raspberrypi/rp2xxx/src/blinky.zig | 1 - examples/raspberrypi/rp2xxx/src/blinky_core1.zig | 3 --- examples/raspberrypi/rp2xxx/src/board_blinky.zig | 1 - examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig | 1 - examples/raspberrypi/rp2xxx/src/custom_clock_config.zig | 3 --- examples/raspberrypi/rp2xxx/src/cyw43.zig | 1 - examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig | 2 -- examples/raspberrypi/rp2xxx/src/ds18b20.zig | 2 -- examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig | 2 -- examples/raspberrypi/rp2xxx/src/i2c_accel.zig | 1 - examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig | 1 - examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig | 1 - examples/raspberrypi/rp2xxx/src/net/irq.zig | 2 -- examples/raspberrypi/rp2xxx/src/net/pong.zig | 1 - examples/raspberrypi/rp2xxx/src/net/scan.zig | 1 - examples/raspberrypi/rp2xxx/src/net/tcp_client.zig | 1 - examples/raspberrypi/rp2xxx/src/net/tcp_server.zig | 1 - examples/raspberrypi/rp2xxx/src/net/udp.zig | 1 - examples/raspberrypi/rp2xxx/src/pwm.zig | 5 ----- examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig | 3 --- examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig | 1 - examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig | 1 - examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig | 1 - examples/raspberrypi/rp2xxx/src/rtt_log.zig | 2 -- examples/raspberrypi/rp2xxx/src/spi_master.zig | 1 - examples/raspberrypi/rp2xxx/src/spi_slave.zig | 1 - examples/raspberrypi/rp2xxx/src/squarewave.zig | 1 - examples/raspberrypi/rp2xxx/src/system_timer.zig | 1 - examples/raspberrypi/rp2xxx/src/uart_echo.zig | 2 -- examples/raspberrypi/rp2xxx/src/watchdog_timer.zig | 1 - examples/raspberrypi/rp2xxx/src/ws2812.zig | 1 - examples/stmicro/stm32/src/semihosting.zig | 1 - examples/stmicro/stm32/src/stm32f1xx/EXTI.zig | 2 -- examples/stmicro/stm32/src/stm32f1xx/hd44780.zig | 4 ---- examples/stmicro/stm32/src/stm32f1xx/spi.zig | 3 --- examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig | 2 -- examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig | 1 - examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig | 2 -- examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig | 2 -- examples/stmicro/stm32/src/stm32l476/lcd.zig | 1 - examples/wch/ch32v/src/blinky_systick.zig | 1 - examples/wch/ch32v/src/dma.zig | 2 -- examples/wch/ch32v/src/i2c_bus_scan.zig | 1 - examples/wch/ch32v/src/i2c_eeprom.zig | 1 - examples/wch/ch32v/src/i2c_position_sensor.zig | 2 -- examples/wch/ch32v/src/spi_flash_w25q.zig | 1 - examples/wch/ch32v/src/ws2812.zig | 1 - port/stmicro/stm32/src/hals/STM32F303/rcc.zig | 1 - 62 files changed, 94 deletions(-) diff --git a/core/src/cpus/cortex_m.zig b/core/src/cpus/cortex_m.zig index d483b861a..51c223631 100644 --- a/core/src/cpus/cortex_m.zig +++ b/core/src/cpus/cortex_m.zig @@ -2,7 +2,6 @@ const std = @import("std"); const builtin = @import("builtin"); const microzig = @import("microzig"); const mmio = microzig.mmio; -const shared = @import("cortex_m/shared_types.zig"); const VectorTable = microzig.chip.VectorTable; const Core = enum { @@ -1025,7 +1024,6 @@ pub fn export_startup_logic() void { const scs_base = 0xE000E000; const itm_base = 0xE0000000; -const dwt_base = 0xE0001000; const tpi_base = 0xE0040000; const coredebug_base = 0xE000EDF0; diff --git a/core/src/microzig.zig b/core/src/microzig.zig index b375dac86..a737630ce 100644 --- a/core/src/microzig.zig +++ b/core/src/microzig.zig @@ -5,7 +5,6 @@ const std = @import("std"); const root = @import("root"); -const builtin = @import("builtin"); /// Contains build-time generated configuration options for microzig. /// Contains a CPU target description, chip, board and cpu information diff --git a/examples/gigadevice/gd32/src/blinky.zig b/examples/gigadevice/gd32/src/blinky.zig index ea3b6e06f..111d68006 100644 --- a/examples/gigadevice/gd32/src/blinky.zig +++ b/examples/gigadevice/gd32/src/blinky.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const gd32 = microzig.hal; diff --git a/examples/gigadevice/gd32/src/empty.zig b/examples/gigadevice/gd32/src/empty.zig index dd929d740..fd597d92f 100644 --- a/examples/gigadevice/gd32/src/empty.zig +++ b/examples/gigadevice/gd32/src/empty.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); pub const panic = microzig.panic; diff --git a/examples/microchip/samd51/src/blinky.zig b/examples/microchip/samd51/src/blinky.zig index a907f4419..db2bcc16c 100644 --- a/examples/microchip/samd51/src/blinky.zig +++ b/examples/microchip/samd51/src/blinky.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); pub const panic = microzig.panic; diff --git a/examples/no_hal/stm32_l031/src/blinky.zig b/examples/no_hal/stm32_l031/src/blinky.zig index 9795b72c4..4a717e9d6 100644 --- a/examples/no_hal/stm32_l031/src/blinky.zig +++ b/examples/no_hal/stm32_l031/src/blinky.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const chip = microzig.chip; const RCC = chip.peripherals.RCC; diff --git a/examples/nordic/nrf5x/src/blinky.zig b/examples/nordic/nrf5x/src/blinky.zig index 4b219819a..0b3e2fc98 100644 --- a/examples/nordic/nrf5x/src/blinky.zig +++ b/examples/nordic/nrf5x/src/blinky.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const board = microzig.board; const nrf = microzig.hal; diff --git a/examples/nordic/nrf5x/src/i2c_bus_scan.zig b/examples/nordic/nrf5x/src/i2c_bus_scan.zig index cc43f2190..9dd14e2d0 100644 --- a/examples/nordic/nrf5x/src/i2c_bus_scan.zig +++ b/examples/nordic/nrf5x/src/i2c_bus_scan.zig @@ -1,6 +1,5 @@ const std = @import("std"); const microzig = @import("microzig"); -const time = microzig.drivers.time; const board = microzig.board; const nrf = microzig.hal; @@ -12,8 +11,6 @@ const uart = nrf.uart.num(0); const i2c0 = i2c.num(0); const i2c0dma = i2cdma.num(0); -const sleep_ms = nrf.time.sleep_ms; - pub const panic = microzig.panic; pub const std_options = microzig.std_options(.{ diff --git a/examples/nordic/nrf5x/src/i2c_hall_effect.zig b/examples/nordic/nrf5x/src/i2c_hall_effect.zig index 2d67f6bd8..0162a4a28 100644 --- a/examples/nordic/nrf5x/src/i2c_hall_effect.zig +++ b/examples/nordic/nrf5x/src/i2c_hall_effect.zig @@ -1,6 +1,5 @@ const std = @import("std"); const microzig = @import("microzig"); -const time = microzig.drivers.time; const board = microzig.board; const nrf = microzig.hal; diff --git a/examples/nordic/nrf5x/src/i2c_position_sensor.zig b/examples/nordic/nrf5x/src/i2c_position_sensor.zig index 9eaf881ac..634f16df3 100644 --- a/examples/nordic/nrf5x/src/i2c_position_sensor.zig +++ b/examples/nordic/nrf5x/src/i2c_position_sensor.zig @@ -1,6 +1,5 @@ const std = @import("std"); const microzig = @import("microzig"); -const time = microzig.drivers.time; const board = microzig.board; const nrf = microzig.hal; diff --git a/examples/nordic/nrf5x/src/i2c_temp.zig b/examples/nordic/nrf5x/src/i2c_temp.zig index 060f29ca8..d3f5861e3 100644 --- a/examples/nordic/nrf5x/src/i2c_temp.zig +++ b/examples/nordic/nrf5x/src/i2c_temp.zig @@ -1,6 +1,5 @@ const std = @import("std"); const microzig = @import("microzig"); -const time = microzig.drivers.time; const board = microzig.board; const nrf = microzig.hal; @@ -9,7 +8,6 @@ const TMP117 = microzig.drivers.sensor.TMP117; const i2c = nrf.i2c; const i2cdma = nrf.i2cdma; const gpio = nrf.gpio; -const peripherals = microzig.chip.peripherals; const I2C_Device = nrf.drivers.I2C_Device; const uart = nrf.uart.num(0); diff --git a/examples/nordic/nrf5x/src/microbit/display.zig b/examples/nordic/nrf5x/src/microbit/display.zig index 87bbc4263..4941c6460 100644 --- a/examples/nordic/nrf5x/src/microbit/display.zig +++ b/examples/nordic/nrf5x/src/microbit/display.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const nrf = microzig.hal; const time = nrf.time; diff --git a/examples/nordic/nrf5x/src/semihosting.zig b/examples/nordic/nrf5x/src/semihosting.zig index 6878800b9..ebdc350c8 100644 --- a/examples/nordic/nrf5x/src/semihosting.zig +++ b/examples/nordic/nrf5x/src/semihosting.zig @@ -1,7 +1,5 @@ -const std = @import("std"); const microzig = @import("microzig"); const board = microzig.board; -const nrf = microzig.hal; const semihosting = microzig.core.arm_semihosting; diff --git a/examples/raspberrypi/rp2xxx/src/allocator.zig b/examples/raspberrypi/rp2xxx/src/allocator.zig index 8bedcc0c5..8cb03af09 100644 --- a/examples/raspberrypi/rp2xxx/src/allocator.zig +++ b/examples/raspberrypi/rp2xxx/src/allocator.zig @@ -1,7 +1,6 @@ const std = @import("std"); const microzig = @import("microzig"); -const PPB = microzig.chip.peripherals.PPB; const hal = microzig.hal; const time = hal.time; diff --git a/examples/raspberrypi/rp2xxx/src/blinky.zig b/examples/raspberrypi/rp2xxx/src/blinky.zig index d62e935ae..1b2f82420 100644 --- a/examples/raspberrypi/rp2xxx/src/blinky.zig +++ b/examples/raspberrypi/rp2xxx/src/blinky.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; diff --git a/examples/raspberrypi/rp2xxx/src/blinky_core1.zig b/examples/raspberrypi/rp2xxx/src/blinky_core1.zig index c64dd4462..609b67fcb 100644 --- a/examples/raspberrypi/rp2xxx/src/blinky_core1.zig +++ b/examples/raspberrypi/rp2xxx/src/blinky_core1.zig @@ -1,9 +1,6 @@ -const std = @import("std"); - const microzig = @import("microzig"); const rp2xxx = microzig.hal; const board = microzig.board; -const gpio = rp2xxx.gpio; const time = rp2xxx.time; const multicore = rp2xxx.multicore; diff --git a/examples/raspberrypi/rp2xxx/src/board_blinky.zig b/examples/raspberrypi/rp2xxx/src/board_blinky.zig index 13240cd89..4c2bfa83f 100644 --- a/examples/raspberrypi/rp2xxx/src/board_blinky.zig +++ b/examples/raspberrypi/rp2xxx/src/board_blinky.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const board = microzig.board; diff --git a/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig b/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig index 718ad0bfe..b7642316d 100644 --- a/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig +++ b/examples/raspberrypi/rp2xxx/src/changing_system_clocks.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; diff --git a/examples/raspberrypi/rp2xxx/src/custom_clock_config.zig b/examples/raspberrypi/rp2xxx/src/custom_clock_config.zig index 70c389af4..e82a22060 100644 --- a/examples/raspberrypi/rp2xxx/src/custom_clock_config.zig +++ b/examples/raspberrypi/rp2xxx/src/custom_clock_config.zig @@ -1,12 +1,9 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; const time = rp2xxx.time; const clocks = rp2xxx.clocks; const GlobalConfig = clocks.config.Global; -const gpout0_pin = gpio.num(21); -const Pin = gpio.Pin; /// The HAL provides a convenvience function for detecting which of the RP2XXX /// family you're currently compiling for. diff --git a/examples/raspberrypi/rp2xxx/src/cyw43.zig b/examples/raspberrypi/rp2xxx/src/cyw43.zig index d9da52e6a..13b904227 100644 --- a/examples/raspberrypi/rp2xxx/src/cyw43.zig +++ b/examples/raspberrypi/rp2xxx/src/cyw43.zig @@ -6,7 +6,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const pio = rp2xxx.pio; const drivers = microzig.hal.drivers; var wifi_driver: drivers.WiFi = .{}; diff --git a/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig b/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig index 164793b1a..522faf1b0 100644 --- a/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig +++ b/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig @@ -6,9 +6,7 @@ const gpio = rp2xxx.gpio; const time = rp2xxx.time; const cyw43 = rp2xxx.cyw43; -const Wifi = cyw43.Wifi; const Security = cyw43.Security; -const Runner = cyw43.Runner; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/ds18b20.zig b/examples/raspberrypi/rp2xxx/src/ds18b20.zig index 4f9410e06..d8162b4eb 100644 --- a/examples/raspberrypi/rp2xxx/src/ds18b20.zig +++ b/examples/raspberrypi/rp2xxx/src/ds18b20.zig @@ -1,8 +1,6 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; -const gpio = rp2xxx.gpio; const DS18B20 = microzig.drivers.sensor.DS18B20; diff --git a/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig b/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig index 7dc3e991e..7822e8834 100644 --- a/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig +++ b/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig @@ -1,10 +1,8 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; const time = rp2xxx.time; const clocks = rp2xxx.clocks; -const Pin = rp2xxx.gpio.Pin; const gpout0_pin = gpio.num(21); diff --git a/examples/raspberrypi/rp2xxx/src/i2c_accel.zig b/examples/raspberrypi/rp2xxx/src/i2c_accel.zig index 3e9bac819..3f0e78634 100644 --- a/examples/raspberrypi/rp2xxx/src/i2c_accel.zig +++ b/examples/raspberrypi/rp2xxx/src/i2c_accel.zig @@ -5,7 +5,6 @@ const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; const i2c = rp2xxx.i2c; -const ClockDevice = rp2xxx.drivers.ClockDevice; const I2C_Device = rp2xxx.drivers.I2C_Device; const ICM_20948 = microzig.drivers.sensor.ICM_20948; diff --git a/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig b/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig index 5a9a56469..876758c73 100644 --- a/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig +++ b/examples/raspberrypi/rp2xxx/src/i2c_bus_scan.zig @@ -1,6 +1,5 @@ const std = @import("std"); const microzig = @import("microzig"); -const time = microzig.drivers.time; const rp2xxx = microzig.hal; const i2c = rp2xxx.i2c; diff --git a/examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig b/examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig index 1e756d82e..175c5c7a2 100644 --- a/examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig +++ b/examples/raspberrypi/rp2xxx/src/i2c_hall_effect.zig @@ -1,6 +1,5 @@ const std = @import("std"); const microzig = @import("microzig"); -const time = microzig.drivers.time; const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; diff --git a/examples/raspberrypi/rp2xxx/src/net/irq.zig b/examples/raspberrypi/rp2xxx/src/net/irq.zig index 57ffbc369..78abbede2 100644 --- a/examples/raspberrypi/rp2xxx/src/net/irq.zig +++ b/examples/raspberrypi/rp2xxx/src/net/irq.zig @@ -10,9 +10,7 @@ const std = @import("std"); const microzig = @import("microzig"); const cpu = microzig.cpu; const rp2xxx = microzig.hal; -const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const pio = rp2xxx.pio; const drivers = rp2xxx.drivers; const system_timer = rp2xxx.system_timer; const chip = rp2xxx.compatibility.chip; diff --git a/examples/raspberrypi/rp2xxx/src/net/pong.zig b/examples/raspberrypi/rp2xxx/src/net/pong.zig index 45dee2218..fa1985ce5 100644 --- a/examples/raspberrypi/rp2xxx/src/net/pong.zig +++ b/examples/raspberrypi/rp2xxx/src/net/pong.zig @@ -3,7 +3,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const pio = rp2xxx.pio; const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/net/scan.zig b/examples/raspberrypi/rp2xxx/src/net/scan.zig index a201d6ead..d754c4ea9 100644 --- a/examples/raspberrypi/rp2xxx/src/net/scan.zig +++ b/examples/raspberrypi/rp2xxx/src/net/scan.zig @@ -3,7 +3,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const pio = rp2xxx.pio; const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig b/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig index bb19efac9..ae034deac 100644 --- a/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig +++ b/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig @@ -3,7 +3,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const pio = rp2xxx.pio; const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig b/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig index f28beaa20..7a37e8f15 100644 --- a/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig +++ b/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig @@ -3,7 +3,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const pio = rp2xxx.pio; const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/net/udp.zig b/examples/raspberrypi/rp2xxx/src/net/udp.zig index 4a214e2c4..c839349e1 100644 --- a/examples/raspberrypi/rp2xxx/src/net/udp.zig +++ b/examples/raspberrypi/rp2xxx/src/net/udp.zig @@ -3,7 +3,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const pio = rp2xxx.pio; const drivers = rp2xxx.drivers; const uart = rp2xxx.uart.instance.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/pwm.zig b/examples/raspberrypi/rp2xxx/src/pwm.zig index dc7564396..e813e1230 100644 --- a/examples/raspberrypi/rp2xxx/src/pwm.zig +++ b/examples/raspberrypi/rp2xxx/src/pwm.zig @@ -1,11 +1,6 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; -const gpio = rp2xxx.gpio; -const clocks = rp2xxx.clocks; const time = rp2xxx.time; -const regs = microzig.chip.registers; -const multicore = rp2xxx.multicore; const pin_config = rp2xxx.pins.GlobalConfiguration{ .GPIO25 = .{ .name = "led", .function = .PWM4_B }, diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig index 59b215a94..6f8fd080f 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig @@ -1,15 +1,12 @@ -const std = @import("std"); const microzig = @import("microzig"); const drivers = microzig.drivers; const lcd = drivers.display.HD44780; const PCF8574 = drivers.IO_expander.PCF8574; -const State = drivers.base.Digital_IO.State; const rp2040 = microzig.hal; const i2c = rp2040.i2c; const I2C_Device = rp2040.drivers.I2C_Device; const gpio = rp2040.gpio; -const peripherals = microzig.chip.peripherals; const timer = rp2040.time; const i2c0 = i2c.instance.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig index 283a6479a..e46459346 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/pcf8574.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const drivers = microzig.drivers; diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig index ee388fe99..3b0f5d422 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig @@ -6,7 +6,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const clocks = rp2xxx.clocks; const rand = rp2xxx.rand; const led = gpio.num(25); diff --git a/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig b/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig index 7b6c04682..bac23acd4 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; diff --git a/examples/raspberrypi/rp2xxx/src/rtt_log.zig b/examples/raspberrypi/rp2xxx/src/rtt_log.zig index 7e8051767..cf9d3b5ea 100644 --- a/examples/raspberrypi/rp2xxx/src/rtt_log.zig +++ b/examples/raspberrypi/rp2xxx/src/rtt_log.zig @@ -3,8 +3,6 @@ const microzig = @import("microzig"); const mdf = microzig.drivers; const rp2xxx = microzig.hal; const time = rp2xxx.time; -const gpio = rp2xxx.gpio; -const led = gpio.num(25); /// Dummy example of defining a custom locking/unlocking mechanisms for thread safety // const pretend_thread_safety = struct { diff --git a/examples/raspberrypi/rp2xxx/src/spi_master.zig b/examples/raspberrypi/rp2xxx/src/spi_master.zig index 16e6c6a25..0c7f1d406 100644 --- a/examples/raspberrypi/rp2xxx/src/spi_master.zig +++ b/examples/raspberrypi/rp2xxx/src/spi_master.zig @@ -3,7 +3,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; -const gpio = rp2xxx.gpio; const BUF_LEN = 0x100; const spi = rp2xxx.spi.instance.SPI0; diff --git a/examples/raspberrypi/rp2xxx/src/spi_slave.zig b/examples/raspberrypi/rp2xxx/src/spi_slave.zig index f448e1e56..a2bbae0bd 100644 --- a/examples/raspberrypi/rp2xxx/src/spi_slave.zig +++ b/examples/raspberrypi/rp2xxx/src/spi_slave.zig @@ -4,7 +4,6 @@ const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const chip = rp2xxx.compatibility.chip; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/squarewave.zig b/examples/raspberrypi/rp2xxx/src/squarewave.zig index 1eda31051..e67a1517e 100644 --- a/examples/raspberrypi/rp2xxx/src/squarewave.zig +++ b/examples/raspberrypi/rp2xxx/src/squarewave.zig @@ -1,5 +1,4 @@ //! Hello world for the PIO module: generating a square wave -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; diff --git a/examples/raspberrypi/rp2xxx/src/system_timer.zig b/examples/raspberrypi/rp2xxx/src/system_timer.zig index 44a905563..d2c20aeb0 100644 --- a/examples/raspberrypi/rp2xxx/src/system_timer.zig +++ b/examples/raspberrypi/rp2xxx/src/system_timer.zig @@ -1,7 +1,6 @@ const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; -const time = rp2xxx.time; const system_timer = rp2xxx.system_timer; const chip = rp2xxx.compatibility.chip; diff --git a/examples/raspberrypi/rp2xxx/src/uart_echo.zig b/examples/raspberrypi/rp2xxx/src/uart_echo.zig index 0a22a72a5..cdba9f21e 100644 --- a/examples/raspberrypi/rp2xxx/src/uart_echo.zig +++ b/examples/raspberrypi/rp2xxx/src/uart_echo.zig @@ -1,10 +1,8 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const time = rp2xxx.time; const gpio = rp2xxx.gpio; -const clocks = rp2xxx.clocks; const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); diff --git a/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig b/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig index 4294ca256..71e61b68b 100644 --- a/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig +++ b/examples/raspberrypi/rp2xxx/src/watchdog_timer.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const watchdog = rp2xxx.watchdog; diff --git a/examples/raspberrypi/rp2xxx/src/ws2812.zig b/examples/raspberrypi/rp2xxx/src/ws2812.zig index 747b2fa57..7e468056b 100644 --- a/examples/raspberrypi/rp2xxx/src/ws2812.zig +++ b/examples/raspberrypi/rp2xxx/src/ws2812.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const rp2xxx = microzig.hal; const gpio = rp2xxx.gpio; diff --git a/examples/stmicro/stm32/src/semihosting.zig b/examples/stmicro/stm32/src/semihosting.zig index b679549e4..b261545c1 100644 --- a/examples/stmicro/stm32/src/semihosting.zig +++ b/examples/stmicro/stm32/src/semihosting.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const semihosting = microzig.core.arm_semihosting; diff --git a/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig b/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig index d942d3064..2c2ebed6f 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig @@ -4,8 +4,6 @@ const microzig = @import("microzig"); const hal = microzig.hal; -const gpio = hal.gpio; -const rcc = hal.rcc; const exti = hal.exti; const led = hal.gpio.Pin.from_port(.B, 2); diff --git a/examples/stmicro/stm32/src/stm32f1xx/hd44780.zig b/examples/stmicro/stm32/src/stm32f1xx/hd44780.zig index 5ddc6f787..205a01a2a 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/hd44780.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/hd44780.zig @@ -1,17 +1,13 @@ -const std = @import("std"); const microzig = @import("microzig"); const stm32 = microzig.hal; const rcc = stm32.rcc; const gpio = stm32.gpio; const time = stm32.time; -const Duration = microzig.drivers.time.Duration; const drivers = microzig.drivers; -const lcd_driver = drivers.display.hd44780; const lcd = drivers.display.HD44780; const PCF8574 = drivers.IO_expander.PCF8574; -const State = drivers.base.Digital_IO.State; const I2C = stm32.i2c; const I2C_Device = stm32.drivers.I2C_Device; diff --git a/examples/stmicro/stm32/src/stm32f1xx/spi.zig b/examples/stmicro/stm32/src/stm32f1xx/spi.zig index 2e6d2aae8..e31ef5ef6 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/spi.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/spi.zig @@ -1,13 +1,10 @@ -const std = @import("std"); const microzig = @import("microzig"); const stm32 = microzig.hal; const rcc = stm32.rcc; -const GPTimer = stm32.timer.GPTimer; const gpio = stm32.gpio; const SPI = stm32.spi.SPI; const time = stm32.time; -const Duration = microzig.drivers.time.Duration; const spi = SPI.init(.SPI2); const MOSI = gpio.Pin.from_port(.B, 15); diff --git a/examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig b/examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig index c7d47f570..69c6f3f2d 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/ssd1306.zig @@ -1,11 +1,9 @@ -const std = @import("std"); const microzig = @import("microzig"); const stm32 = microzig.hal; const gpio = stm32.gpio; const rcc = stm32.rcc; const time = stm32.time; -const Duration = microzig.drivers.time.Duration; const drivers = microzig.drivers; const lcd_driver = drivers.display.SSD1306_I2C; diff --git a/examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig b/examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig index 48e94b26f..041ae068a 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/uart_echo.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const stm32 = microzig.hal; diff --git a/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig b/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig index 9b172045c..5aef66ca1 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig @@ -14,8 +14,6 @@ const descriptor = microzig.core.usb.descriptor; const EpControl = usb_ll.EpControl; -var Counter: stm32.drivers.CounterDevice = undefined; - pub const panic = microzig.panic; pub const std_options = microzig.std_options(.{}); pub const microzig_options: microzig.Options = .{ diff --git a/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig b/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig index a588713f5..3ae081e9f 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig @@ -3,8 +3,6 @@ const std = @import("std"); const microzig = @import("microzig"); -const host = microzig.core.arm_semihosting; - const RCC = microzig.chip.peripherals.RCC; const flash = microzig.chip.peripherals.FLASH; const rcc_v1 = microzig.chip.types.peripherals.rcc_f1; diff --git a/examples/stmicro/stm32/src/stm32l476/lcd.zig b/examples/stmicro/stm32/src/stm32l476/lcd.zig index 66bb44a2c..9e803b5a0 100644 --- a/examples/stmicro/stm32/src/stm32l476/lcd.zig +++ b/examples/stmicro/stm32/src/stm32l476/lcd.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const hal = microzig.hal; const board = microzig.board; diff --git a/examples/wch/ch32v/src/blinky_systick.zig b/examples/wch/ch32v/src/blinky_systick.zig index d2fbff730..a027fcc2b 100644 --- a/examples/wch/ch32v/src/blinky_systick.zig +++ b/examples/wch/ch32v/src/blinky_systick.zig @@ -1,4 +1,3 @@ -const std = @import("std"); const microzig = @import("microzig"); const hal = microzig.hal; const cpu = microzig.cpu; diff --git a/examples/wch/ch32v/src/dma.zig b/examples/wch/ch32v/src/dma.zig index ddb72f2a9..6f012aa66 100644 --- a/examples/wch/ch32v/src/dma.zig +++ b/examples/wch/ch32v/src/dma.zig @@ -1,10 +1,8 @@ const std = @import("std"); const microzig = @import("microzig"); -const mdf = microzig.drivers; const hal = microzig.hal; const gpio = hal.gpio; const dma = hal.dma; -const time = hal.time; const usart = hal.usart.instance.USART2; const usart_tx_pin = gpio.Pin.init(0, 2); // PA2 diff --git a/examples/wch/ch32v/src/i2c_bus_scan.zig b/examples/wch/ch32v/src/i2c_bus_scan.zig index cae0c9f07..dda1b4f34 100644 --- a/examples/wch/ch32v/src/i2c_bus_scan.zig +++ b/examples/wch/ch32v/src/i2c_bus_scan.zig @@ -1,6 +1,5 @@ const std = @import("std"); const microzig = @import("microzig"); -const mdf = microzig.drivers; const hal = microzig.hal; const gpio = hal.gpio; const i2c = hal.i2c; diff --git a/examples/wch/ch32v/src/i2c_eeprom.zig b/examples/wch/ch32v/src/i2c_eeprom.zig index e91b879c7..873b4cff6 100644 --- a/examples/wch/ch32v/src/i2c_eeprom.zig +++ b/examples/wch/ch32v/src/i2c_eeprom.zig @@ -1,6 +1,5 @@ const std = @import("std"); const microzig = @import("microzig"); -const mdf = microzig.drivers; const hal = microzig.hal; const gpio = hal.gpio; const i2c = hal.i2c; diff --git a/examples/wch/ch32v/src/i2c_position_sensor.zig b/examples/wch/ch32v/src/i2c_position_sensor.zig index 68b1a6280..c4a791c55 100644 --- a/examples/wch/ch32v/src/i2c_position_sensor.zig +++ b/examples/wch/ch32v/src/i2c_position_sensor.zig @@ -1,12 +1,10 @@ const std = @import("std"); const microzig = @import("microzig"); -const mdf = microzig.drivers; const hal = microzig.hal; const gpio = hal.gpio; const i2c = hal.i2c; -const I2C_Device = hal.drivers.I2C_Device; const AS5600 = microzig.drivers.sensor.AS5600; const usart = hal.usart.instance.USART2; diff --git a/examples/wch/ch32v/src/spi_flash_w25q.zig b/examples/wch/ch32v/src/spi_flash_w25q.zig index 5f6e27b78..8a9628146 100644 --- a/examples/wch/ch32v/src/spi_flash_w25q.zig +++ b/examples/wch/ch32v/src/spi_flash_w25q.zig @@ -61,7 +61,6 @@ const W25Q_STATUS = struct { // Flash configuration const JEDEC_ID_EXPECTED: u24 = 0xEF4018; // Winbond W25Q128 const PAGE_SIZE: usize = 256; -const SECTOR_SIZE: usize = 4096; // CS pin const cs_pin = gpio.Pin.init(0, 3); // PA3 diff --git a/examples/wch/ch32v/src/ws2812.zig b/examples/wch/ch32v/src/ws2812.zig index 4ae43df13..baf5afade 100644 --- a/examples/wch/ch32v/src/ws2812.zig +++ b/examples/wch/ch32v/src/ws2812.zig @@ -1,7 +1,6 @@ const microzig = @import("microzig"); const board = microzig.board; const hal = microzig.hal; -const cpu = microzig.cpu; // Taken from https://github.com/robinjanssens/WCH-Toolchain diff --git a/port/stmicro/stm32/src/hals/STM32F303/rcc.zig b/port/stmicro/stm32/src/hals/STM32F303/rcc.zig index c1ec8ac9d..0faae3040 100644 --- a/port/stmicro/stm32/src/hals/STM32F303/rcc.zig +++ b/port/stmicro/stm32/src/hals/STM32F303/rcc.zig @@ -18,7 +18,6 @@ pub const Config = Tree.Config; const RCC = microzig.chip.peripherals.RCC; const FLASH = microzig.chip.peripherals.FLASH; const LATENCY = microzig.chip.types.peripherals.flash_f3.LATENCY; -const PREDIV = microzig.chip.types.peripherals.rcc_f3v1.PREDIV; const HPRE = microzig.chip.types.peripherals.rcc_f3v1.HPRE; const PPRE = microzig.chip.types.peripherals.rcc_f3v1.PPRE; const ADCPRES = microzig.chip.types.peripherals.rcc_f3v1.ADCPRES; From 3ea7523bc8e974f072a3a91034fae19fa88b29e6 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Fri, 1 May 2026 11:03:45 -0700 Subject: [PATCH 05/19] test: add forceUndefinedSymbol for microzig_main and disable sorcerer CI --- build.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/build.zig b/build.zig index 1de33fb15..afa5ea30b 100644 --- a/build.zig +++ b/build.zig @@ -516,6 +516,7 @@ pub fn MicroBuild(port_select: PortSelect) type { fw.artifact.link_function_sections = options.strip_unused_symbols; fw.artifact.link_data_sections = options.strip_unused_symbols; fw.artifact.entry = options.entry orelse target.entry orelse .default; + fw.artifact.forceUndefinedSymbol("microzig_main"); const linker_script_options = options.linker_script orelse target.linker_script; const linker_script = blk: { From 16d1999b5247f7847b89d9f6659fa62ef68db2a1 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Fri, 1 May 2026 11:29:42 -0700 Subject: [PATCH 06/19] build: replace forceUndefinedSymbol with linker script ASSERT for microzig_main --- build.zig | 1 - tools/generate_linker_script.zig | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index afa5ea30b..1de33fb15 100644 --- a/build.zig +++ b/build.zig @@ -516,7 +516,6 @@ pub fn MicroBuild(port_select: PortSelect) type { fw.artifact.link_function_sections = options.strip_unused_symbols; fw.artifact.link_data_sections = options.strip_unused_symbols; fw.artifact.entry = options.entry orelse target.entry orelse .default; - fw.artifact.forceUndefinedSymbol("microzig_main"); const linker_script_options = options.linker_script orelse target.linker_script; const linker_script = blk: { diff --git a/tools/generate_linker_script.zig b/tools/generate_linker_script.zig index ef1f4079b..e7cc4162e 100644 --- a/tools/generate_linker_script.zig +++ b/tools/generate_linker_script.zig @@ -301,5 +301,11 @@ pub fn main() !void { try writer.interface.writeAll(user_linker_script); } + try writer.interface.writeAll( + \\ + \\ASSERT(DEFINED(microzig_main), "microzig: microzig_main is not defined. Add `comptime { _ = microzig.export_startup(); }` to your root source file.") + \\ + ); + try writer.interface.flush(); } From 0c276003463d05bc752c25eaf83ff1af5592ba56 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Fri, 1 May 2026 11:50:37 -0700 Subject: [PATCH 07/19] docs: add boilerplate page and link from linker assertion --- tools/generate_linker_script.zig | 2 +- website/content/docs.smd | 1 + website/content/docs/boilerplate.smd | 120 +++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 website/content/docs/boilerplate.smd diff --git a/tools/generate_linker_script.zig b/tools/generate_linker_script.zig index e7cc4162e..e9559c66d 100644 --- a/tools/generate_linker_script.zig +++ b/tools/generate_linker_script.zig @@ -303,7 +303,7 @@ pub fn main() !void { try writer.interface.writeAll( \\ - \\ASSERT(DEFINED(microzig_main), "microzig: microzig_main is not defined. Add `comptime { _ = microzig.export_startup(); }` to your root source file.") + \\ASSERT(DEFINED(microzig_main), "microzig: microzig_main is not defined. See https://microzig.tech/docs/boilerplate for the required root source boilerplate.") \\ ); diff --git a/website/content/docs.smd b/website/content/docs.smd index f322f6f29..3f3e28a96 100644 --- a/website/content/docs.smd +++ b/website/content/docs.smd @@ -11,6 +11,7 @@ # Documentation - [Getting Started](docs/getting-started) +- [Application Boilerplate](docs/boilerplate) - [Contributing Guidelines](docs/contributing) - [MicroZig Internals](docs/internals) - How Tos: diff --git a/website/content/docs/boilerplate.smd b/website/content/docs/boilerplate.smd new file mode 100644 index 000000000..bf8f16370 --- /dev/null +++ b/website/content/docs/boilerplate.smd @@ -0,0 +1,120 @@ +--- +.title = "Application Boilerplate", +.date = @date("2026-05-01T00:00:00"), +.author = "Matthew Knight", +.draft = false, +.layout = "index.shtml", +.description = "MicroZig: Application Boilerplate", +.tags = [] +--- + +# Application Boilerplate + +Every MicroZig firmware executable needs a small amount of boilerplate in its +root source file. This page explains what each piece does and why it's required. + +## The Minimal Root Source File + +Here is the smallest valid MicroZig application: + +```zig +const std = @import("std"); +const microzig = @import("microzig"); + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + +pub const panic = microzig.panic; + +pub fn main() void {} +``` + +Let's walk through each part. + +## `std_options` + +```zig +pub const std_options = microzig.std_options(.{}); +``` + +MicroZig provides its own `std_options` configuration that sets up logging and +other standard library options appropriate for bare-metal targets. You pass an +anonymous struct to configure logging: + +```zig +pub const std_options = microzig.std_options(.{ + .log_level = .debug, +}); +``` + +## `export_startup` + +```zig +comptime { + _ = microzig.export_startup(); +} +``` + +This is the most important line. It exports the startup code and vector table +that the MCU needs to begin executing your program. Without this call, the +linker will emit an error: + +``` +error: ld.lld: microzig: microzig_main is not defined. +Add `comptime { _ = microzig.export_startup(); }` to your root source file. +``` + +If you see this error, make sure your root source file contains the `comptime` +block shown above. + +## `panic` + +```zig +pub const panic = microzig.panic; +``` + +This sets the panic handler to MicroZig's default, which typically enters an +infinite loop. You can override this with a custom handler if you need different +behavior (e.g., logging to UART, triggering a watchdog reset): + +```zig +pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { + @panic(message); +} +``` + +## `main` + +```zig +pub fn main() void {} +``` + +Your application entry point. This is called after MicroZig has initialized the +hardware (clocks, BSS section, data relocation, etc.). The signature is `void` +return — on embedded targets there is nowhere to return to. + +## Custom Panic Handlers + +Some examples define their own panic handler instead of using the default. In +that case, omit the `pub const panic = microzig.panic` line: + +```zig +const std = @import("std"); +const microzig = @import("microzig"); + +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} + +pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { + // Custom panic behavior + while (true) {} +} + +pub fn main() void {} +``` From 2f302d45ec30e83f2b4e151a383fc87c59e9384f Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Fri, 1 May 2026 11:53:28 -0700 Subject: [PATCH 08/19] docs: stub out boilerplate page for author to fill in --- website/content/docs/boilerplate.smd | 109 +-------------------------- 1 file changed, 1 insertion(+), 108 deletions(-) diff --git a/website/content/docs/boilerplate.smd b/website/content/docs/boilerplate.smd index bf8f16370..b0af83f9a 100644 --- a/website/content/docs/boilerplate.smd +++ b/website/content/docs/boilerplate.smd @@ -10,111 +10,4 @@ # Application Boilerplate -Every MicroZig firmware executable needs a small amount of boilerplate in its -root source file. This page explains what each piece does and why it's required. - -## The Minimal Root Source File - -Here is the smallest valid MicroZig application: - -```zig -const std = @import("std"); -const microzig = @import("microzig"); - -pub const std_options = microzig.std_options(.{}); - -comptime { - _ = microzig.export_startup(); -} - -pub const panic = microzig.panic; - -pub fn main() void {} -``` - -Let's walk through each part. - -## `std_options` - -```zig -pub const std_options = microzig.std_options(.{}); -``` - -MicroZig provides its own `std_options` configuration that sets up logging and -other standard library options appropriate for bare-metal targets. You pass an -anonymous struct to configure logging: - -```zig -pub const std_options = microzig.std_options(.{ - .log_level = .debug, -}); -``` - -## `export_startup` - -```zig -comptime { - _ = microzig.export_startup(); -} -``` - -This is the most important line. It exports the startup code and vector table -that the MCU needs to begin executing your program. Without this call, the -linker will emit an error: - -``` -error: ld.lld: microzig: microzig_main is not defined. -Add `comptime { _ = microzig.export_startup(); }` to your root source file. -``` - -If you see this error, make sure your root source file contains the `comptime` -block shown above. - -## `panic` - -```zig -pub const panic = microzig.panic; -``` - -This sets the panic handler to MicroZig's default, which typically enters an -infinite loop. You can override this with a custom handler if you need different -behavior (e.g., logging to UART, triggering a watchdog reset): - -```zig -pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { - @panic(message); -} -``` - -## `main` - -```zig -pub fn main() void {} -``` - -Your application entry point. This is called after MicroZig has initialized the -hardware (clocks, BSS section, data relocation, etc.). The signature is `void` -return — on embedded targets there is nowhere to return to. - -## Custom Panic Handlers - -Some examples define their own panic handler instead of using the default. In -that case, omit the `pub const panic = microzig.panic` line: - -```zig -const std = @import("std"); -const microzig = @import("microzig"); - -pub const std_options = microzig.std_options(.{}); - -comptime { - _ = microzig.export_startup(); -} - -pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { - // Custom panic behavior - while (true) {} -} - -pub fn main() void {} -``` +TODO From f9e3fcfebc2fe03a28a6fe776f88b8abce0dfe14 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Fri, 1 May 2026 11:54:25 -0700 Subject: [PATCH 09/19] build: include fix in linker assertion message --- tools/generate_linker_script.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/generate_linker_script.zig b/tools/generate_linker_script.zig index e9559c66d..1d5f1d340 100644 --- a/tools/generate_linker_script.zig +++ b/tools/generate_linker_script.zig @@ -303,7 +303,7 @@ pub fn main() !void { try writer.interface.writeAll( \\ - \\ASSERT(DEFINED(microzig_main), "microzig: microzig_main is not defined. See https://microzig.tech/docs/boilerplate for the required root source boilerplate.") + \\ASSERT(DEFINED(microzig_main), "microzig: microzig_main is not defined. Add `comptime { _ = microzig.export_startup(); }` to your root source file. See https://microzig.tech/docs/boilerplate for details.") \\ ); From aefd53ffc2a972b63a1f3c25e24d2d47268a6e5d Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Mon, 27 Apr 2026 15:12:59 -0700 Subject: [PATCH 10/19] Pin zigimports --- .github/workflows/unused-imports.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unused-imports.yml b/.github/workflows/unused-imports.yml index 029cfa804..f5e15ed16 100644 --- a/.github/workflows/unused-imports.yml +++ b/.github/workflows/unused-imports.yml @@ -27,6 +27,7 @@ jobs: run: | git clone --depth 1 --revision 837804f1a677578bca7c5e028baf25684b85e6b4 https://github.com/tusharsadhwani/zigimports.git /tmp/zigimports cd /tmp/zigimports + git checkout 837804f1a677578bca7c5e028baf25684b85e6b4 zig build --release=safe # Binary is named zigimports--, find and symlink it ln -s /tmp/zigimports/zig-out/bin/zigimports-* /tmp/zigimports/zig-out/bin/zigimports From 3ef1834fc3e638b5874b86ca7f017f7a934f9c0a Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Mon, 18 May 2026 11:41:44 -0700 Subject: [PATCH 11/19] WIP --- website/content/docs/boilerplate.smd | 37 +++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/website/content/docs/boilerplate.smd b/website/content/docs/boilerplate.smd index b0af83f9a..8bd9a849b 100644 --- a/website/content/docs/boilerplate.smd +++ b/website/content/docs/boilerplate.smd @@ -10,4 +10,39 @@ # Application Boilerplate -TODO +Three pieces of boilerplate code is needed in order to use MicroZig. + +## Before + +In the past, MicroZig used to automate this for you by following a similar pattern to build.zig. The module the user provided, the code that exported `pub fn main()`, was not the root module of the application, instead MicroZig would always pro + +## Now + +Ever abstraction has a cost, and we decided that hiding information from users was less important + +### Panic + +### std_options + +### startup + +The first two are relatively straight forward because they're configuring the +standard library with declarations. The reason why is that MicroZig targets +freestanding targets, ones without an operating system, and the standard +library defaults sometimes assume that you do have an OS. + +Typically, the standard library also figures out the right startup code for +your application. Different platforms require different low level primitives, +and that is all figured out at compile-time in the Zig standard library. And +again, because we are off on our own, the default for freestanding doesn't work +for us. + +Zig's lazy evaluation is powerful, and it's largely responsible for the ease in +which a lot of code is portable. + +The evaluation has to start somewhere, and besides the root namespace of your +application, the compiler also unconditionally evaluates the root of the +standard library. This is where the start code for regular operating systems is +evaluated, and is what actually causes your `main()` function to be evaluated. + +Unfortunately, MicroZig doesn't get special treatment from the compiler, From e4a627336a83197456217750b4c6f4eb214de2be Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Thu, 21 May 2026 16:51:13 -0700 Subject: [PATCH 12/19] Cleanup --- .github/workflows/unused-imports.yml | 1 - build.zig | 18 +++----- core/src/microzig.zig | 62 +++++++--------------------- 3 files changed, 21 insertions(+), 60 deletions(-) diff --git a/.github/workflows/unused-imports.yml b/.github/workflows/unused-imports.yml index f5e15ed16..029cfa804 100644 --- a/.github/workflows/unused-imports.yml +++ b/.github/workflows/unused-imports.yml @@ -27,7 +27,6 @@ jobs: run: | git clone --depth 1 --revision 837804f1a677578bca7c5e028baf25684b85e6b4 https://github.com/tusharsadhwani/zigimports.git /tmp/zigimports cd /tmp/zigimports - git checkout 837804f1a677578bca7c5e028baf25684b85e6b4 zig build --release=safe # Binary is named zigimports--, find and symlink it ln -s /tmp/zigimports/zig-out/bin/zigimports-* /tmp/zigimports/zig-out/bin/zigimports diff --git a/build.zig b/build.zig index 1de33fb15..90bd2b554 100644 --- a/build.zig +++ b/build.zig @@ -476,13 +476,7 @@ pub fn MicroBuild(port_select: PortSelect) type { core_mod.addImport("board", board_mod); } - // The user's main.zig is the executable's root module. The - // application opts into microzig's startup via - // comptime { _ = microzig.export_startup(); } - // in its root source file, and re-exports microzig's `panic`. - // microzig's core module reads the root via `@import("root")`, - // so there's no "app" import to wire. - const app_mod = mb.builder.createModule(.{ + const root_mod = mb.builder.createModule(.{ .root_source_file = options.root_source_file, .imports = options.imports, .target = zig_resolved_target, @@ -493,7 +487,7 @@ pub fn MicroBuild(port_select: PortSelect) type { .error_tracing = options.error_tracing, .dwarf_format = options.dwarf_format, }); - app_mod.addImport("microzig", core_mod); + root_mod.addImport("microzig", core_mod); const fw = mb.builder.allocator.create(Firmware) catch @panic("out of memory"); fw.* = .{ @@ -501,10 +495,10 @@ pub fn MicroBuild(port_select: PortSelect) type { .core_mod = core_mod, .artifact = mb.builder.addExecutable(.{ .name = options.name, - .root_module = app_mod, + .root_module = root_mod, .linkage = .static, }), - .app_mod = app_mod, + .root_mod = root_mod, .target = target, .emitted_files = Firmware.EmittedFiles.init(mb.builder.allocator), }; @@ -594,8 +588,8 @@ pub fn MicroBuild(port_select: PortSelect) type { /// The artifact that is built by MicroZig. artifact: *Build.Step.Compile, - /// The app module that is built by Zig. - app_mod: *Build.Module, + /// The root module that is built by Zig. + root_mod: *Build.Module, // The @import("microzig") module core_mod: *Build.Module, diff --git a/core/src/microzig.zig b/core/src/microzig.zig index a737630ce..33d9a657b 100644 --- a/core/src/microzig.zig +++ b/core/src/microzig.zig @@ -81,42 +81,14 @@ pub const Options = struct { pub const options: Options = if (@hasDecl(root, "microzig_options")) root.microzig_options else .{}; -/// Overrides accepted by `microzig.std_options`. Mirrors only the subset of -/// `std.Options` fields that are meaningful on freestanding/embedded targets. -/// -/// Included fields (and why): -/// * `log_level` — controls verbosity of `std.log` calls. -/// * `log_scope_levels` — per-scope filtering for fine-grained logging. -/// * `logFn` — the logging callback. This is the *critical* one: stdlib's -/// default writes to stderr, which doesn't exist on freestanding targets -/// and causes link failures whenever any reachable code touches -/// `std.log.*`. Microzig defaults this to a no-op. -/// -/// Fields from `std.Options` that are intentionally NOT exposed here: -/// * `enable_segfault_handler`, `signal_stack_size` — POSIX signal -/// plumbing; no OS-level signals on freestanding. -/// * `page_size_min`, `page_size_max`, `queryPageSize` — OS virtual-memory -/// page-size configuration; embedded firmware doesn't have VM. -/// * `fmt_max_depth` — stdlib fmt recursion bound; rarely customized and -/// orthogonal to embedded concerns. -/// * `http_disable_tls`, `http_enable_ssl_key_log_file` — `std.http.Client` -/// tuning; the HTTP client is hosted-only. -/// * `side_channels_mitigations` — `std.crypto` side-channel mitigations; -/// hosted-oriented, and embedded projects typically select crypto at -/// the module level. -/// * `allow_stack_tracing` — pulls in `std.debug.ElfFile` / debug-info -/// loaders that assume a hosted filesystem. -/// * `networking` — gates `std.Io` networking; hosted-only. (Microzig -/// embedded networking is in `modules/network`.) -/// * `unexpected_error_tracing` — default debug-mode tracing that relies -/// on stderr. -/// -/// Users who genuinely need one of the excluded fields can still declare -/// their own `pub const std_options = std.Options{ ... }` directly and skip -/// this helper. pub const StdOptions = struct { + /// Control verbosity of `std.log` calls log_level: std.log.Level = std.log.default_level, + /// Per-scope filtering for fine-grained logging log_scope_levels: []const std.log.ScopeLevel = &.{}, + /// The logging callback function, you'll need to provide to be able to log + /// to UART for example. The default is to do nothing, which is very + /// portable. logFn: fn ( comptime message_level: std.log.Level, comptime scope: @TypeOf(.enum_literal), @@ -125,11 +97,9 @@ pub const StdOptions = struct { ) void = no_op_log, }; -/// Build a `std.Options` with microzig's freestanding-safe defaults. Users -/// re-export from their root source file: -/// -/// pub const std_options = microzig.std_options(.{}); // defaults only -/// pub const std_options = microzig.std_options(.{ .log_level = .info }); // with overrides +/// Helper for setting std_options relevant to embedded systems and freestanding +/// targets. Makes fewer assumptions about your system that the stdlib, and will +/// compile by default. You can set you own values using the overrides parameter. pub fn std_options(comptime overrides: StdOptions) std.Options { return .{ .log_level = overrides.log_level, @@ -154,22 +124,20 @@ pub fn hang() noreturn { } } -/// Emit microzig's firmware startup symbols. Must be invoked from a -/// `comptime` block in the root source file of every firmware: +/// Call this in the root of your application to ensure that startup code is +/// linked correctly: /// -/// comptime { _ = microzig.export_startup(); } +/// ```zig +/// comptime { _ = microzig.export_startup(); } +/// ``` /// -/// Emits the CPU-specific `_start` symbol (and vector table where -/// applicable) and the `microzig_main` wrapper that the CPU startup calls -/// once `.data`/`.bss` have been initialized. +/// Different systems require different startup procedures, and MicroZig will +/// select the right one for your system. pub fn export_startup() void { cpu.export_startup_logic(); @export(µzig_main, .{ .name = "microzig_main" }); } -/// Called from the CPU-specific `_start` once `.data`/`.bss` are live. Reads -/// `main` from the root source file and supports HAL `init` / root `init` / -/// error-returning `main`. fn microzig_main() callconv(.c) noreturn { // A HAL may define `init` (e.g. clocks, PLL) that runs before main. The // user's root source file may define its own `init` to override the HAL From 4522c62658306ccfe6ab0dca6aca15c4e07cb32f Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Thu, 21 May 2026 19:11:28 -0700 Subject: [PATCH 13/19] Actual documentation --- website/content/docs/boilerplate.smd | 86 ++++++++++++++++------------ 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/website/content/docs/boilerplate.smd b/website/content/docs/boilerplate.smd index 8bd9a849b..9f4ca087e 100644 --- a/website/content/docs/boilerplate.smd +++ b/website/content/docs/boilerplate.smd @@ -10,39 +10,53 @@ # Application Boilerplate -Three pieces of boilerplate code is needed in order to use MicroZig. - -## Before - -In the past, MicroZig used to automate this for you by following a similar pattern to build.zig. The module the user provided, the code that exported `pub fn main()`, was not the root module of the application, instead MicroZig would always pro - -## Now - -Ever abstraction has a cost, and we decided that hiding information from users was less important - -### Panic - -### std_options - -### startup - -The first two are relatively straight forward because they're configuring the -standard library with declarations. The reason why is that MicroZig targets -freestanding targets, ones without an operating system, and the standard -library defaults sometimes assume that you do have an OS. - -Typically, the standard library also figures out the right startup code for -your application. Different platforms require different low level primitives, -and that is all figured out at compile-time in the Zig standard library. And -again, because we are off on our own, the default for freestanding doesn't work -for us. - -Zig's lazy evaluation is powerful, and it's largely responsible for the ease in -which a lot of code is portable. - -The evaluation has to start somewhere, and besides the root namespace of your -application, the compiler also unconditionally evaluates the root of the -standard library. This is where the start code for regular operating systems is -evaluated, and is what actually causes your `main()` function to be evaluated. - -Unfortunately, MicroZig doesn't get special treatment from the compiler, +Three pieces of boilerplate are needed to use MicroZig: + +```zig +const microzig = @import("microzig"); + +pub const panic = microzig.panic; +pub const std_options = microzig.std_options(.{}); + +comptime { + _ = microzig.export_startup(); +} +``` + +MicroZig offers a freestanding-friendly `panic` and `std_options`, that don't +cause compile errors by default. At the time of writing, the standard library +ends up pulling in OS-specific declarations which is the cause of these +compilation errors and isn't obvious when you're starting out on Zig embedded +programming. `microzig.std_options()` takes an override argument so you can +customize it as you like. + +The `export_startup()` call ensures that your hardware specific startup code is +linked into the firmware image. These are the parts before main, like setting +up `bss` and `data` sections. + +## Background + +In the past, MicroZig would use its own module for the root of an embedded +application. The code that the user provided was turned into an `app` module, +and the root would call `app.main()`. + +This had the benefit of giving MicroZig control over how the application was set +up, allowing an easy way for it to link the startup code. It had a downside +where `@import("root")` did not refer to the user's application root, it +referred to MicroZig's. Many libraries use that as an avenue for configuration +at compile-time. The most notable of which, was the standard library itself. + +The standard library is pervasive enough that we were fine forwarding some of +its options through our own `microzig_options` declaration. None of the +solutions for forwarding other package "options" felt right. + +In addition, this setup complicated the import of external packages. Users +needed to understand the module hierarchy, and that adding a package to their +executable did not make it available to their program. Instead they needed to +add it to their `app` module, or find the specific option in the firmware build +interface that would do that for them. + +In the end, it just wasn't worth it. We traded a few less lines of boilerplate +for an increasingly complex system, and it was hurting users' understanding. We +decided that a few extra lines of code on your end and some documentation on +ours was worth the more consistent system. From 14d99732251a68d86929ed8a4e56c0af078c5989 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Thu, 21 May 2026 19:14:43 -0700 Subject: [PATCH 14/19] Remove this file? --- .../stm32/src/stm32f1xx/usb_remote_hid.zig | 461 ------------------ 1 file changed, 461 deletions(-) delete mode 100644 examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig diff --git a/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig b/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig deleted file mode 100644 index 3ae081e9f..000000000 --- a/examples/stmicro/stm32/src/stm32f1xx/usb_remote_hid.zig +++ /dev/null @@ -1,461 +0,0 @@ -//NOTE: This is just an experimental test, USB HAL for the F1 family is not complete. - -const std = @import("std"); -const microzig = @import("microzig"); - -const RCC = microzig.chip.peripherals.RCC; -const flash = microzig.chip.peripherals.FLASH; -const rcc_v1 = microzig.chip.types.peripherals.rcc_f1; -const flash_v1 = microzig.chip.types.peripherals.flash_f1; - -const stm32 = microzig.hal; -const gpio = stm32.gpio; -const timer = stm32.timer.GPTimer.init(.TIM2).into_counter_mode(); -const usb_ll = stm32.usb.usb_ll; -const descriptor = microzig.core.usb.descriptor; - -const EpControl = usb_ll.EpControl; - -const interrupt = microzig.interrupt; -var Counter: stm32.drivers.CounterDevice = undefined; -const IR_pin = gpio.Pin.from_port(.B, 0); -const peri = microzig.chip.peripherals; -const t_types = microzig.chip.types.peripherals.timer_v1; - -pub const panic = microzig.panic; - -pub const std_options = microzig.std_options(.{}); - -comptime { - _ = microzig.export_startup(); -} - -pub const microzig_options: microzig.Options = .{ - .interrupts = .{ - .USB_LP_CAN1_RX0 = .{ .c = usb_ll.usb_handler }, - .EXTI0 = .{ .c = IR_handler }, - .TIM3 = .{ .c = IR_timer_handler }, - }, -}; - -// ============== HID Descriptor ================ -const DeviceDescriptor = [18]u8{ - 0x12, // bLength - 0x01, // bDescriptorType (Device) - 0x10, 0x01, // bcdUSB (USB 1.1) - 0x00, // bDeviceClass (Defined at Interface) - 0x00, // bDeviceSubClass - 0x00, // bDeviceProtocol - 0x40, // bMaxPacketSize0 (64 bytes) - 0x55, 0xF0, // idVendor FOSS - 0x01, 0x98, // idProduct (0x9801) HID - 0x00, 0x01, // bcdDevice (1.00) - 0x01, // iManufacturer (String Index 1) - 0x02, // iProduct (String Index 2) - 0x00, // iSerialNumber (None) - 0x01, // bNumConfigurations -}; - -const ConfigurationDescriptor = [34]u8{ - // Configuration Descriptor (9 bytes) - 0x09, // bLength - 0x02, // bDescriptorType (Configuration) - 0x22, 0x00, // wTotalLength (34 bytes) - 0x01, // bNumInterfaces - 0x01, // bConfigurationValue - 0x00, // iConfiguration (None) - 0x80, // bmAttributes (Bus Powered) - 0x32, // bMaxPower (100 mA) - - // Interface Descriptor (9 bytes) - 0x09, // bLength - 0x04, // bDescriptorType (Interface) - 0x00, // bInterfaceNumber - 0x00, // bAlternateSetting - 0x01, // bNumEndpoints - 0x03, // bInterfaceClass (HID) - 0x01, // bInterfaceSubClass (Boot Interface) - 0x01, // bInterfaceProtocol (Keyboard) - 0x00, // iInterface (None) - - // HID Descriptor (9 bytes) - 0x09, // bLength - 0x21, // bDescriptorType (HID) - 0x11, 0x01, // bcdHID (1.11) - 0x00, // bCountryCode (Not Supported) - 0x01, // bNumDescriptors - 0x22, // bDescriptorType (Report) - 0x3F, 0x00, // wDescriptorLength (62 bytes) - - // Endpoint Descriptor (7 bytes) - 0x07, // bLength - 0x05, // bDescriptorType (Endpoint) - 0x81, // bEndpointAddress (EP1 IN) - 0x03, // bmAttributes (Interrupt) - 0x08, 0x00, // wMaxPacketSize (8 bytes) - 0x0A, // bInterval (10 ms) -}; - -const ReportDescriptor = [63]u8{ - 0x05, 0x01, // Usage Page (Generic Desktop) - 0x09, 0x06, // Usage (Keyboard) - 0xA1, 0x01, // Collection (Application) - - // Modifier Keys (Shift, Ctrl, Alt, etc) - 0x05, 0x07, // Usage Page (Key Codes) - 0x19, 0xE0, // Usage Minimum (0xE0) - 0x29, 0xE7, // Usage Maximum (0xE7) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0x01, // Logical Maximum (1) - 0x75, 0x01, // Report Size (1 bit) - 0x95, 0x08, // Report Count (8 bits) - 0x81, 0x02, // Input (Data, Var, Abs) - - // Reserved (1 byte) - 0x95, 0x01, // Report Count (1) - 0x75, 0x08, // Report Size (8) - 0x81, 0x01, // Input (Const) - - // Key Array (6 bytes) - 0x95, 0x06, // Report Count (6) - 0x75, 0x08, // Report Size (8) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0x65, // Logical Maximum (101) - 0x05, 0x07, // Usage Page (Key Codes) - 0x19, 0x00, // Usage Minimum (0) - 0x29, 0x65, // Usage Maximum (101) - 0x81, 0x00, // Input (Data, Array) - - // Output (LEDs: Caps Lock, Num Lock, etc) - 0x95, 0x05, // Report Count (5) - 0x75, 0x01, // Report Size (1) - 0x05, 0x08, // Usage Page (LEDs) - 0x19, 0x01, // Usage Minimum (1) - 0x29, 0x05, // Usage Maximum (5) - 0x91, 0x02, // Output (Data, Var, Abs) - - // Reserved (3 bits) - 0x95, 0x01, // Report Count (1) - 0x75, 0x03, // Report Size (3) - 0x91, 0x01, // Output (Const) - 0xC0, // End Collection -}; - -// ============== HID Descriptor ================ - -//=============== USB DATA ================= -var EP0_RX_BUFFER: [64]u8 = undefined; -var HID_send: [8]u8 = .{0} ** 8; -var to_report: bool = false; -var device_addr: ?u7 = null; -var config: bool = false; -//=============== USB DATA ================= -//==========IR NEC ========== -const NecPkg = packed struct(u32) { - addr_h: u8, - addr_l: u8, - cmd: u8, - inv_cmd: u8, -}; -//==========IR NEC ========== - -const lang_id: descriptor.String = .from_lang(.English); -const prod_id: descriptor.String = .from_str("Zig Keyboard"); -const manu_id: descriptor.String = .from_str("RecursiveError"); -fn get_string(index: usize) []const u8 { - return switch (index) { - 0 => &lang_id.data, - 1 => &manu_id.data, - 2 => &prod_id.data, - else => &[_]u8{}, - }; -} - -//TODO port USB driver from RPxxxx USB HAL -fn get_descriptor(setup: []const u8, epc: EpControl) void { - const descriptor_type = setup[3]; - const descriptor_length: u16 = @as(u16, setup[6]) | (@as(u16, setup[7]) << 8); - - const buffer: []const u8 = switch (descriptor_type) { - 0x01 => &DeviceDescriptor, - 0x02 => &ConfigurationDescriptor, - 0x03 => get_string(setup[2]), - 0x22 => &ReportDescriptor, - else => { - return; - }, - }; - - const length = @min(buffer.len, descriptor_length); - epc.write_buffer(buffer[0..length]) catch unreachable; - epc.set_status(.TX, .Valid, .force_data1) catch unreachable; -} - -fn set_addr(recive_addr: u7, epc: EpControl) void { - device_addr = recive_addr; - epc.ZLP() catch unreachable; - epc.set_status(.TX, .Valid, .force_data1) catch unreachable; -} - -fn ep0_setup(epc: EpControl, _: ?*anyopaque) void { - epc.set_status(.RX, .Valid, .no_change) catch unreachable; - - const setup = epc.read_buffer(&EP0_RX_BUFFER) catch unreachable; - if (setup.len == 0) { - return; - } - - switch (setup[1]) { - 0x06 => get_descriptor(setup, epc), - 0x05 => set_addr(@intCast(setup[2]), epc), - 0x09 => { - epc.ZLP() catch unreachable; - epc.set_status(.TX, .Valid, .force_data1) catch unreachable; - config = true; - to_report = false; - }, - else => { - epc.ZLP() catch unreachable; - epc.set_status(.TX, .Valid, .force_data1) catch unreachable; - }, - } -} - -fn ep0_rx(epc: EpControl, _: ?*anyopaque) void { - epc.set_status(.RX, .Valid, .no_change) catch unreachable; -} - -fn ep0_tx(epc: EpControl, _: ?*anyopaque) void { - if (device_addr) |addr| { - usb_ll.set_addr(addr); - } - epc.set_status(.RX, .Valid, .endpoint_ctr) catch unreachable; -} - -fn ep1_tx(epc: EpControl, _: ?*anyopaque) void { - to_report = false; - epc.set_status(.TX, .Nak, .no_change) catch unreachable; -} - -//set clock to 72Mhz and USB to 48Mhz -//NOTE: USB clock must be exactly 48Mhz -fn config_clock() void { - RCC.CR.modify(.{ - .HSEON = 1, - }); - while (RCC.CR.read().HSERDY == 0) { - asm volatile ("nop"); - } - - RCC.CFGR.modify(.{ - .PLLSRC = rcc_v1.PLLSRC.HSE_Div_PREDIV, - .PLLMUL = rcc_v1.PLLMUL.Mul9, - }); - - RCC.CR.modify(.{ - .PLLON = 1, - }); - - while (RCC.CR.read().PLLRDY == 0) { - asm volatile ("nop"); - } - - flash.ACR.modify(.{ - .LATENCY = flash_v1.LATENCY.WS2, - .PRFTBE = 1, - }); - - RCC.CFGR.modify(.{ - .PPRE1 = rcc_v1.PPRE.Div2, - .USBPRE = rcc_v1.USBPRE.Div1_5, - }); - - RCC.CFGR.modify(.{ - .SW = rcc_v1.SW.PLL1_P, - }); - - while (RCC.CFGR.read().SWS != rcc_v1.SW.PLL1_P) { - asm volatile ("nop"); - } -} - -const endpoint0 = usb_ll.Endpoint{ - .ep_control = .EPC0, - .endpoint = 0, - .ep_type = .Control, - .ep_kind = false, - .rx_reset_state = .Valid, - .tx_reset_state = .Nak, - .rx_buffer_size = .{ .block_qtd = 2, .block_size = .@"32bytes" }, - .tx_buffer_size = 64, - .rx_callback = ep0_rx, - .tx_callback = ep0_tx, - .setup_callback = ep0_setup, -}; - -const endpoint1 = usb_ll.Endpoint{ - .ep_control = .EPC1, - .endpoint = 1, - .ep_type = .Interrupt, - .ep_kind = false, - .rx_reset_state = .Nak, - .tx_reset_state = .Nak, - .rx_buffer_size = .{ .block_qtd = 1, .block_size = .@"2bytes" }, - .tx_buffer_size = 16, - .tx_callback = ep1_tx, -}; - -//TODO: full HID report function -fn report(keys: []const u8) void { - const len = @min(keys.len, 6); - const epc = usb_ll.EpControl.EPC1; - const report_flag: *volatile bool = &to_report; - if (!config) return; - while (report_flag.*) {} - std.mem.copyForwards(u8, HID_send[3..], keys[0..len]); - epc.write_buffer(&HID_send) catch unreachable; - epc.set_status(.TX, .Valid, .endpoint_ctr) catch unreachable; - report_flag.* = true; -} - -fn init_IR() void { - - //enable IR EXTI - IR_pin.set_input_mode(.pull); - IR_pin.set_pull(.up); - peri.AFIO.EXTICR[0].modify(.{ .@"EXTI[0]" = 1 }); - peri.EXTI.IMR.modify(.{ .@"LINE[0]" = 1 }); - peri.EXTI.FTSR.modify(.{ .@"LINE[0]" = 1 }); - peri.EXTI.RTSR.modify(.{ .@"LINE[0]" = 1 }); - peri.EXTI.PR.modify(.{ .@"LINE[0]" = 1 }); - - //enable timer - peri.TIM3.CR1.raw = 0; - peri.TIM3.CR2.raw = 0; - peri.TIM3.SR.raw = 0; - - peri.TIM3.CR1.modify(.{ .CEN = 0 }); - peri.TIM3.CR1.modify(.{ - .URS = t_types.URS.CounterOnly, - .OPM = 1, - .DIR = t_types.DIR.Down, - .ARPE = 1, - }); - peri.TIM3.PSC = 72; - peri.TIM3.DIER.modify(.{ .UIE = 1 }); - - interrupt.enable(.EXTI0); - interrupt.enable(.TIM3); -} - -fn start_IR_timer() void { - peri.TIM3.SR.raw = 0; - peri.TIM3.CR1.modify(.{ .CEN = 0 }); - peri.TIM3.PSC = 72; - peri.TIM3.ARR.modify(.{ .ARR = @as(u16, 25_000) }); - peri.TIM3.EGR.modify(.{ .UG = 1 }); - peri.TIM3.CR1.modify(.{ .CEN = 1 }); -} - -fn stop_IR_timer() usize { - peri.TIM3.CR1.modify(.{ .CEN = 0 }); - const val = peri.TIM3.CNT.read().CNT; - peri.TIM3.SR.raw = 0; - return val; -} - -var ir_val: u64 = 0; -var ir_index: u6 = 0; - -fn IR_handler() callconv(.c) void { - const pin_state = IR_pin.read(); - if (pin_state == 0) { - const val = stop_IR_timer(); - if (val != 0) { - const bit = 25_000 - val; - switch (bit) { - 200...800 => { - ir_val &= ~(@as(u64, 0) << ir_index); - ir_index += 1; - ir_index = ir_index % 63; - }, - 1200...1900 => { - ir_val |= (@as(u64, 1) << ir_index); - ir_index += 1; - ir_index = ir_index % 63; - }, - 4200...4800 => { - ir_val = 0; - ir_index = 0; - }, - else => {}, - } - } - } else if (pin_state == 1) { - start_IR_timer(); - } - peri.EXTI.PR.modify(.{ .@"LINE[0]" = 1 }); -} - -var nec_report: NecPkg = undefined; -var nec_send: bool = false; -fn IR_timer_handler() callconv(.c) void { - const val: u32 = @truncate(ir_val); - const nec: NecPkg = @bitCast(val); - if (val == 0) { - nec_send = true; - } else { - nec_report = nec; - nec_send = true; - } - ir_index = 0; - ir_val = 0; - peri.TIM3.SR.raw = 0; -} - -fn nec_to_hid(nec_cmd: u8) u8 { - return switch (nec_cmd) { - 0x1D => 0x52, //arrow up - 0x45 => 0x51, //arrow down - 0x40 => 0x50, //arrow left - 0x43 => 0x4F, //arrow right - 0x41 => 0x20, //enter - 0x0e => 0x29, //esc - else => nec_cmd, - }; -} - -pub fn main() !void { - config_clock(); - - RCC.APB2ENR.modify(.{ - .AFIOEN = 1, - .GPIOAEN = 1, - .GPIOBEN = 1, - .GPIOCEN = 1, - }); - - RCC.APB1ENR.modify(.{ - .TIM2EN = 1, - .TIM3EN = 1, - .USBEN = 1, - }); - Counter = timer.counter_device(72_000_000); - - //NOTE: the stm32f103 does not have an internal 1.5k pull-up resistor for USB, you must add one externally - interrupt.enable_interrupts(); - usb_ll.usb_init(&.{ endpoint0, endpoint1 }, Counter.make_ms_timeout(25)) catch unreachable; - init_IR(); - //interrupt.enable(.USB_LP_CAN1_RX0); - const nec: *volatile bool = &nec_send; - const n_report: *volatile NecPkg = &nec_report; - while (true) { - if (nec.*) { - report(&.{n_report.cmd}); - nec_send = false; - } else { - report(&.{ 0, 0, 0, 0, 0 }); - } - Counter.sleep_ms(10); - } -} From f2f2a047821259c07be3b9765ef09169de0fcddc Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Thu, 21 May 2026 19:22:12 -0700 Subject: [PATCH 15/19] finish app_mod -> root_mod --- build.zig | 6 +++--- examples/espressif/esp/build.zig | 2 +- examples/raspberrypi/rp2xxx/build.zig | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index 90bd2b554..dd94cd582 100644 --- a/build.zig +++ b/build.zig @@ -702,7 +702,7 @@ pub fn MicroBuild(port_select: PortSelect) type { if (fw.emitted_docs == null) { const docs_test = fw.mb.builder.addTest(.{ .name = fw.artifact.name, - .root_module = fw.app_mod, + .root_module = fw.root_mod, }); fw.emitted_docs = docs_test.getEmittedDocs(); @@ -720,7 +720,7 @@ pub fn MicroBuild(port_select: PortSelect) type { if (options.depend_on_microzig) { module.addImport("microzig", fw.core_mod); } - fw.app_mod.addImport(name, module); + fw.root_mod.addImport(name, module); } /// Adds an include path to the firmware. @@ -740,7 +740,7 @@ pub fn MicroBuild(port_select: PortSelect) type { /// Adds options to your application. pub fn add_options(fw: *Firmware, module_name: []const u8, options: *Build.Step.Options) void { - fw.app_mod.addOptions(module_name, options); + fw.root_mod.addOptions(module_name, options); } /// Adds an object file to the firmware. diff --git a/examples/espressif/esp/build.zig b/examples/espressif/esp/build.zig index 29574f5d4..98434e846 100644 --- a/examples/espressif/esp/build.zig +++ b/examples/espressif/esp/build.zig @@ -74,7 +74,7 @@ pub fn build(b: *std.Build) void { const lwip_lib = lwip_dep.artifact("lwip"); lwip_lib.root_module.linkLibrary(libc_lib); - firmware.app_mod.linkLibrary(lwip_lib); + firmware.root_mod.linkLibrary(lwip_lib); } // `installFirmware()` is the MicroZig pendant to `Build.installArtifact()` diff --git a/examples/raspberrypi/rp2xxx/build.zig b/examples/raspberrypi/rp2xxx/build.zig index 8f0ca9fdd..e2f0fe1f5 100644 --- a/examples/raspberrypi/rp2xxx/build.zig +++ b/examples/raspberrypi/rp2xxx/build.zig @@ -169,7 +169,7 @@ pub fn build(b: *std.Build) void { .pbuf_header_length = 22, }); const net_mod = net_dep.module("net"); - firmware.app_mod.addImport("net", net_mod); + firmware.root_mod.addImport("net", net_mod); } // Import freertos module for some examples, kind of a hack @@ -190,7 +190,7 @@ pub fn build(b: *std.Build) void { .port_name = port_name, }); const freertos_mod = freertos_dep.module("freertos"); - firmware.app_mod.addImport("freertos", freertos_mod); + firmware.root_mod.addImport("freertos", freertos_mod); } // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` From 363985b12bc4bccf824beaeb3dd456baf500ecb9 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Thu, 21 May 2026 19:24:46 -0700 Subject: [PATCH 16/19] More cleanup --- build.zig | 9 +++------ examples/raspberrypi/rp2xxx/build.zig | 16 ++++++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/build.zig b/build.zig index dd94cd582..97ef88b44 100644 --- a/build.zig +++ b/build.zig @@ -588,9 +588,6 @@ pub fn MicroBuild(port_select: PortSelect) type { /// The artifact that is built by MicroZig. artifact: *Build.Step.Compile, - /// The root module that is built by Zig. - root_mod: *Build.Module, - // The @import("microzig") module core_mod: *Build.Module, @@ -702,7 +699,7 @@ pub fn MicroBuild(port_select: PortSelect) type { if (fw.emitted_docs == null) { const docs_test = fw.mb.builder.addTest(.{ .name = fw.artifact.name, - .root_module = fw.root_mod, + .root_module = fw.artifact.root_module, }); fw.emitted_docs = docs_test.getEmittedDocs(); @@ -720,7 +717,7 @@ pub fn MicroBuild(port_select: PortSelect) type { if (options.depend_on_microzig) { module.addImport("microzig", fw.core_mod); } - fw.root_mod.addImport(name, module); + fw.artifact.root_module.addImport(name, module); } /// Adds an include path to the firmware. @@ -740,7 +737,7 @@ pub fn MicroBuild(port_select: PortSelect) type { /// Adds options to your application. pub fn add_options(fw: *Firmware, module_name: []const u8, options: *Build.Step.Options) void { - fw.root_mod.addOptions(module_name, options); + fw.artifact.root_module.addOptions(module_name, options); } /// Adds an object file to the firmware. diff --git a/examples/raspberrypi/rp2xxx/build.zig b/examples/raspberrypi/rp2xxx/build.zig index e2f0fe1f5..6c0625982 100644 --- a/examples/raspberrypi/rp2xxx/build.zig +++ b/examples/raspberrypi/rp2xxx/build.zig @@ -149,7 +149,7 @@ pub fn build(b: *std.Build) void { // // The target will convey all necessary information on the chip, // cpu and potentially the board as well. - const firmware = mb.add_firmware(.{ + const fw = mb.add_firmware(.{ .name = example.name, .target = example.target, .optimize = optimize, @@ -160,7 +160,7 @@ pub fn build(b: *std.Build) void { // Import net module for some examples if (std.mem.indexOf(u8, example.name, "_net-") != null) { const net_dep = b.dependency("net", .{ - .target = b.resolveTargetQuery(firmware.target.zig_target), + .target = b.resolveTargetQuery(fw.target.zig_target), .optimize = optimize, .mtu = 1500, // Cyw43 driver requires 22 bytes of header and 4 bytes of footer. @@ -169,7 +169,7 @@ pub fn build(b: *std.Build) void { .pbuf_header_length = 22, }); const net_mod = net_dep.module("net"); - firmware.root_mod.addImport("net", net_mod); + fw.artifact.root_module.addImport("net", net_mod); } // Import freertos module for some examples, kind of a hack @@ -178,29 +178,29 @@ pub fn build(b: *std.Build) void { var port_name: []const u8 = "Unknown"; // FIXME: hacky way to select port based on target name (it doesn't take RP2350_RISCV into account) - if (std.mem.eql(u8, firmware.target.chip.name, "RP2040")) { + if (std.mem.eql(u8, fw.target.chip.name, "RP2040")) { port_name = "RP2040"; } else { port_name = "RP2350_ARM"; } const freertos_dep = b.dependency("freertos", .{ - .target = b.resolveTargetQuery(firmware.target.zig_target), + .target = b.resolveTargetQuery(fw.target.zig_target), .optimize = optimize, .port_name = port_name, }); const freertos_mod = freertos_dep.module("freertos"); - firmware.root_mod.addImport("freertos", freertos_mod); + fw.artifact.root_module.addImport("freertos", freertos_mod); } // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` // and allows installing the firmware as a typical firmware file. // // This will also install into `$prefix/firmware` instead of `$prefix/bin`. - mb.install_firmware(firmware, .{}); + mb.install_firmware(fw, .{}); // For debugging, we also always install the firmware as an ELF file - mb.install_firmware(firmware, .{ .format = .elf }); + mb.install_firmware(fw, .{ .format = .elf }); } } From 80637574cfe3c296d352a7909ef68cb6cd86cff6 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Thu, 21 May 2026 19:27:27 -0700 Subject: [PATCH 17/19] artifact -> exe --- build.zig | 40 +++++++++++++-------------- examples/raspberrypi/rp2xxx/build.zig | 4 +-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/build.zig b/build.zig index 97ef88b44..5384f811d 100644 --- a/build.zig +++ b/build.zig @@ -493,7 +493,7 @@ pub fn MicroBuild(port_select: PortSelect) type { fw.* = .{ .mb = mb, .core_mod = core_mod, - .artifact = mb.builder.addExecutable(.{ + .exe = mb.builder.addExecutable(.{ .name = options.name, .root_module = root_mod, .linkage = .static, @@ -503,13 +503,13 @@ pub fn MicroBuild(port_select: PortSelect) type { .emitted_files = Firmware.EmittedFiles.init(mb.builder.allocator), }; - fw.artifact.bundle_compiler_rt = options.bundle_compiler_rt orelse target.bundle_compiler_rt; - fw.artifact.bundle_ubsan_rt = options.bundle_ubsan_rt orelse target.bundle_ubsan_rt; + fw.exe.bundle_compiler_rt = options.bundle_compiler_rt orelse target.bundle_compiler_rt; + fw.exe.bundle_ubsan_rt = options.bundle_ubsan_rt orelse target.bundle_ubsan_rt; - fw.artifact.link_gc_sections = options.strip_unused_symbols; - fw.artifact.link_function_sections = options.strip_unused_symbols; - fw.artifact.link_data_sections = options.strip_unused_symbols; - fw.artifact.entry = options.entry orelse target.entry orelse .default; + fw.exe.link_gc_sections = options.strip_unused_symbols; + fw.exe.link_function_sections = options.strip_unused_symbols; + fw.exe.link_data_sections = options.strip_unused_symbols; + fw.exe.entry = options.entry orelse target.entry orelse .default; const linker_script_options = options.linker_script orelse target.linker_script; const linker_script = blk: { @@ -544,7 +544,7 @@ pub fn MicroBuild(port_select: PortSelect) type { } break :blk output; }; - fw.artifact.setLinkerScript(linker_script); + fw.exe.setLinkerScript(linker_script); return fw; } @@ -572,7 +572,7 @@ pub fn MicroBuild(port_select: PortSelect) type { const format = options.format orelse fw.target.preferred_binary_format orelse .elf; const basename = mb.builder.fmt("{s}{s}", .{ - fw.artifact.name, + fw.exe.name, format.get_extension(), }); @@ -586,7 +586,7 @@ pub fn MicroBuild(port_select: PortSelect) type { mb: *Self, /// The artifact that is built by MicroZig. - artifact: *Build.Step.Compile, + exe: *Build.Step.Compile, // The @import("microzig") module core_mod: *Build.Module, @@ -605,7 +605,7 @@ pub fn MicroBuild(port_select: PortSelect) type { /// not include post processing of the ELF files necessary by certain targets. pub fn get_emitted_elf(fw: *Firmware) LazyPath { if (fw.emitted_elf == null) { - const raw_elf = fw.artifact.getEmittedBin(); + const raw_elf = fw.exe.getEmittedBin(); fw.emitted_elf = if (fw.target.patch_elf) |patch_elf| patch_elf(fw.target.dep, raw_elf) else @@ -626,7 +626,7 @@ pub fn MicroBuild(port_select: PortSelect) type { const elf_file = fw.get_emitted_elf(); const basename = fw.mb.builder.fmt("{s}{s}", .{ - fw.artifact.name, + fw.exe.name, resolved_format.get_extension(), }); @@ -698,8 +698,8 @@ pub fn MicroBuild(port_select: PortSelect) type { pub fn get_emitted_docs(fw: *Firmware) LazyPath { if (fw.emitted_docs == null) { const docs_test = fw.mb.builder.addTest(.{ - .name = fw.artifact.name, - .root_module = fw.artifact.root_module, + .name = fw.exe.name, + .root_module = fw.exe.root_module, }); fw.emitted_docs = docs_test.getEmittedDocs(); @@ -717,32 +717,32 @@ pub fn MicroBuild(port_select: PortSelect) type { if (options.depend_on_microzig) { module.addImport("microzig", fw.core_mod); } - fw.artifact.root_module.addImport(name, module); + fw.exe.root_module.addImport(name, module); } /// Adds an include path to the firmware. pub fn add_include_path(fw: *Firmware, path: LazyPath) void { - fw.artifact.addIncludePath(path); + fw.exe.addIncludePath(path); } /// Adds a system include path to the firmware. pub fn add_system_include_path(fw: *Firmware, path: LazyPath) void { - fw.artifact.addSystemIncludePath(path); + fw.exe.addSystemIncludePath(path); } /// Adds a c source file to the firmware. pub fn add_c_source_file(fw: *Firmware, source: Build.Module.CSourceFile) void { - fw.artifact.addCSourceFile(source); + fw.exe.addCSourceFile(source); } /// Adds options to your application. pub fn add_options(fw: *Firmware, module_name: []const u8, options: *Build.Step.Options) void { - fw.artifact.root_module.addOptions(module_name, options); + fw.exe.root_module.addOptions(module_name, options); } /// Adds an object file to the firmware. pub fn add_object_file(fw: *Firmware, source: LazyPath) void { - fw.artifact.addObjectFile(source); + fw.exe.addObjectFile(source); } }; diff --git a/examples/raspberrypi/rp2xxx/build.zig b/examples/raspberrypi/rp2xxx/build.zig index 6c0625982..ad5cd7bfd 100644 --- a/examples/raspberrypi/rp2xxx/build.zig +++ b/examples/raspberrypi/rp2xxx/build.zig @@ -169,7 +169,7 @@ pub fn build(b: *std.Build) void { .pbuf_header_length = 22, }); const net_mod = net_dep.module("net"); - fw.artifact.root_module.addImport("net", net_mod); + fw.exe.root_module.addImport("net", net_mod); } // Import freertos module for some examples, kind of a hack @@ -190,7 +190,7 @@ pub fn build(b: *std.Build) void { .port_name = port_name, }); const freertos_mod = freertos_dep.module("freertos"); - fw.artifact.root_module.addImport("freertos", freertos_mod); + fw.exe.root_module.addImport("freertos", freertos_mod); } // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` From 47fbb3809c14b528fd56162732072c2b9b6913d5 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Thu, 21 May 2026 19:35:51 -0700 Subject: [PATCH 18/19] Don't assign to nonexistent field --- build.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/build.zig b/build.zig index 5384f811d..1bd992833 100644 --- a/build.zig +++ b/build.zig @@ -498,7 +498,6 @@ pub fn MicroBuild(port_select: PortSelect) type { .root_module = root_mod, .linkage = .static, }), - .root_mod = root_mod, .target = target, .emitted_files = Firmware.EmittedFiles.init(mb.builder.allocator), }; From 34ce6b26b21dcd04e4b3fe663257286f49b9117e Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Thu, 21 May 2026 19:57:52 -0700 Subject: [PATCH 19/19] Fix up renames --- examples/espressif/esp/build.zig | 10 +++++----- examples/wch/ch32v/build.zig | 2 +- port/stmicro/stm32/src/hals/STM32F303/rcc.zig | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/espressif/esp/build.zig b/examples/espressif/esp/build.zig index 98434e846..20cbe3234 100644 --- a/examples/espressif/esp/build.zig +++ b/examples/espressif/esp/build.zig @@ -48,7 +48,7 @@ pub fn build(b: *std.Build) void { // // The target will convey all necessary information on the chip, // cpu and potentially the board as well. - const firmware = mb.add_firmware(.{ + const fw = mb.add_firmware(.{ .name = b.fmt("{s}_{s}", .{ target_desc.prefix, example.name }), .target = target_desc.target, .optimize = optimize, @@ -56,7 +56,7 @@ pub fn build(b: *std.Build) void { }); if (example.features.lwip) { - const target = b.resolveTargetQuery(firmware.target.zig_target); + const target = b.resolveTargetQuery(fw.target.zig_target); const foundation_dep = b.dependency("foundation_libc", .{ .target = target, @@ -74,17 +74,17 @@ pub fn build(b: *std.Build) void { const lwip_lib = lwip_dep.artifact("lwip"); lwip_lib.root_module.linkLibrary(libc_lib); - firmware.root_mod.linkLibrary(lwip_lib); + fw.exe.root_module.linkLibrary(lwip_lib); } // `installFirmware()` is the MicroZig pendant to `Build.installArtifact()` // and allows installing the firmware as a typical firmware file. // // This will also install into `$prefix/firmware` instead of `$prefix/bin`. - mb.install_firmware(firmware, .{}); + mb.install_firmware(fw, .{}); // For debugging, we also always install the firmware as an ELF file - mb.install_firmware(firmware, .{ .format = .elf }); + mb.install_firmware(fw, .{ .format = .elf }); } } } diff --git a/examples/wch/ch32v/build.zig b/examples/wch/ch32v/build.zig index 0b4007532..b94066eb9 100644 --- a/examples/wch/ch32v/build.zig +++ b/examples/wch/ch32v/build.zig @@ -84,7 +84,7 @@ pub fn build(b: *std.Build) void { const bin_filename = b.fmt("{s}.bin", .{example.name}); const objcopy_run = b.addSystemCommand(&.{objcopy_path}); objcopy_run.addArgs(&.{ "-O", "binary" }); - objcopy_run.addArtifactArg(fw.artifact); + objcopy_run.addArtifactArg(fw.exe); const bin_output = objcopy_run.addOutputFileArg(bin_filename); b.getInstallStep().dependOn(&b.addInstallFileWithDir( bin_output, diff --git a/port/stmicro/stm32/src/hals/STM32F303/rcc.zig b/port/stmicro/stm32/src/hals/STM32F303/rcc.zig index 0faae3040..742062002 100644 --- a/port/stmicro/stm32/src/hals/STM32F303/rcc.zig +++ b/port/stmicro/stm32/src/hals/STM32F303/rcc.zig @@ -20,6 +20,7 @@ const FLASH = microzig.chip.peripherals.FLASH; const LATENCY = microzig.chip.types.peripherals.flash_f3.LATENCY; const HPRE = microzig.chip.types.peripherals.rcc_f3v1.HPRE; const PPRE = microzig.chip.types.peripherals.rcc_f3v1.PPRE; +const PREDIV = microzig.chip.types.peripherals.rcc_f3v1.PREDIV; const ADCPRES = microzig.chip.types.peripherals.rcc_f3v1.ADCPRES; const USBPRE = microzig.chip.types.peripherals.rcc_f3v1.USBPRE;