Adds building support for STM32

wch-ch32v003
Felix "xq" Queißner 1 year ago
parent 8a124a68db
commit 2b25d1fe1c

@ -1,2 +1,3 @@
# microzig-examples # microzig-examples
Examples for embedded zig! Examples for embedded zig!

@ -1,34 +1,52 @@
const std = @import("std"); const std = @import("std");
const rp2040 = @import("rp2040"); const rp2040 = @import("rp2040");
const microzig_build = @import("microzig"); const stm32 = @import("stm32");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const microzig = microzig_build.init(b, "microzig"); const microzig = @import("microzig").init(b, "microzig");
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const TargetDesc = struct {
target: @import("microzig").Target,
name: []const u8,
};
const available_targets = [_]TargetDesc{
// RP2040
.{ .name = "pico", .target = rp2040.boards.raspberry_pi.pico },
.{ .name = "rp2040-eth", .target = rp2040.boards.waveshare.rp2040_eth },
.{ .name = "rp2040-plus-4m", .target = rp2040.boards.waveshare.rp2040_plus_4m },
.{ .name = "rp2040-plus-16m", .target = rp2040.boards.waveshare.rp2040_plus_16m },
.{ .name = "rp2040-matrix", .target = rp2040.boards.waveshare.rp2040_matrix },
// STM32
.{ .name = "stm32f103x8", .target = stm32.chips.stm32f103x8 },
.{ .name = "stm32f303vc", .target = stm32.chips.stm32f303vc },
.{ .name = "stm32f407vg", .target = stm32.chips.stm32f407vg },
.{ .name = "stm32f429zit6u", .target = stm32.chips.stm32f429zit6u },
.{ .name = "stm32f3discovery", .target = stm32.boards.stm32f3discovery },
.{ .name = "stm32f4discovery", .target = stm32.boards.stm32f4discovery },
.{ .name = "stm3240geval", .target = stm32.boards.stm3240geval },
.{ .name = "stm32f429idiscovery", .target = stm32.boards.stm32f429idiscovery },
};
for (available_targets) |dest| {
// `addFirmware` basically works like addExecutable, but takes a // `addFirmware` basically works like addExecutable, but takes a
// `microzig.Target` for target instead of a `std.zig.CrossTarget`. // `microzig.Target` for target instead of a `std.zig.CrossTarget`.
// //
// The target will convey all necessary information on the chip, // The target will convey all necessary information on the chip,
// cpu and potentially the board as well. // cpu and potentially the board as well.
const firmware = microzig.addFirmware(b, .{ const firmware = microzig.addFirmware(b, .{
.name = "blinky", .name = b.fmt("empty-{s}", .{dest.name}),
.target = rp2040.boards.raspberry_pi.pico, .target = dest.target,
.optimize = optimize, .optimize = optimize,
.source_file = .{ .path = "src/blinky.zig" }, .source_file = .{ .path = "src/empty.zig" },
}); });
// Pendant to `getEmittedBin()`: Always returns the path to the output elf file
_ = firmware.getEmittedElf();
// Extension of `getEmittedElf()` that will also convert the file to the given
// binary format.
_ = firmware.getEmittedBin(null); // `null` is preferred format, in this case uf2
// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()` // `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
// and allows installing the firmware as a typical firmware file. // and allows installing the firmware as a typical firmware file.
// //
// This will also install into `$prefix/firmware` instead of `$prefix/bin`. // This will also install into `$prefix/firmware` instead of `$prefix/bin`.
microzig.installFirmware(b, firmware, .{}); microzig.installFirmware(b, firmware, .{});
}
} }

@ -3,12 +3,16 @@
.version = "0.1.0", .version = "0.1.0",
.dependencies = .{ .dependencies = .{
.microzig = .{ .microzig = .{
.url = "https://github.com/ZigEmbeddedGroup/microzig/archive/44ab82cac86ab7fbd4e6718021d51a2bb8c4a42c.tar.gz", .url = "https://github.com/ZigEmbeddedGroup/microzig/archive/c6c9ec4516f57638e751141085c9d76120990312.tar.gz",
.hash = "122039437ab5c8946e3f1f77dec17092f0c6cae9fcd830bce89f03725e75a02d101b", .hash = "1220af58bdaa721b8189f3a7adfda660517dd354463463388e96d69fe4ceccf80b92",
}, },
.rp2040 = .{ .rp2040 = .{
.url = "https://github.com/ZigEmbeddedGroup/raspberrypi-rp2040/archive/b9c361be68215d48657ec3684c8a30ebbc74efd5.tar.gz", .url = "https://github.com/ZigEmbeddedGroup/raspberrypi-rp2040/archive/67d36eebb0fbd89633db1a51d6d2bcb049f2066a.tar.gz",
.hash = "1220aa6da071763468a358e82af753db23513e12120cf749bdb8bb4f8ea2a8b6da7b", .hash = "122094bf268f45b188f3916f9e5964f4257414afaafba98a455ac47d25389a456832",
},
.stm32 = .{
.url = "https://github.com/ZigEmbeddedGroup/stmicro-stm32/archive/cb2893707efa6aa289fa72f02959ad5f2d9db2a1.tar.gz",
.hash = "12208cab5f60ef97cac4165ad694f3ba0c7b28f279538c1539b74f7c152f34fe306d",
}, },
}, },
} }

@ -2,4 +2,8 @@
exec ezpkg \ exec ezpkg \
microzig=/home/felix/projects/zeg/microzig \ microzig=/home/felix/projects/zeg/microzig \
rp2040=/home/felix/projects/zeg/device-support-package/rp2040 microzig.uf2=/home/felix/projects/zeg/uf2 \
microzig.regz=/home/felix/projects/zeg/regz \
rp2040=/home/felix/projects/zeg/device-support-package/rp2040 \
stm32=/home/felix/projects/zeg/device-support-package/stmicro-stm32

@ -0,0 +1,6 @@
const std = @import("std");
const microzig = @import("microzig");
pub fn main() void {
//
}
Loading…
Cancel
Save