finally working oh my gash

This commit is contained in:
Filipriec
2026-04-13 09:35:15 +02:00
parent bee9777a4b
commit e0b3573be9
4 changed files with 42 additions and 12 deletions

2
.gitignore vendored
View File

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

View File

@@ -20,6 +20,7 @@
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 },
});
@@ -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

@@ -3,23 +3,46 @@ const cmsis = @cImport({
@cInclude("TM4C123GH6PM.h");
});
const GPIO_PORTF_CLK_EN: u32 = 0x20; // Bit 5 (Port F)
const GPIO_PORTF_PIN1_EN: u32 = 0x02; // Bit 1
const GPIO_PORTF_CLK_EN = @as(u32, 0x20); // Bit 5 (Port F)
const GPIO_PORTF_PIN1_EN = @as(u32, 0x02); // Bit 1
const LED_ON1: u32 = 0x02;
const LED_RED = @as(u32, 0x02);
export fn _start() noreturn {
// 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.GPIOF.*.DEN |= GPIO_PORTF_PIN1_EN;
cmsis.GPIOF.*.DIR |= GPIO_PORTF_PIN1_EN;
cmsis.SYSCTL.*.GPIOHBCTL |= GPIO_PORTF_CLK_EN;
const DELAY_VALUE = 4000000;
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) {
cmsis.GPIOF.*.DATA = LED_ON1; // LED On
gpiof_data_pf1.* = LED_RED; // LED On
Delay(DELAY_VALUE);
cmsis.GPIOF.*.DATA = 0; // LED On
gpiof_data_pf1.* = 0; // LED off
Delay(DELAY_VALUE);
}
}