]> code.bitgloo.com Git - clyne/zig-stm32l476.git/commitdiff
toggle gpio
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 5 Oct 2024 16:44:04 +0000 (12:44 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 5 Oct 2024 16:44:04 +0000 (12:44 -0400)
build.zig
src/bootstrap.s
src/main.zig

index 10fe592d75f8220511b3157b70925e68e7b26247..1d53b0904393c649899bb73d47366dcad9589680 100644 (file)
--- a/build.zig
+++ b/build.zig
@@ -3,6 +3,7 @@ const std = @import("std");
 pub fn build(b: *std.Build) void {
     const target = b.resolveTargetQuery(.{
         .cpu_arch = .thumb,
+        .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 },
         .os_tag = .freestanding,
         .abi = .none
     });
index 22f66f07d3ba36bd36905ae65080270c50c73980..5e71da0cbba6b3d515e63c3bb2b46d10e648db98 100644 (file)
@@ -23,7 +23,7 @@ fault5:
     b fault_handler
 
 .section .bss
-.skip 128
+.skip 2048
 stack_top:
 
 .section .isr_vector
index de602dd699b2b1674868c13363c92f747e87165c..0fe44974f25f386bc6960ec4b1f4b9fed11f5585 100644 (file)
@@ -3,8 +3,44 @@
 //! is to delete this file and start with root.zig instead.
 //const std = @import("std");
 
+const gpio = packed struct {
+    moder: u32,
+    otyper: u32,
+    ospeedr: u32,
+    pupdr: u32,
+    idr: u32,
+    odr: u32,
+    bsrr: u32,
+    lckr: u32,
+    afrl: u32,
+    afrh: u32,
+    brr: u32,
+    ascr: u32,
+};
+
+const cpu = struct {
+    pub fn interrupt_disable() void {
+        asm volatile("cpsid i");
+    }
+
+    pub fn interrupt_enable() void {
+        asm volatile("cpsie i");
+    }
+};
+
+const gpioa: *gpio = @ptrFromInt(0x48000000);
+const rcc: *[39]u32 = @ptrFromInt(0x40021000);
+
 export fn _start() callconv(.C) noreturn {
-    while (true) {}
+    cpu.interrupt_disable();
+
+    rcc[19] |= 1; // gpioaen
+    gpioa.moder &= ~@as(u32, 0x3 << (5 * 2));
+    gpioa.moder |= (1 << (5 * 2));
+
+    while (true) {
+        gpioa.odr ^= (1 << 5);
+    }
 }
 
 export fn fault_handler() callconv(.C) void {