Compare commits
3 Commits
6706055229
...
v0.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0b3573be9 | ||
|
|
bee9777a4b | ||
|
|
20dade6168 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
.zig-cache/
|
.zig-cache/
|
||||||
main
|
main
|
||||||
|
test/
|
||||||
|
test.zip
|
||||||
|
|||||||
2
basics/.gitignore
vendored
Normal file
2
basics/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.zig-cache/
|
||||||
|
zig-out/
|
||||||
@@ -4,15 +4,17 @@ pub fn build(b: *std.Build) void {
|
|||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const root_module = b.createModule(.{
|
||||||
.name = "HAL-9000",
|
|
||||||
.version = "0.1.0",
|
|
||||||
.debug = true,
|
|
||||||
.root_source_file = b.path("src/main.zig"),
|
.root_source_file = b.path("src/main.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "HAL-9000",
|
||||||
|
.root_module = root_module,
|
||||||
|
});
|
||||||
|
|
||||||
b.installArtifact(exe);
|
b.installArtifact(exe);
|
||||||
|
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
|||||||
@@ -15,11 +15,12 @@
|
|||||||
zls = pkgs.zls;
|
zls = pkgs.zls;
|
||||||
in {
|
in {
|
||||||
devShells.${system}.default = pkgs.mkShell {
|
devShells.${system}.default = pkgs.mkShell {
|
||||||
buildInputs = [ zig zls ];
|
buildInputs = [ zig zls pkgs.openocd ];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
echo "Entering Zig Master Environment"
|
echo "Entering Zig Master Environment"
|
||||||
echo "Zig: $(zig version)"
|
echo "Zig: $(zig version)"
|
||||||
echo "ZLS: $(zls --version)"
|
echo "ZLS: $(zls --version)"
|
||||||
|
echo "openocd -f board/ek-tm4c123gxl.cfg -c \"program tiva/zig-out/bin/tiva-app verify reset exit\""
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
const target = b.resolveTargetQuery(.{
|
const target = b.resolveTargetQuery(.{
|
||||||
.cpu_arch = .thumb,
|
.cpu_arch = .thumb,
|
||||||
.os_tag = .freestanding,
|
.os_tag = .freestanding,
|
||||||
.abi = .eabi,
|
.abi = .eabihf,
|
||||||
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 },
|
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
const cmsis_path = "/home/priec/programs/CMSIS";
|
const cmsis_path = "/home/priec/programs/CMSIS";
|
||||||
|
|
||||||
// Generic CMSIS Core (for core_cm4.h)
|
// Generic CMSIS Core (for core_cm4.h)
|
||||||
tiva_module.addIncludePath(.{ .cwd_relative = cmsis_path ++ "/CMSIS/Include" });
|
tiva_module.addIncludePath(.{ .cwd_relative = cmsis_path ++ "/Include" });
|
||||||
// TM4C Device Specific (for TM4C123GH6PM.h)
|
// TM4C Device Specific (for TM4C123GH6PM.h)
|
||||||
tiva_module.addIncludePath(.{ .cwd_relative = cmsis_path ++ "/Device/TI/TM4C/Include" });
|
tiva_module.addIncludePath(.{ .cwd_relative = cmsis_path ++ "/Device/TI/TM4C/Include" });
|
||||||
|
|
||||||
@@ -29,6 +29,10 @@ pub fn build(b: *std.Build) void {
|
|||||||
.root_module = tiva_module,
|
.root_module = tiva_module,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const bin = elf.addObjCopy(.{ .format = .bin });
|
||||||
|
const install_bin = b.addInstallBinFile(bin.getOutput(), "tiva-app.bin");
|
||||||
|
b.getInstallStep().dependOn(&install_bin.step);
|
||||||
|
|
||||||
elf.root_module.strip = true;
|
elf.root_module.strip = true;
|
||||||
elf.root_module.omit_frame_pointer = true;
|
elf.root_module.omit_frame_pointer = true;
|
||||||
elf.root_module.unwind_tables = .none;
|
elf.root_module.unwind_tables = .none;
|
||||||
|
|||||||
@@ -1,7 +1,54 @@
|
|||||||
const cmsis = @cImport({
|
const cmsis = @cImport({
|
||||||
|
@cDefine("TM4C123GH6PM", "");
|
||||||
@cInclude("TM4C123GH6PM.h");
|
@cInclude("TM4C123GH6PM.h");
|
||||||
});
|
});
|
||||||
|
|
||||||
export fn _start() noreturn {
|
const GPIO_PORTF_CLK_EN = @as(u32, 0x20); // Bit 5 (Port F)
|
||||||
while (true) {}
|
const GPIO_PORTF_PIN1_EN = @as(u32, 0x02); // Bit 1
|
||||||
|
|
||||||
|
const LED_RED = @as(u32, 0x02);
|
||||||
|
|
||||||
|
// export const vector_table linksection(".isr_vector") = [2]usize{
|
||||||
|
// 0x20008000,
|
||||||
|
// @intFromPtr(&_start),
|
||||||
|
// };
|
||||||
|
|
||||||
|
const VectorEntry = extern union {
|
||||||
|
stack_top: u32,
|
||||||
|
handler: *const fn () callconv(.c) noreturn,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const vector_table linksection(".vector_table") = [_]VectorEntry{
|
||||||
|
.{ .stack_top = 0x20008000 },
|
||||||
|
.{ .handler = &_start },
|
||||||
|
};
|
||||||
|
|
||||||
|
export fn _start() callconv(.c) noreturn {
|
||||||
|
cmsis.SYSCTL.*.RCGC2 |= GPIO_PORTF_CLK_EN;
|
||||||
|
cmsis.SYSCTL.*.RCGCGPIO |= GPIO_PORTF_CLK_EN;
|
||||||
|
_ = cmsis.SYSCTL.*.RCGCGPIO;
|
||||||
|
_ = cmsis.SYSCTL.*.RCGCGPIO;
|
||||||
|
_ = cmsis.SYSCTL.*.RCGCGPIO;
|
||||||
|
|
||||||
|
cmsis.SYSCTL.*.GPIOHBCTL |= GPIO_PORTF_CLK_EN;
|
||||||
|
|
||||||
|
cmsis.GPIOF_AHB.*.DEN |= GPIO_PORTF_PIN1_EN;
|
||||||
|
cmsis.GPIOF_AHB.*.DIR |= GPIO_PORTF_PIN1_EN;
|
||||||
|
// cmsis.GPIOF_AHB.*.DATA ^= LED_RED;
|
||||||
|
|
||||||
|
const gpiof_data_pf1: *volatile u32 = @ptrFromInt(@intFromPtr(cmsis.GPIOF_AHB) + (LED_RED << 2));
|
||||||
|
|
||||||
|
const DELAY_VALUE = 400000;
|
||||||
|
while (true) {
|
||||||
|
gpiof_data_pf1.* = LED_RED; // LED On
|
||||||
|
Delay(DELAY_VALUE);
|
||||||
|
gpiof_data_pf1.* = 0; // LED off
|
||||||
|
Delay(DELAY_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn Delay(delay: usize) void {
|
||||||
|
for (0..delay) |_| {
|
||||||
|
asm volatile ("nop");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user