-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
74 lines (67 loc) · 2.25 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{
.default_target = std.Target.Query{
.cpu_arch = .riscv32,
.cpu_model = .{ .explicit = &std.Target.riscv.cpu.generic_rv32 },
.os_tag = .freestanding,
.abi = .eabi,
.cpu_features_add = std.Target.riscv.featureSet(&.{
std.Target.riscv.Feature.c,
std.Target.riscv.Feature.m,
}),
},
});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "firmware",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.addAssemblyFile(b.path("src/startup.S"));
exe.setLinkerScriptPath(b.path("src/linker.ld"));
b.installArtifact(exe);
const make_image = b.addSystemCommand(&.{
"riscv32-esp-elf-objcopy",
"-O",
"binary",
});
make_image.addArtifactArg(exe);
const binary = make_image.addOutputFileArg("firmware.bin");
make_image.step.dependOn(&exe.step);
const make_image_step = b.step("make-image", "runs esptool.py elf2image");
make_image_step.dependOn(&make_image.step);
const flash_command = b.addSystemCommand(&.{
"esptool.py",
"--chip",
"esp32c3",
"--port",
"/dev/ttyUSB0",
"write_flash",
"--flash_mode",
"dio",
"0x0",
});
flash_command.addFileArg(binary);
flash_command.step.dependOn(&make_image.step);
const flash_step = b.step("flash", "flash to chip");
flash_step.dependOn(&flash_command.step);
const monitor_command = b.addSystemCommand(&.{
"picocom",
"--baud",
"115200",
"/dev/ttyUSB0",
});
const monitor_step = b.step("monitor", "picocom monitor");
monitor_step.dependOn(&monitor_command.step);
const monitor_build_command = b.addSystemCommand(&.{
"picocom",
"--baud",
"115200",
"/dev/ttyUSB0",
});
monitor_build_command.step.dependOn(&flash_command.step);
const monitor_build_step = b.step("monitor-build", "picocom monitor and build");
monitor_build_step.dependOn(&monitor_build_command.step);
}