From e5b8d57c72a2de4a113d0186fa8fa133915bf1f6 Mon Sep 17 00:00:00 2001 From: Marnix Klooster Date: Sat, 23 Jul 2022 19:43:39 +0200 Subject: [PATCH] Stm32f303 target speed trivial check (#66) * Check new I2C target_speed config setting * Corrected incorrect doc comment --- src/core/i2c.zig | 3 +-- src/modules/chips/stm32f303/stm32f303.zig | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/i2c.zig b/src/core/i2c.zig index 48a23b4..2aa89f6 100644 --- a/src/core/i2c.zig +++ b/src/core/i2c.zig @@ -148,8 +148,7 @@ pub const Pins = struct { sda: ?type = null, }; -/// A UART configuration. The config defaults to the *8N1* setting, so "8 data bits, no parity, 1 stop bit" which is the -/// most common serial format. +/// An I2C configuration. pub const Config = struct { /// The target speed in bit/s. Note that the actual speed can differ from this, due to prescaler rounding. target_speed: u32, diff --git a/src/modules/chips/stm32f303/stm32f303.zig b/src/modules/chips/stm32f303/stm32f303.zig index a80a6a6..e9cc706 100644 --- a/src/modules/chips/stm32f303/stm32f303.zig +++ b/src/modules/chips/stm32f303/stm32f303.zig @@ -274,8 +274,6 @@ pub fn I2CController(comptime index: usize, comptime pins: micro.i2c.Pins) type const Self = @This(); pub fn init(config: micro.i2c.Config) !Self { - // TODO: use config - _ = config; // CONFIGURE I2C1 // connected to APB1, MCU pins PB6 + PB7 = I2C1_SCL + I2C1_SDA, // if GPIO port B is configured for alternate function 4 for these PB pins. @@ -307,6 +305,7 @@ pub fn I2CController(comptime index: usize, comptime pins: micro.i2c.Pins) type // 4-6. Configure I2C1 timing, based on 8 MHz I2C clock, run at 100 kHz // (Not using https://controllerstech.com/stm32-i2c-configuration-using-registers/ // but copying an example from the reference manual, RM0316 section 28.4.9.) + if (config.target_speed != 100_000) @panic("TODO: Support speeds other than 100 kHz"); regs.I2C1.TIMINGR.modify(.{ .PRESC = 1, .SCLL = 0x13,