From 558918651ee99024876fb1f85a559d46edba9548 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 19 Jun 2023 03:07:26 +0200 Subject: stm32: update stm32-metapac. --- examples/stm32f0/src/bin/wdg.rs | 4 +- examples/stm32f4/src/bin/wdt.rs | 8 +--- examples/stm32g4/src/bin/usb_serial.rs | 4 +- examples/stm32h5/src/bin/usb_serial.rs | 8 ++-- examples/stm32h7/src/bin/low_level_timer_api.rs | 54 ++++++++++--------------- examples/stm32h7/src/bin/wdg.rs | 4 +- examples/stm32l4/src/bin/adc.rs | 10 ++--- examples/stm32l4/src/bin/dac.rs | 8 ++-- examples/stm32wl/src/bin/lora_lorawan.rs | 2 +- examples/stm32wl/src/bin/random.rs | 8 ++-- 10 files changed, 43 insertions(+), 67 deletions(-) (limited to 'examples') diff --git a/examples/stm32f0/src/bin/wdg.rs b/examples/stm32f0/src/bin/wdg.rs index 80e76f901..a44b17528 100644 --- a/examples/stm32f0/src/bin/wdg.rs +++ b/examples/stm32f0/src/bin/wdg.rs @@ -16,10 +16,10 @@ async fn main(_spawner: Spawner) { let mut wdg = IndependentWatchdog::new(p.IWDG, 20_000_00); info!("Watchdog start"); - unsafe { wdg.unleash() }; + wdg.unleash(); loop { Timer::after(Duration::from_secs(1)).await; - unsafe { wdg.pet() }; + wdg.pet(); } } diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs index b2c587fa1..e5d122af7 100644 --- a/examples/stm32f4/src/bin/wdt.rs +++ b/examples/stm32f4/src/bin/wdt.rs @@ -17,9 +17,7 @@ async fn main(_spawner: Spawner) { let mut led = Output::new(p.PB7, Level::High, Speed::Low); let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000); - unsafe { - wdt.unleash(); - } + wdt.unleash(); let mut i = 0; @@ -36,9 +34,7 @@ async fn main(_spawner: Spawner) { // MCU should restart in 1 second after the last pet. if i < 5 { info!("Petting watchdog"); - unsafe { - wdt.pet(); - } + wdt.pet(); } i += 1; diff --git a/examples/stm32g4/src/bin/usb_serial.rs b/examples/stm32g4/src/bin/usb_serial.rs index ecbe3a6e6..c111a9787 100644 --- a/examples/stm32g4/src/bin/usb_serial.rs +++ b/examples/stm32g4/src/bin/usb_serial.rs @@ -38,9 +38,7 @@ async fn main(_spawner: Spawner) { let p = embassy_stm32::init(config); info!("Hello World!"); - unsafe { - pac::RCC.ccipr().write(|w| w.set_clk48sel(0b10)); - } + pac::RCC.ccipr().write(|w| w.set_clk48sel(0b10)); let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); diff --git a/examples/stm32h5/src/bin/usb_serial.rs b/examples/stm32h5/src/bin/usb_serial.rs index 3912327e2..336eed644 100644 --- a/examples/stm32h5/src/bin/usb_serial.rs +++ b/examples/stm32h5/src/bin/usb_serial.rs @@ -45,11 +45,9 @@ async fn main(_spawner: Spawner) { info!("Hello World!"); - unsafe { - pac::RCC.ccipr4().write(|w| { - w.set_usbsel(pac::rcc::vals::Usbsel::HSI48); - }); - } + pac::RCC.ccipr4().write(|w| { + w.set_usbsel(pac::rcc::vals::Usbsel::HSI48); + }); // Create the driver, from the HAL. let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 1972f8ff2..d360df085 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs @@ -62,49 +62,39 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { T::enable(); ::reset(); - unsafe { - ch1.set_speed(Speed::VeryHigh); - ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); - ch2.set_speed(Speed::VeryHigh); - ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); - ch3.set_speed(Speed::VeryHigh); - ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); - ch4.set_speed(Speed::VeryHigh); - ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); - } + ch1.set_speed(Speed::VeryHigh); + ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); + ch2.set_speed(Speed::VeryHigh); + ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); + ch3.set_speed(Speed::VeryHigh); + ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); + ch4.set_speed(Speed::VeryHigh); + ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); let mut this = Self { inner: tim }; this.set_freq(freq); this.inner.start(); - unsafe { - T::regs_gp32() - .ccmr_output(0) - .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); - T::regs_gp32() - .ccmr_output(0) - .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); - T::regs_gp32() - .ccmr_output(1) - .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); - T::regs_gp32() - .ccmr_output(1) - .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); - } + let r = T::regs_gp32(); + r.ccmr_output(0) + .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); + r.ccmr_output(0) + .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); + r.ccmr_output(1) + .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); + r.ccmr_output(1) + .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); + this } pub fn enable(&mut self, channel: Channel) { - unsafe { - T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); - } + T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); } pub fn disable(&mut self, channel: Channel) { - unsafe { - T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); - } + T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); } pub fn set_freq(&mut self, freq: Hertz) { @@ -112,11 +102,11 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { } pub fn get_max_duty(&self) -> u32 { - unsafe { T::regs_gp32().arr().read().arr() } + T::regs_gp32().arr().read().arr() } pub fn set_duty(&mut self, channel: Channel, duty: u32) { defmt::assert!(duty < self.get_max_duty()); - unsafe { T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) } + T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) } } diff --git a/examples/stm32h7/src/bin/wdg.rs b/examples/stm32h7/src/bin/wdg.rs index 2b0301aad..9181dfd67 100644 --- a/examples/stm32h7/src/bin/wdg.rs +++ b/examples/stm32h7/src/bin/wdg.rs @@ -15,10 +15,10 @@ async fn main(_spawner: Spawner) { let mut wdg = IndependentWatchdog::new(p.IWDG1, 20_000_000); - unsafe { wdg.unleash() }; + wdg.unleash(); loop { Timer::after(Duration::from_secs(1)).await; - unsafe { wdg.pet() }; + wdg.pet(); } } diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index 281346e5f..1771e5202 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs @@ -12,12 +12,10 @@ use {defmt_rtt as _, panic_probe as _}; fn main() -> ! { info!("Hello World!"); - unsafe { - pac::RCC.ccipr().modify(|w| { - w.set_adcsel(0b11); - }); - pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); - } + pac::RCC.ccipr().modify(|w| { + w.set_adcsel(0b11); + }); + pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); let p = embassy_stm32::init(Default::default()); diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index d6e744aa6..a36ed5d90 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs @@ -11,11 +11,9 @@ use {defmt_rtt as _, panic_probe as _}; fn main() -> ! { info!("Hello World!"); - unsafe { - pac::RCC.apb1enr1().modify(|w| { - w.set_dac1en(true); - }); - } + pac::RCC.apb1enr1().modify(|w| { + w.set_dac1en(true); + }); let p = embassy_stm32::init(Default::default()); diff --git a/examples/stm32wl/src/bin/lora_lorawan.rs b/examples/stm32wl/src/bin/lora_lorawan.rs index e179c5ca1..805d21418 100644 --- a/examples/stm32wl/src/bin/lora_lorawan.rs +++ b/examples/stm32wl/src/bin/lora_lorawan.rs @@ -35,7 +35,7 @@ async fn main(_spawner: Spawner) { config.rcc.enable_lsi = true; // enable RNG let p = embassy_stm32::init(config); - unsafe { pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)) } + pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)); let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); diff --git a/examples/stm32wl/src/bin/random.rs b/examples/stm32wl/src/bin/random.rs index 182c607f9..d8562fca5 100644 --- a/examples/stm32wl/src/bin/random.rs +++ b/examples/stm32wl/src/bin/random.rs @@ -15,11 +15,9 @@ async fn main(_spawner: Spawner) { config.rcc.enable_lsi = true; //Needed for RNG to work let p = embassy_stm32::init(config); - unsafe { - pac::RCC.ccipr().modify(|w| { - w.set_rngsel(0b01); - }); - } + pac::RCC.ccipr().modify(|w| { + w.set_rngsel(0b01); + }); info!("Hello World!"); -- cgit