diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..4c8d0e1 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,4 @@ +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +wrap_comments = true +edition = "2021" diff --git a/Cargo.toml b/Cargo.toml index fca9008..10d8438 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,7 @@ bench = false codegen-units = 1 # better optimizations debug = true # symbols are nice and they don't increase the size on Flash lto = true # better optimizations + +[profile.dev.package."*"] +opt-level = "z" +debug = true diff --git a/src/main.rs b/src/main.rs index 2dfe299..c07e55c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,13 @@ #![no_std] #![no_main] -use stm32f3xx_hal::{self as hal, adc, pac, prelude::*}; - -use {defmt_rtt as _, panic_halt as _}; +use defmt_rtt as _; +#[allow(deprecated)] +use hal::pwm::{tim16, tim2, tim3}; +use panic_halt as _; +use stm32f3xx_hal::{ + self as hal, adc, flash::FlashExt, gpio::GpioExt, hal::PwmPin, pac, prelude::*, rcc::RccExt, +}; static POT_MAX: u16 = 4095; @@ -13,7 +17,9 @@ mod motor; #[cortex_m_rt::entry] fn main() -> ! { let sp = pac::Peripherals::take().unwrap(); + let mut flash = sp.FLASH.constrain(); let mut rcc = sp.RCC.constrain(); + let clocks = rcc.cfgr.freeze(&mut flash.acr); let mut gpiob = sp.GPIOB.split(&mut rcc.ahb); let mut led = gpiob .pb2 @@ -21,8 +27,6 @@ fn main() -> ! { let mut pot = gpiob.pb1.into_analog(&mut gpiob.moder, &mut gpiob.pupdr); - let mut flash = sp.FLASH.constrain(); - let clocks = rcc.cfgr.freeze(&mut flash.acr); let cp = cortex_m::Peripherals::take().unwrap(); let mut delay = hal::delay::Delay::new(cp.SYST, clocks); @@ -34,6 +38,7 @@ fn main() -> ! { &adc_common, ); + cortex_m::asm::wfi(); loop { let pot_out: u16 = padc.read(&mut pot).unwrap_or(0); let pot_out = (POT_MAX - pot_out) as f32 / POT_MAX as f32;