diff --git a/build.zig b/build.zig index 1a3159776..1bd992833 100644 --- a/build.zig +++ b/build.zig @@ -476,47 +476,39 @@ pub fn MicroBuild(port_select: PortSelect) type { core_mod.addImport("board", board_mod); } - 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, + .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); + root_mod.addImport("microzig", core_mod); const fw = mb.builder.allocator.create(Firmware) catch @panic("out of memory"); fw.* = .{ .mb = mb, .core_mod = core_mod, - .artifact = mb.builder.addExecutable(.{ + .exe = 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 = root_mod, .linkage = .static, }), - .app_mod = app_mod, .target = target, .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.artifact.root_module.addImport("microzig", core_mod); - fw.artifact.root_module.addImport("app", app_mod); + 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: { @@ -551,7 +543,7 @@ pub fn MicroBuild(port_select: PortSelect) type { } break :blk output; }; - fw.artifact.setLinkerScript(linker_script); + fw.exe.setLinkerScript(linker_script); return fw; } @@ -579,7 +571,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(), }); @@ -593,10 +585,7 @@ pub fn MicroBuild(port_select: PortSelect) type { mb: *Self, /// The artifact that is built by MicroZig. - artifact: *Build.Step.Compile, - - /// The app module that is built by Zig. - app_mod: *Build.Module, + exe: *Build.Step.Compile, // The @import("microzig") module core_mod: *Build.Module, @@ -615,7 +604,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 @@ -636,7 +625,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(), }); @@ -708,8 +697,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.app_mod, + .name = fw.exe.name, + .root_module = fw.exe.root_module, }); fw.emitted_docs = docs_test.getEmittedDocs(); @@ -727,32 +716,32 @@ 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.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.app_mod.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/core/src/cpus/cortex_m.zig b/core/src/cpus/cortex_m.zig index 2a8e2e425..51c223631 100644 --- a/core/src/cpus/cortex_m.zig +++ b/core/src/cpus/cortex_m.zig @@ -2,8 +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; const Core = enum { @@ -1026,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 b761913df..33d9a657b 100644 --- a/core/src/microzig.zig +++ b/core/src/microzig.zig @@ -5,10 +5,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 @@ -67,26 +63,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 +79,41 @@ 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 .{}; + +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), + comptime format: []const u8, + args: anytype, + ) void = no_op_log, +}; + +/// 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, + .log_scope_levels = overrides.log_scope_levels, + .logFn = overrides.logFn, + }; +} + +fn no_op_log( + comptime _: std.log.Level, + comptime _: @TypeOf(.enum_literal), + comptime _: []const u8, + _: anytype, +) void {} /// Hangs the processor and will stop doing anything useful. Use with caution! pub fn hang() noreturn { @@ -114,6 +124,63 @@ pub fn hang() noreturn { } } +/// Call this in the root of your application to ensure that startup code is +/// linked correctly: +/// +/// ```zig +/// comptime { _ = microzig.export_startup(); } +/// ``` +/// +/// 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" }); +} + +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/build.zig b/examples/espressif/esp/build.zig index 29574f5d4..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.app_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/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..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; @@ -12,6 +11,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..fd597d92f 100644 --- a/examples/gigadevice/gd32/src/empty.zig +++ b/examples/gigadevice/gd32/src/empty.zig @@ -1,6 +1,13 @@ -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..db2bcc16c 100644 --- a/examples/microchip/samd51/src/blinky.zig +++ b/examples/microchip/samd51/src/blinky.zig @@ -1,6 +1,13 @@ -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..4a717e9d6 100644 --- a/examples/no_hal/stm32_l031/src/blinky.zig +++ b/examples/no_hal/stm32_l031/src/blinky.zig @@ -1,10 +1,17 @@ -const std = @import("std"); const microzig = @import("microzig"); const chip = microzig.chip; 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..0b3e2fc98 100644 --- a/examples/nordic/nrf5x/src/blinky.zig +++ b/examples/nordic/nrf5x/src/blinky.zig @@ -1,9 +1,16 @@ -const std = @import("std"); const microzig = @import("microzig"); 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..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,12 +11,16 @@ 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 microzig_options = microzig.Options{ +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..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; @@ -16,10 +15,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..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; @@ -16,10 +15,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..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); @@ -18,10 +16,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..4941c6460 100644 --- a/examples/nordic/nrf5x/src/microbit/display.zig +++ b/examples/nordic/nrf5x/src/microbit/display.zig @@ -1,9 +1,16 @@ -const std = @import("std"); const microzig = @import("microzig"); 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..ebdc350c8 100644 --- a/examples/nordic/nrf5x/src/semihosting.zig +++ b/examples/nordic/nrf5x/src/semihosting.zig @@ -1,10 +1,16 @@ -const std = @import("std"); const microzig = @import("microzig"); const board = microzig.board; -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/build.zig b/examples/raspberrypi/rp2xxx/build.zig index 8f0ca9fdd..ad5cd7bfd 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.app_mod.addImport("net", net_mod); + fw.exe.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.app_mod.addImport("freertos", freertos_mod); + fw.exe.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 }); } } 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..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; @@ -34,11 +33,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..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; @@ -10,6 +9,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..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; @@ -18,6 +15,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..4c2bfa83f 100644 --- a/examples/raspberrypi/rp2xxx/src/board_blinky.zig +++ b/examples/raspberrypi/rp2xxx/src/board_blinky.zig @@ -1,8 +1,15 @@ -const std = @import("std"); 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..1c5ab22a0 100644 --- a/examples/raspberrypi/rp2xxx/src/board_id.zig +++ b/examples/raspberrypi/rp2xxx/src/board_id.zig @@ -8,16 +8,21 @@ const gpio = rp2xxx.gpio; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +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..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; @@ -21,6 +20,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..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. @@ -110,6 +107,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..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 = .{}; @@ -14,10 +13,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..522faf1b0 100644 --- a/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig +++ b/examples/raspberrypi/rp2xxx/src/cyw43/wifi_connect.zig @@ -6,17 +6,21 @@ 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); -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..cb83fe190 100644 --- a/examples/raspberrypi/rp2xxx/src/dma.zig +++ b/examples/raspberrypi/rp2xxx/src/dma.zig @@ -19,17 +19,21 @@ fn transfer_from_slices(channel: dma.Channel, write_buf: []u8, read_buf: []const }); } +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..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; @@ -18,6 +16,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..68c35899f 100644 --- a/examples/raspberrypi/rp2xxx/src/flash_program.zig +++ b/examples/raspberrypi/rp2xxx/src/flash_program.zig @@ -12,17 +12,21 @@ 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 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..7822e8834 100644 --- a/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig +++ b/examples/raspberrypi/rp2xxx/src/gpio_clock_output.zig @@ -1,13 +1,19 @@ -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); +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..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; @@ -13,10 +12,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..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; @@ -9,10 +8,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..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; @@ -17,10 +16,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..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; @@ -20,17 +18,24 @@ const chip = rp2xxx.compatibility.chip; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); -pub const rp2040_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 rp2040_options: microzig.Options = .{ .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/net/pong.zig b/examples/raspberrypi/rp2xxx/src/net/pong.zig index b360bd2df..fa1985ce5 100644 --- a/examples/raspberrypi/rp2xxx/src/net/pong.zig +++ b/examples/raspberrypi/rp2xxx/src/net/pong.zig @@ -3,15 +3,21 @@ 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); 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..d754c4ea9 100644 --- a/examples/raspberrypi/rp2xxx/src/net/scan.zig +++ b/examples/raspberrypi/rp2xxx/src/net/scan.zig @@ -3,15 +3,21 @@ 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); 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..ae034deac 100644 --- a/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig +++ b/examples/raspberrypi/rp2xxx/src/net/tcp_client.zig @@ -3,15 +3,21 @@ 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); 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..7a37e8f15 100644 --- a/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig +++ b/examples/raspberrypi/rp2xxx/src/net/tcp_server.zig @@ -3,15 +3,21 @@ 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); 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..c839349e1 100644 --- a/examples/raspberrypi/rp2xxx/src/net/udp.zig +++ b/examples/raspberrypi/rp2xxx/src/net/udp.zig @@ -3,15 +3,21 @@ 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); 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..e813e1230 100644 --- a/examples/raspberrypi/rp2xxx/src/pwm.zig +++ b/examples/raspberrypi/rp2xxx/src/pwm.zig @@ -1,16 +1,19 @@ -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 }, }; +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..6f8fd080f 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/hd44780.zig @@ -1,21 +1,26 @@ -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); 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..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; @@ -15,6 +14,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..3b0f5d422 100644 --- a/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig +++ b/examples/raspberrypi/rp2xxx/src/rp2040_only/random.zig @@ -6,24 +6,27 @@ 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); const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +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..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; @@ -10,7 +9,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..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 { @@ -52,6 +50,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 +83,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..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; @@ -17,6 +16,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..a2bbae0bd 100644 --- a/examples/raspberrypi/rp2xxx/src/spi_slave.zig +++ b/examples/raspberrypi/rp2xxx/src/spi_slave.zig @@ -4,15 +4,20 @@ 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); -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..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; @@ -30,6 +29,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..efd9f4fcf 100644 --- a/examples/raspberrypi/rp2xxx/src/stepper_driver.zig +++ b/examples/raspberrypi/rp2xxx/src/stepper_driver.zig @@ -10,16 +10,20 @@ const A4988 = microzig.drivers.stepper.A4988; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +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..3066ad83c 100644 --- a/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig +++ b/examples/raspberrypi/rp2xxx/src/stepper_driver_dumb.zig @@ -10,16 +10,20 @@ const ULN2003 = microzig.drivers.stepper.ULN2003; const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +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..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; @@ -12,15 +11,22 @@ const timer = system_timer.num(0); const timer_irq = if (chip == .RP2040) .TIMER_IRQ_0 else .TIMER0_IRQ_0; -pub const rp2040_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 rp2040_options: microzig.Options = .{ .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_echo.zig b/examples/raspberrypi/rp2xxx/src/uart_echo.zig index 9a5e9d51b..cdba9f21e 100644 --- a/examples/raspberrypi/rp2xxx/src/uart_echo.zig +++ b/examples/raspberrypi/rp2xxx/src/uart_echo.zig @@ -1,16 +1,22 @@ -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); 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..a271c066b 100644 --- a/examples/raspberrypi/rp2xxx/src/uart_log.zig +++ b/examples/raspberrypi/rp2xxx/src/uart_log.zig @@ -8,17 +8,21 @@ const led = gpio.num(25); const uart = rp2xxx.uart.instance.num(0); const uart_tx_pin = gpio.num(0); +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..edb307f0b 100644 --- a/examples/raspberrypi/rp2xxx/src/usb_cdc.zig +++ b/examples/raspberrypi/rp2xxx/src/usb_cdc.zig @@ -32,13 +32,7 @@ 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 microzig_options = microzig.Options{ +pub const std_options = microzig.std_options(.{ .log_level = .debug, .log_scope_levels = &.{ .{ .scope = .usb_dev, .level = .warn }, @@ -46,7 +40,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..e1a331624 100644 --- a/examples/raspberrypi/rp2xxx/src/usb_hid.zig +++ b/examples/raspberrypi/rp2xxx/src/usb_hid.zig @@ -6,6 +6,20 @@ const time = rp2xxx.time; const usb = microzig.core.usb; const USB_Device = rp2xxx.usb.Polled(.{}); +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 +144,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..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; @@ -10,6 +9,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..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; @@ -36,6 +35,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..b261545c1 100644 --- a/examples/stmicro/stm32/src/semihosting.zig +++ b/examples/stmicro/stm32/src/semihosting.zig @@ -1,7 +1,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..2c2ebed6f 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/EXTI.zig @@ -4,14 +4,20 @@ 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); 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..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; @@ -31,6 +27,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..e31ef5ef6 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/spi.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/spi.zig @@ -1,19 +1,24 @@ -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); 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..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; @@ -25,9 +23,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..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; @@ -11,6 +10,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..5aef66ca1 100644 --- a/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig +++ b/examples/stmicro/stm32/src/stm32f1xx/usb_cdc.zig @@ -14,10 +14,16 @@ 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 = [_]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/stm32l476/lcd.zig b/examples/stmicro/stm32/src/stm32l476/lcd.zig index 5ea7a127d..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; @@ -11,6 +10,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..210f9c47d 100644 --- a/examples/texasinstruments/msp430/src/blinky.zig +++ b/examples/texasinstruments/msp430/src/blinky.zig @@ -4,6 +4,12 @@ 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..afe74bf57 100644 --- a/examples/texasinstruments/msp430/src/empty.zig +++ b/examples/texasinstruments/msp430/src/empty.zig @@ -1,4 +1,12 @@ 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/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/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..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; @@ -9,6 +8,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..6f012aa66 100644 --- a/examples/wch/ch32v/src/dma.zig +++ b/examples/wch/ch32v/src/dma.zig @@ -1,18 +1,22 @@ 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 -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..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; @@ -8,10 +7,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..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; @@ -8,10 +7,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..c4a791c55 100644 --- a/examples/wch/ch32v/src/i2c_position_sensor.zig +++ b/examples/wch/ch32v/src/i2c_position_sensor.zig @@ -1,21 +1,25 @@ 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; 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..8a9628146 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 { @@ -55,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/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..baf5afade 100644 --- a/examples/wch/ch32v/src/ws2812.zig +++ b/examples/wch/ch32v/src/ws2812.zig @@ -1,10 +1,17 @@ const microzig = @import("microzig"); const board = microzig.board; const hal = microzig.hal; -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/port/stmicro/stm32/src/hals/STM32F303/rcc.zig b/port/stmicro/stm32/src/hals/STM32F303/rcc.zig index c1ec8ac9d..742062002 100644 --- a/port/stmicro/stm32/src/hals/STM32F303/rcc.zig +++ b/port/stmicro/stm32/src/hals/STM32F303/rcc.zig @@ -18,9 +18,9 @@ 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 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; diff --git a/tools/generate_linker_script.zig b/tools/generate_linker_script.zig index ef1f4079b..1d5f1d340 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. See https://microzig.tech/docs/boilerplate for details.") + \\ + ); + try writer.interface.flush(); } 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 {} 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..9f4ca087e --- /dev/null +++ b/website/content/docs/boilerplate.smd @@ -0,0 +1,62 @@ +--- +.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 + +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. 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 = .{