3 Commits

Author SHA1 Message Date
Filipriec
e0b3573be9 finally working oh my gash 2026-04-13 09:35:15 +02:00
Filipriec
bee9777a4b blinky 2026-03-23 09:41:11 +01:00
Filipriec
20dade6168 zig build 2026-03-09 12:20:46 +01:00
6 changed files with 67 additions and 9 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
.zig-cache/
main
test/
test.zip

2
basics/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.zig-cache/
zig-out/

View File

@@ -4,15 +4,17 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "HAL-9000",
.version = "0.1.0",
.debug = true,
const root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{
.name = "HAL-9000",
.root_module = root_module,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);

View File

@@ -15,11 +15,12 @@
zls = pkgs.zls;
in {
devShells.${system}.default = pkgs.mkShell {
buildInputs = [ zig zls ];
buildInputs = [ zig zls pkgs.openocd ];
shellHook = ''
echo "Entering Zig Master Environment"
echo "Zig: $(zig version)"
echo "ZLS: $(zls --version)"
echo "openocd -f board/ek-tm4c123gxl.cfg -c \"program tiva/zig-out/bin/tiva-app verify reset exit\""
'';
};
};

View File

@@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void {
const target = b.resolveTargetQuery(.{
.cpu_arch = .thumb,
.os_tag = .freestanding,
.abi = .eabi,
.abi = .eabihf,
.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";
// 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)
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,
});
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.omit_frame_pointer = true;
elf.root_module.unwind_tables = .none;

View File

@@ -1,7 +1,54 @@
const cmsis = @cImport({
@cDefine("TM4C123GH6PM", "");
@cInclude("TM4C123GH6PM.h");
});
export fn _start() noreturn {
while (true) {}
const GPIO_PORTF_CLK_EN = @as(u32, 0x20); // Bit 5 (Port F)
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");
}
}