-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed building error for WCH CH32V (#298)
* Fix build errors in example files. Related to the commit 'Build system rewrite (#259)' * use cpu specific module. Without this cpu specific module, the startup_logic is skipped because the cpu doen't start from _start label but start at the top of binary. * Added LICENSE files for wch/ch32v. --------- Co-authored-by: nosuz <[email protected]>
- Loading branch information
Showing
14 changed files
with
205 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) Zig Embedded Group contributors | ||
|
||
This software is provided 'as-is', without any express or implied warranty. In | ||
no event will the authors be held liable for any damages arising from the use | ||
of this software. | ||
|
||
Permission is granted to anyone to use this software for any purpose, including | ||
commercial applications, and to alter it and redistribute it freely, subject to | ||
the following restrictions: | ||
|
||
1. The origin of this software must not be misrepresented; you must not claim | ||
that you wrote the original software. If you use this software in a product, | ||
an acknowledgment in the product documentation would be appreciated but is | ||
not required. | ||
|
||
2. Altered source versions must be plainly marked as such, and must not be | ||
misrepresented as being the original software. | ||
|
||
3. This notice may not be removed or altered from any source distribution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,61 @@ | ||
const std = @import("std"); | ||
const MicroZig = @import("microzig/build"); | ||
const wch = @import("microzig/port/wch/ch32v"); | ||
|
||
const available_examples = [_]Example{ | ||
// CH32V003 | ||
.{ .target = wch.chips.ch32v003x4, .name = "empty_ch32v003", .file = "src/empty.zig" }, | ||
.{ .target = wch.chips.ch32v003x4, .name = "blinky_ch32v003", .file = "src/blinky_ch32v003.zig" }, | ||
// .{ .target = wch.boards.ch32v003.ch32v003f4p6_r0_1v1, .name = "ch32v003f4p6_r0_1v1_empty", .file = "src/empty.zig" }, | ||
// .{ .target = wch.boards.ch32v003.ch32v003f4p6_r0_1v1, .name = "ch32v003f4p6_r0_1v1_blinky", .file = "src/blinky.zig" }, | ||
|
||
// CH32V103 | ||
.{ .target = wch.chips.ch32v103x8, .name = "empty_ch32v103", .file = "src/empty.zig" }, | ||
.{ .target = wch.chips.ch32v103x8, .name = "blinky_ch32v103", .file = "src/blinky.zig" }, | ||
// .{ .target = wch.boards.ch32v103.ch32v103r_r1_1v1, .name = "ch32v103r_r1_1v1_empty", .file = "src/empty.zig" }, | ||
// .{ .target = wch.boards.ch32v103.ch32v103r_r1_1v1, .name = "ch32v103r_r1_1v1_blinky", .file = "src/blinky.zig" }, | ||
|
||
// CH32V203 | ||
.{ .target = wch.chips.ch32v203x8, .name = "empty_ch32v203", .file = "src/empty.zig" }, | ||
.{ .target = wch.chips.ch32v203x8, .name = "blinky_ch32v203", .file = "src/blinky.zig" }, | ||
.{ .target = wch.boards.ch32v203.suzuduino_uno_v1b, .name = "suzuduino_blinky", .file = "src/board_blinky.zig" }, | ||
}; | ||
const microzig = @import("microzig"); | ||
|
||
const MicroBuild = microzig.MicroBuild(.{ | ||
.ch32v = true, | ||
}); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const microzig = MicroZig.init(b, .{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const mz_dep = b.dependency("microzig", .{}); | ||
const mb = MicroBuild.init(b, mz_dep) orelse return; | ||
|
||
const available_examples = [_]Example{ | ||
// CH32V003 | ||
.{ .target = mb.ports.ch32v.chips.ch32v003x4, .name = "empty_ch32v003", .file = "src/empty.zig" }, | ||
.{ .target = mb.ports.ch32v.chips.ch32v003x4, .name = "blinky_ch32v003", .file = "src/blinky_ch32v003.zig" }, | ||
.{ .target = mb.ports.ch32v.boards.ch32v003.ch32v003f4p6_r0_1v1, .name = "ch32v003f4p6_r0_1v1_empty", .file = "src/empty.zig" }, | ||
.{ .target = mb.ports.ch32v.boards.ch32v003.ch32v003f4p6_r0_1v1, .name = "ch32v003f4p6_r0_1v1_blinky", .file = "src/blinky.zig" }, | ||
|
||
// CH32V103 | ||
.{ .target = mb.ports.ch32v.chips.ch32v103x8, .name = "empty_ch32v103", .file = "src/empty.zig" }, | ||
.{ .target = mb.ports.ch32v.chips.ch32v103x8, .name = "blinky_ch32v103", .file = "src/blinky.zig" }, | ||
.{ .target = mb.ports.ch32v.boards.ch32v103.ch32v103r_r1_1v1, .name = "ch32v103r_r1_1v1_blinky", .file = "src/blinky.zig" }, | ||
.{ .target = mb.ports.ch32v.boards.ch32v103.ch32v103r_r1_1v1, .name = "ch32v103r_r1_1v1_empty", .file = "src/empty.zig" }, | ||
|
||
// CH32V203 | ||
.{ .target = mb.ports.ch32v.chips.ch32v203x8, .name = "empty_ch32v203", .file = "src/empty.zig" }, | ||
.{ .target = mb.ports.ch32v.chips.ch32v203x8, .name = "blinky_ch32v203", .file = "src/blinky.zig" }, | ||
.{ .target = mb.ports.ch32v.boards.ch32v203.suzuduino_uno_v1b, .name = "suzuduino_blinky", .file = "src/board_blinky.zig" }, | ||
}; | ||
|
||
for (available_examples) |example| { | ||
// `add_firmware` basically works like addExecutable, but takes a | ||
// `microzig.Target` for target instead of a `std.zig.CrossTarget`. | ||
// | ||
// The target will convey all necessary information on the chip, | ||
// cpu and potentially the board as well. | ||
const firmware = microzig.add_firmware(b, .{ | ||
const fw = mb.add_firmware(.{ | ||
.name = example.name, | ||
.target = example.target, | ||
.optimize = optimize, | ||
// .optimize = .ReleaseSmall, // not work -Doptimize=ReleaseSmall | ||
.root_source_file = b.path(example.file), | ||
}); | ||
|
||
// `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`. | ||
microzig.install_firmware(b, firmware, .{ .format = .bin }); | ||
mb.install_firmware(fw, .{}); | ||
|
||
// For debugging, we also always install the firmware as an ELF file | ||
// microzig.install_firmware(b, firmware, .{}); // default format is ELF | ||
microzig.install_firmware(b, firmware, .{ .format = .elf }); | ||
mb.install_firmware(fw, .{ .format = .elf }); | ||
} | ||
} | ||
|
||
const Example = struct { | ||
target: MicroZig.Target, | ||
target: *const microzig.Target, | ||
name: []const u8, | ||
file: []const u8, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) Zig Embedded Group contributors | ||
|
||
This software is provided 'as-is', without any express or implied warranty. In | ||
no event will the authors be held liable for any damages arising from the use | ||
of this software. | ||
|
||
Permission is granted to anyone to use this software for any purpose, including | ||
commercial applications, and to alter it and redistribute it freely, subject to | ||
the following restrictions: | ||
|
||
1. The origin of this software must not be misrepresented; you must not claim | ||
that you wrote the original software. If you use this software in a product, | ||
an acknowledgment in the product documentation would be appreciated but is | ||
not required. | ||
|
||
2. Altered source versions must be plainly marked as such, and must not be | ||
misrepresented as being the original software. | ||
|
||
3. This notice may not be removed or altered from any source distribution. |
Oops, something went wrong.