Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions core/src/cpus/cortex_m/m4.zig
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ pub const SystemControlBlock = extern struct {
BFAR: u32,
/// Auxilary Feature Register.
AFSR: u32,
reserved0: [18]u32,
CPACR: mmio.Mmio(packed struct(u32) {
reserved0: u20,
CP10: Privilege,
CP11: Privilege,
reserved1: u8,

pub const Privilege = enum(u2) {
/// Access denied. Any attempted access generates a NOCP UsageFault.
access_denied = 0b00,
/// Privileged access only. An unprivileged access generates a NOCP UsageFault.
priviledged_access_only = 0b01,
reserved = 0b10,
/// Full access.
full_access = 0b11,
};
}),
};

pub const NestedVectorInterruptController = extern struct {
Expand Down Expand Up @@ -187,3 +204,39 @@ pub const MemoryProtectionUnit = extern struct {
reserved2: u3 = 0,
});
};

pub const FloatingPointUnit = extern struct {
FPCCR: mmio.Mmio(packed struct(u32) {
LSPACT: u1,
USER: u1,
reserved0: u1 = 0,
THREAD: u1,
HFRDY: u1,
MMRDY: u1,
BFRDY: u1,
reserved1: u1 = 0,
MONRDY: u1,
reserved2: u21 = 0,
/// Automatic state preservation enable. Enables lazy context save of
/// floating-point state. The possible values of this bit are:
/// 0 = Disable automatic lazy context save.
/// 1 = Enable automatic lazy state preservation for floating-point
/// context.
///
/// Writes to this bit from Non-secure state are ignored if LSPENS is
/// set to one.
LSPEN: u1,
/// Automatic state preservation enable. Enables CONTROL.FPCA setting
/// on execution of a floating-point instruction. This results in
/// automatic hardware state preservation and restoration, for
/// floating-point context, on exception entry and exit. The possible
/// values of this bit are:
/// 1 = Enable CONTROL.FPCA setting on execution of a floating-point
/// instruction.
/// 0 = Disable CONTROL.FPCA setting on execution of a
/// floating-point instruction.
ASPEN: u1,
}),
FPCAR: u32,
FPDSCR: u32,
};
43 changes: 25 additions & 18 deletions examples/stmicro/stm32/src/blinky.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,33 @@ pub fn main() !void {
};
break :res .{ pins, all_leds };
} else if (comptime microzig.config.board_name != null and std.mem.eql(u8, microzig.config.board_name.?, "STM32F3DISCOVERY")) {
const pins = (stm32.pins.GlobalConfiguration{ .GPIOE = .{
.PE8 = .{ .mode = .{ .output = .push_pull } },
.PE9 = .{ .mode = .{ .output = .push_pull } },
.PE10 = .{ .mode = .{ .output = .push_pull } },
.PE11 = .{ .mode = .{ .output = .push_pull } },
.PE12 = .{ .mode = .{ .output = .push_pull } },
.PE13 = .{ .mode = .{ .output = .push_pull } },
.PE14 = .{ .mode = .{ .output = .push_pull } },
.PE15 = .{ .mode = .{ .output = .push_pull } },
} }).apply();
const pins = (stm32.pins.GlobalConfiguration{
.GPIOC = .{
.PIN4 = .{ .mode = .{ .alternate_function = .{ .afr = .AF7 } } },
.PIN5 = .{ .mode = .{ .alternate_function = .{ .afr = .AF7 } } },
},
.GPIOE = .{
.PIN8 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
.PIN9 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
.PIN10 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
.PIN11 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
.PIN12 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
.PIN13 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
.PIN14 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
.PIN15 = .{ .mode = .{ .output = .{ .resistor = .Floating, .o_type = .PushPull } } },
},
}).apply();
const all_leds = .{
pins.PE8,
pins.PE9,
pins.PE10,
pins.PE11,
pins.PE12,
pins.PE13,
pins.PE14,
pins.PE15,
pins.PIN8,
pins.PIN9,
pins.PIN10,
pins.PIN11,
pins.PIN12,
pins.PIN13,
pins.PIN14,
pins.PIN15,
};

break :res .{ pins, all_leds };
} else {
@compileError("blinky is not (yet?) implemented for this target");
Expand Down
41 changes: 30 additions & 11 deletions port/stmicro/stm32/src/boards/STM32F3DISCOVERY.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const std = @import("std");

pub const microzig = @import("microzig");

pub const cpu_frequency = 8_000_000;
pub const hal = microzig.hal;
pub const rcc = hal.rcc;
pub const pins = hal.pins;
const UART_LOG = microzig.hal.uart.Uart(.UART1);

pub const pin_map = .{
// circle of LEDs, connected to GPIOE bits 8..15
Expand All @@ -23,15 +28,29 @@ pub const pin_map = .{
.LD6 = "PE15",
};

pub fn debug_write(string: []const u8) void {
const uart1 = microzig.core.experimental.Uart(1, .{}).get_or_init(.{
.baud_rate = 9600,
.data_bits = .eight,
.parity = null,
.stop_bits = .one,
}) catch unreachable;
pub fn init() void {
hal.enable_fpu();
rcc.enable_hse(8_000_000);
rcc.enable_pll(.HSE, .Div1, .Mul5) catch {
@panic("PLL faile to enable");
};
rcc.select_pll_for_sysclk() catch {
@panic("Faile to select sysclk");
};
}

var uart_log: ?UART_LOG = null;

const writer = uart1.writer();
_ = writer.write(string) catch unreachable;
uart1.internal.txflush();
// Init should come first or the baud_rate would be too fast for the default HSI.
pub fn init_log() void {
_ = (pins.GlobalConfiguration{
.GPIOC = .{
.PIN4 = .{ .mode = .{ .alternate_function = .{ .afr = .AF7 } } },
.PIN5 = .{ .mode = .{ .alternate_function = .{ .afr = .AF7 } } },
},
}).apply();
uart_log = try microzig.hal.uart.Uart(.UART1).init(.{ .baud_rate = 115200 });
if (uart_log) |*logger| {
microzig.hal.uart.init_logger(logger);
}
}
Loading
Loading