Skip to content

Commit fb7bfef

Browse files
committed
Add I2C and improve FPU for stm32f3 core
1 parent b929a50 commit fb7bfef

File tree

8 files changed

+351
-285
lines changed

8 files changed

+351
-285
lines changed

core/src/cpus/cortex_m/m4.zig

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ pub const SystemControlBlock = extern struct {
8484
BFAR: u32,
8585
/// Auxilary Feature Register.
8686
AFSR: u32,
87+
reserved0: [18]u32,
88+
CPACR: mmio.Mmio(packed struct(u32) {
89+
reserved0: u20,
90+
CP10: Privilege,
91+
CP11: Privilege,
92+
reserved1: u8,
93+
94+
pub const Privilege = enum(u2) {
95+
/// Access denied. Any attempted access generates a NOCP UsageFault.
96+
access_denied = 0b00,
97+
/// Privileged access only. An unprivileged access generates a NOCP UsageFault.
98+
priviledged_access_only = 0b01,
99+
reserved = 0b10,
100+
/// Full access.
101+
full_access = 0b11,
102+
};
103+
}),
87104
};
88105

89106
pub const NestedVectorInterruptController = extern struct {
@@ -187,3 +204,39 @@ pub const MemoryProtectionUnit = extern struct {
187204
reserved2: u3 = 0,
188205
});
189206
};
207+
208+
pub const FloatingPointUnit = extern struct {
209+
FPCCR: mmio.Mmio(packed struct(u32) {
210+
LSPACT: u1,
211+
USER: u1,
212+
reserved0: u1 = 0,
213+
THREAD: u1,
214+
HFRDY: u1,
215+
MMRDY: u1,
216+
BFRDY: u1,
217+
reserved1: u1 = 0,
218+
MONRDY: u1,
219+
reserved2: u21 = 0,
220+
/// Automatic state preservation enable. Enables lazy context save of
221+
/// floating-point state. The possible values of this bit are:
222+
/// 0 = Disable automatic lazy context save.
223+
/// 1 = Enable automatic lazy state preservation for floating-point
224+
/// context.
225+
///
226+
/// Writes to this bit from Non-secure state are ignored if LSPENS is
227+
/// set to one.
228+
LSPEN: u1,
229+
/// Automatic state preservation enable. Enables CONTROL.FPCA setting
230+
/// on execution of a floating-point instruction. This results in
231+
/// automatic hardware state preservation and restoration, for
232+
/// floating-point context, on exception entry and exit. The possible
233+
/// values of this bit are:
234+
/// 1 = Enable CONTROL.FPCA setting on execution of a floating-point
235+
/// instruction.
236+
/// 0 = Disable CONTROL.FPCA setting on execution of a
237+
/// floating-point instruction.
238+
ASPEN: u1,
239+
}),
240+
FPCAR: u32,
241+
FPDSCR: u32,
242+
};

port/stmicro/stm32/src/boards/STM32F3DISCOVERY.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const std = @import("std");
2+
13
pub const microzig = @import("microzig");
24
pub const hal = microzig.hal;
35
pub const rcc = hal.rcc;
@@ -27,7 +29,7 @@ pub const pin_map = .{
2729
pub fn init() void {
2830
hal.enable_fpu();
2931
rcc.enable_hse(8_000_000);
30-
rcc.enable_pll(.HSE, .Div1, .Mul6) catch {
32+
rcc.enable_pll(.HSE, .Div1, .Mul5) catch {
3133
@panic("PLL faile to enable");
3234
};
3335
rcc.select_pll_for_sysclk() catch {

0 commit comments

Comments
 (0)