This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.zig
259 lines (225 loc) · 9.31 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
const std = @import("std");
const microzig = @import("root").dependencies.imports.microzig; // HACK: Please import MicroZig always under the name `microzig`. Otherwise the RP2040 module will fail to be properly imported.
fn root() []const u8 {
return comptime (std.fs.path.dirname(@src().file) orelse ".");
}
const build_root = root();
const KiB = 1024;
////////////////////////////////////////
// MicroZig Gen 2 Interface //
////////////////////////////////////////
pub fn build(b: *std.Build) !void {
_ = b;
// Dummy func to make package manager happy
}
pub const chips = struct {
pub const stm32f103x8 = .{
.preferred_format = .elf,
.chip = .{
.name = "STM32F103",
.cpu = .cortex_m3,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = 64 * KiB, .kind = .flash },
.{ .offset = 0x20000000, .length = 20 * KiB, .kind = .ram },
},
.register_definition = .{
.json = .{ .cwd_relative = build_root ++ "/src/chips/STM32F103.json" },
},
},
.hal = .{
.source_file = .{ .cwd_relative = build_root ++ "/src/hals/STM32F103/hal.zig" },
},
};
pub const stm32f303vc = .{
.preferred_format = .elf,
.chip = .{
.name = "STM32F303",
.cpu = .cortex_m4,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = 256 * KiB, .kind = .flash },
.{ .offset = 0x20000000, .length = 40 * KiB, .kind = .ram },
},
.register_definition = .{
.json = .{ .cwd_relative = build_root ++ "/src/chips/STM32F303.json" },
},
},
};
pub const stm32f407vg = .{
.preferred_format = .elf,
.chip = .{
.name = "STM32F407",
.cpu = .cortex_m4,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = 1024 * KiB, .kind = .flash },
.{ .offset = 0x20000000, .length = 128 * KiB, .kind = .ram },
.{ .offset = 0x10000000, .length = 64 * KiB, .kind = .ram }, // CCM RAM
},
.register_definition = .{
.json = .{ .cwd_relative = build_root ++ "/src/chips/STM32F407.json" },
},
},
};
pub const stm32f429zit6u = .{
.preferred_format = .elf,
.chip = .{
.name = "STM32F429",
.cpu = .cortex_m4,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = 2048 * KiB, .kind = .flash },
.{ .offset = 0x20000000, .length = 192 * KiB, .kind = .ram },
.{ .offset = 0x10000000, .length = 64 * KiB, .kind = .ram }, // CCM RAM
},
.register_definition = .{
.json = .{ .cwd_relative = build_root ++ "/src/chips/STM32F429.json" },
},
},
};
// All STM32L0x1 series MCUs differ only in memory size. So we create a comptime function
// to generate all MCU variants as per https://www.st.com/en/microcontrollers-microprocessors/stm32l0x1.html
fn stm32l0x1(comptime rom_size: u64, comptime ram_size: u64) microzig.Target {
return microzig.Target{
.preferred_format = .elf,
.chip = .{
.name = "STM32L0x1",
.cpu = .cortex_m0plus,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = rom_size, .kind = .flash },
.{ .offset = 0x20000000, .length = ram_size, .kind = .ram },
},
.register_definition = .{
.svd = .{ .cwd_relative = build_root ++ "/src/chips/STM32L0x1.svd" },
},
},
};
}
pub const stm32l011x3 = stm32l0x1(8 * KiB, 2 * KiB);
pub const stm32l011x4 = stm32l0x1(16 * KiB, 2 * KiB);
pub const stm32l021x4 = stm32l0x1(16 * KiB, 2 * KiB);
pub const stm32l031x4 = stm32l0x1(16 * KiB, 8 * KiB);
pub const stm32l031x6 = stm32l0x1(32 * KiB, 8 * KiB);
pub const stm32l041x6 = stm32l0x1(32 * KiB, 8 * KiB);
pub const stm32l051x6 = stm32l0x1(32 * KiB, 8 * KiB);
pub const stm32l051x8 = stm32l0x1(64 * KiB, 8 * KiB);
pub const stm32l071x8 = stm32l0x1(64 * KiB, 20 * KiB);
pub const stm32l071xb = stm32l0x1(128 * KiB, 20 * KiB);
pub const stm32l081cb = stm32l0x1(128 * KiB, 20 * KiB);
pub const stm32l071xz = stm32l0x1(192 * KiB, 20 * KiB);
pub const stm32l081xz = stm32l0x1(192 * KiB, 20 * KiB);
// All STM32L0x2 series MCUs differ only in memory size. So we create a comptime function
// to generate all MCU variants as per https://www.st.com/en/microcontrollers-microprocessors/stm32l0x2.html
fn stm32l0x2(comptime rom_size: u64, comptime ram_size: u64) microzig.Target {
return microzig.Target{
.preferred_format = .elf,
.chip = .{
.name = "STM32L0x2",
.cpu = .cortex_m0plus,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = rom_size, .kind = .flash },
.{ .offset = 0x20000000, .length = ram_size, .kind = .ram },
},
.register_definition = .{
.svd = .{ .cwd_relative = build_root ++ "/src/chips/STM32L0x2.svd" },
},
},
};
}
pub const stm32l052x6 = stm32l0x2(32 * KiB, 8 * KiB);
pub const stm32l052x8 = stm32l0x2(64 * KiB, 8 * KiB);
pub const stm32l062x8 = stm32l0x2(64 * KiB, 8 * KiB);
pub const stm32l072v8 = stm32l0x2(64 * KiB, 20 * KiB);
pub const stm32l072xb = stm32l0x2(128 * KiB, 20 * KiB);
pub const stm32l082xb = stm32l0x2(128 * KiB, 20 * KiB);
pub const stm32l072xz = stm32l0x2(192 * KiB, 20 * KiB);
pub const stm32l082xz = stm32l0x2(192 * KiB, 20 * KiB);
// All STM32L0x2 series MCUs differ only in memory size. So we create a comptime function
// to generate all MCU variants as per https://www.st.com/en/microcontrollers-microprocessors/stm32l0x3.html
fn stm32l0x3(comptime rom_size: u64, comptime ram_size: u64) microzig.Target {
return microzig.Target{
.preferred_format = .elf,
.chip = .{
.name = "STM32L0x3",
.cpu = .cortex_m0plus,
.memory_regions = &.{
.{ .offset = 0x08000000, .length = rom_size, .kind = .flash },
.{ .offset = 0x20000000, .length = ram_size, .kind = .ram },
},
.register_definition = .{
.svd = .{ .cwd_relative = build_root ++ "/src/chips/STM32L0x3.svd" },
},
},
};
}
pub const stm32l053x6 = stm32l0x2(32 * KiB, 8 * KiB);
pub const stm32l053x8 = stm32l0x2(64 * KiB, 8 * KiB);
pub const stm32l063x8 = stm32l0x2(64 * KiB, 8 * KiB);
pub const stm32l073v8 = stm32l0x2(64 * KiB, 20 * KiB);
pub const stm32l083v8 = stm32l0x2(64 * KiB, 20 * KiB);
pub const stm32l073xb = stm32l0x2(128 * KiB, 20 * KiB);
pub const stm32l083xb = stm32l0x2(128 * KiB, 20 * KiB);
pub const stm32l073xz = stm32l0x2(192 * KiB, 20 * KiB);
pub const stm32l083xz = stm32l0x2(192 * KiB, 20 * KiB);
};
pub const boards = struct {
pub const stm32f3discovery = .{
.preferred_format = .elf,
.chip = chips.stm32f303vc.chip,
.board = .{
.name = "STM32F3DISCOVERY",
.source_file = .{ .path = build_root ++ "/src/boards/STM32F3DISCOVERY.zig" },
},
};
pub const stm32f4discovery = .{
.preferred_format = .elf,
.chip = chips.stm32f407vg.chip,
.board = .{
.name = "STM32F4DISCOVERY",
.source_file = .{ .path = build_root ++ "/src/boards/STM32F4DISCOVERY.zig" },
},
};
pub const stm3240geval = .{
.preferred_format = .elf,
.chip = chips.stm32f407vg.chip,
.board = .{
.name = "STM3240G_EVAL",
.source_file = .{ .path = build_root ++ "/src/boards/STM3240G_EVAL.zig" },
},
};
pub const stm32f429idiscovery = .{
.preferred_format = .elf,
.chip = chips.stm32f429zit6u.chip,
.board = .{
.name = "STM32F429IDISCOVERY",
.source_file = .{ .path = build_root ++ "/src/boards/STM32F429IDISCOVERY.zig" },
},
};
};
// pub fn build(b: *std.build.Builder) void {
// _ = b;
// const optimize = b.standardOptimizeOption(.{});
// inline for (@typeInfo(boards).Struct.decls) |decl| {
// if (!decl.is_pub)
// continue;
// const exe = microzig.addEmbeddedExecutable(b, .{
// .name = @field(boards, decl.name).name ++ ".minimal",
// .source_file = .{
// .path = "test/programs/minimal.zig",
// },
// .backing = .{ .board = @field(boards, decl.name) },
// .optimize = optimize,
// });
// exe.installArtifact(b);
// }
// inline for (@typeInfo(chips).Struct.decls) |decl| {
// if (!decl.is_pub)
// continue;
// const exe = microzig.addEmbeddedExecutable(b, .{
// .name = @field(chips, decl.name).name ++ ".minimal",
// .source_file = .{
// .path = "test/programs/minimal.zig",
// },
// .backing = .{ .chip = @field(chips, decl.name) },
// .optimize = optimize,
// });
// exe.installArtifact(b);
// }
// }