From 3c457bef6bb0a7d0b9d816e70719a94b5868921b Mon Sep 17 00:00:00 2001 From: Roma Sokolov Date: Tue, 7 Jul 2020 20:11:38 +0200 Subject: [PATCH] Bump stm32f --- Cargo.toml | 2 +- src/rcc.rs | 16 +++++---- src/timer.rs | 91 +++++++++++++++++++++++++--------------------------- 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c466d30..2da8a7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ bobbin-bits = "0.1.1" bitrate = "0.1.1" [dependencies.stm32f3] -version = "0.7.0" +version = "0.11.0" [dependencies.hal] features = ["unproven"] diff --git a/src/rcc.rs b/src/rcc.rs index b75d774..e79277b 100644 --- a/src/rcc.rs +++ b/src/rcc.rs @@ -2,8 +2,8 @@ use core::cmp; -use cast::u32; use crate::pac::{rcc, RCC}; +use cast::u32; use crate::flash::ACR; use crate::time::Hertz; @@ -336,9 +336,8 @@ impl CFGR { // WARNING! Bit 0 in cfgr2 is connected to bit 17 in cfgr (due to // MCU compatibility), if bit 0 is set here it must also // be set in any subsequent write to cfgr and vise-versa - rcc.cfgr2.write(|w| - w.prediv().bits(hse_cfg.divider as u8 - 1) - ); + rcc.cfgr2 + .write(|w| w.prediv().bits(hse_cfg.divider as u8 - 1)); while rcc.cr.read().hserdy().bit_is_clear() {} } @@ -348,12 +347,15 @@ impl CFGR { if let Some(_) = &self.hse { // HSE as PLL input - rcc.cfgr.modify(|_, w| unsafe { - w.pllsrc().hse_div_prediv().pllmul().bits(pllmul_bits) + rcc.cfgr.modify(|_, w| { + w.pllsrc() + .hse_div_prediv() + .pllmul() + .bits(pllmul_bits) }); } else { // HSI as PLL input - rcc.cfgr.write(|w| unsafe { w.pllmul().bits(pllmul_bits) }); + rcc.cfgr.write(|w| w.pllmul().bits(pllmul_bits)); } rcc.cr.modify(|_, w| w.pllon().set_bit()); diff --git a/src/timer.rs b/src/timer.rs index 5c63eaa..4da7395 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,5 +1,6 @@ //! Timers +use crate::pac::{TIM2, TIM3, TIM4}; use bobbin_bits::*; use cast::{u16, u32}; use core::intrinsics::transmute; @@ -7,7 +8,6 @@ use cortex_m::peripheral::syst::SystClkSource; use cortex_m::peripheral::SYST; use hal::timer::{CountDown, Periodic}; use nb; -use crate::pac::{TIM2, TIM3, TIM4}; use void::Void; use crate::rcc::Clocks; @@ -114,7 +114,6 @@ pub mod syst { } impl Periodic for Timer {} - } /// Trait for channel state @@ -334,25 +333,15 @@ macro_rules! tim { pub fn mode(self, nm: NM) -> Channel { let tim = unsafe { &(*$TIMSRC::ptr()) }; let mode_bits: u8 = nm.channel_mode().into(); - unsafe { - match CN::channel_number() { - U2::B00 => { - tim.ccmr1_output - .modify(|_, w| w.oc1m().bits(mode_bits)) - } - U2::B01 => { - tim.ccmr1_output - .modify(|_, w| w.oc2m().bits(mode_bits)) - } - U2::B10 => { - tim.ccmr2_output - .modify(|_, w| w.oc3m().bits(mode_bits)) - } - U2::B11 => { - tim.ccmr2_output - .modify(|_, w| w.oc4m().bits(mode_bits)) - } - } + match CN::channel_number() { + U2::B00 => tim.ccmr1_output() + .modify(|_, w| w.oc1m().bits(mode_bits)), + U2::B01 => tim.ccmr1_output() + .modify(|_, w| w.oc2m().bits(mode_bits)), + U2::B10 => tim.ccmr2_output() + .modify(|_, w| w.oc3m().bits(mode_bits)), + U2::B11 => tim.ccmr2_output() + .modify(|_, w| w.oc4m().bits(mode_bits)), } unsafe { transmute(self) } @@ -365,22 +354,24 @@ macro_rules! tim { let mask = true; if index < 2 { let offset: u32 = 3 + (index * 4); - tim.ccmr1_output.modify(|r, w| unsafe { - w.bits((r.bits() - & !((mask as u32) + tim.ccmr1_output().modify(|r, w| unsafe { + w.bits((r.bits() + & !((mask as u32) + << offset)) + | (((value & mask) + as u32) << offset)) - | (((value & mask) as u32) - << offset)) - }) + }) } else { let offset: u32 = 3 + (index - 2) * 4; - tim.ccmr2_output.modify(|r, w| unsafe { - w.bits((r.bits() - & !((mask as u32) + tim.ccmr2_output().modify(|r, w| unsafe { + w.bits((r.bits() + & !((mask as u32) + << offset)) + | (((value & mask) + as u32) << offset)) - | (((value & mask) as u32) - << offset)) - }) + }) }; } } @@ -499,11 +490,13 @@ macro_rules! tim { impl Timer { /// Consumes timer and returns pwm channels and timer without /// them. - pub fn use_pwm(self) -> ((Channel, - Channel, - Channel, - Channel), - Timer) { + pub fn use_pwm( + self) + -> ((Channel, + Channel, + Channel, + Channel), + Timer) { let ch1: Channel = Channel { _index: PhantomData, _mode: PhantomData }; @@ -524,21 +517,23 @@ macro_rules! tim { impl Timer { /// Returns pwm channels back. pub fn return_pwm(self, - _channels: (Channel, - Channel, - Channel, - Channel)) + _channels: (Channel, + Channel, + Channel, + Channel)) -> Timer - where - M1: ChMode, - M2: ChMode, - M3: ChMode, - M4: ChMode + where M1: ChMode, + M2: ChMode, + M3: ChMode, + M4: ChMode { unsafe { transmute(self) } } } - } }; }