From 71c8d7aa7d84175810b6495c72d3767179d6b341 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 15 Jul 2021 00:30:31 +0200 Subject: stm32l4/examples: remove old-pac uses. --- examples/stm32l4/Cargo.toml | 2 +- examples/stm32l4/src/bin/blinky.rs | 38 +++++++++--------- examples/stm32l4/src/bin/button.rs | 42 ++++++++++---------- examples/stm32l4/src/bin/button_exti.rs | 47 +++++++++++----------- examples/stm32l4/src/bin/spi.rs | 42 ++++++++++---------- examples/stm32l4/src/bin/usart.rs | 70 +++++++++++++++------------------ examples/stm32l4/src/bin/usart_dma.rs | 68 ++++++++++++++------------------ 7 files changed, 147 insertions(+), 162 deletions(-) (limited to 'examples/stm32l4') diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index 48125c4f..069c1434 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml @@ -19,7 +19,7 @@ defmt-error = [] [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } -embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32l4s5vi"] } +embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "unstable-pac", "stm32l4s5vi"] } embassy-extras = {version = "0.1.0", path = "../../embassy-extras" } stm32l4 = { version = "0.13", features = ["stm32l4x5" ] } stm32l4xx-hal = { version = "0.6.0", features = ["stm32l4x5"] } diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs index ae4b3d1d..0af16867 100644 --- a/examples/stm32l4/src/bin/blinky.rs +++ b/examples/stm32l4/src/bin/blinky.rs @@ -8,34 +8,32 @@ #[path = "../example_common.rs"] mod example_common; +use cortex_m_rt::entry; use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::pac; use embedded_hal::digital::v2::OutputPin; use example_common::*; -use cortex_m_rt::entry; -use stm32l4::stm32l4x5 as pac; - #[entry] fn main() -> ! { info!("Hello World!"); - let pp = pac::Peripherals::take().unwrap(); - - pp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - - pp.RCC.ahb2enr.modify(|_, w| { - w.gpioaen().set_bit(); - w.gpioben().set_bit(); - w.gpiocen().set_bit(); - w.gpioden().set_bit(); - w.gpioeen().set_bit(); - w.gpiofen().set_bit(); - w - }); + unsafe { + pac::DBGMCU.cr().modify(|w| { + w.set_dbg_sleep(true); + w.set_dbg_standby(true); + w.set_dbg_stop(true); + }); + + pac::RCC.ahb2enr().modify(|w| { + w.set_gpioaen(true); + w.set_gpioben(true); + w.set_gpiocen(true); + w.set_gpioden(true); + w.set_gpioeen(true); + w.set_gpiofen(true); + }); + } let p = embassy_stm32::init(Default::default()); diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs index 3efeee20..c7246360 100644 --- a/examples/stm32l4/src/bin/button.rs +++ b/examples/stm32l4/src/bin/button.rs @@ -8,34 +8,36 @@ #[path = "../example_common.rs"] mod example_common; +use cortex_m_rt::entry; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::pac; use embedded_hal::digital::v2::{InputPin, OutputPin}; use example_common::*; -use cortex_m_rt::entry; -use stm32l4::stm32l4x5 as pac; - #[entry] fn main() -> ! { info!("Hello World!"); - let pp = pac::Peripherals::take().unwrap(); - - pp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - - pp.RCC.ahb2enr.modify(|_, w| { - w.gpioaen().set_bit(); - w.gpioben().set_bit(); - w.gpiocen().set_bit(); - w.gpioden().set_bit(); - w.gpioeen().set_bit(); - w.gpiofen().set_bit(); - w - }); + unsafe { + pac::DBGMCU.cr().modify(|w| { + w.set_dbg_sleep(true); + w.set_dbg_standby(true); + w.set_dbg_stop(true); + }); + + pac::RCC.apb2enr().modify(|w| { + w.set_syscfgen(true); + }); + + pac::RCC.ahb2enr().modify(|w| { + w.set_gpioaen(true); + w.set_gpioben(true); + w.set_gpiocen(true); + w.set_gpioden(true); + w.set_gpioeen(true); + w.set_gpiofen(true); + }); + } let p = embassy_stm32::init(Default::default()); diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs index c6b7c83e..6a06e437 100644 --- a/examples/stm32l4/src/bin/button_exti.rs +++ b/examples/stm32l4/src/bin/button_exti.rs @@ -8,17 +8,16 @@ #[path = "../example_common.rs"] mod example_common; +use cortex_m_rt::entry; use embassy::executor::Executor; use embassy::time::Clock; use embassy::util::Forever; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; +use embassy_stm32::pac; use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; use example_common::*; -use cortex_m_rt::entry; -use stm32l4::stm32l4x5 as pac; - #[embassy::task] async fn main_task() { let p = embassy_stm32::init(Default::default()); @@ -50,28 +49,26 @@ static EXECUTOR: Forever = Forever::new(); fn main() -> ! { info!("Hello World!"); - let pp = pac::Peripherals::take().unwrap(); - - pp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - - pp.RCC.ahb2enr.modify(|_, w| { - w.gpioaen().set_bit(); - w.gpioben().set_bit(); - w.gpiocen().set_bit(); - w.gpioden().set_bit(); - w.gpioeen().set_bit(); - w.gpiofen().set_bit(); - w - }); - - pp.RCC.apb2enr.modify(|_, w| { - w.syscfgen().set_bit(); - w - }); + unsafe { + pac::DBGMCU.cr().modify(|w| { + w.set_dbg_sleep(true); + w.set_dbg_standby(true); + w.set_dbg_stop(true); + }); + + pac::RCC.apb2enr().modify(|w| { + w.set_syscfgen(true); + }); + + pac::RCC.ahb2enr().modify(|w| { + w.set_gpioaen(true); + w.set_gpioben(true); + w.set_gpiocen(true); + w.set_gpioden(true); + w.set_gpioeen(true); + w.set_gpiofen(true); + }); + } unsafe { embassy::time::set_clock(&ZeroClock) }; diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs index 28c563c1..45ccfceb 100644 --- a/examples/stm32l4/src/bin/spi.rs +++ b/examples/stm32l4/src/bin/spi.rs @@ -9,37 +9,39 @@ #[path = "../example_common.rs"] mod example_common; -use embassy_stm32::gpio::{Level, Output, Speed}; -use embedded_hal::digital::v2::OutputPin; -use example_common::*; - use cortex_m_rt::entry; +use embassy_stm32::gpio::{Level, Output, Speed}; +use embassy_stm32::pac; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; use embedded_hal::blocking::spi::Transfer; -use stm32l4::stm32l4x5 as pac; +use embedded_hal::digital::v2::OutputPin; +use example_common::*; #[entry] fn main() -> ! { info!("Hello World, dude!"); - let pp = pac::Peripherals::take().unwrap(); + unsafe { + pac::DBGMCU.cr().modify(|w| { + w.set_dbg_sleep(true); + w.set_dbg_standby(true); + w.set_dbg_stop(true); + }); - pp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); + pac::RCC.apb2enr().modify(|w| { + w.set_syscfgen(true); + }); - pp.RCC.ahb2enr.modify(|_, w| { - w.gpioaen().set_bit(); - w.gpioben().set_bit(); - w.gpiocen().set_bit(); - w.gpioden().set_bit(); - w.gpioeen().set_bit(); - w.gpiofen().set_bit(); - w - }); + pac::RCC.ahb2enr().modify(|w| { + w.set_gpioaen(true); + w.set_gpioben(true); + w.set_gpiocen(true); + w.set_gpioden(true); + w.set_gpioeen(true); + w.set_gpiofen(true); + }); + } let p = embassy_stm32::init(Default::default()); diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs index dc0f649b..e9a44f15 100644 --- a/examples/stm32l4/src/bin/usart.rs +++ b/examples/stm32l4/src/bin/usart.rs @@ -1,4 +1,3 @@ - #![no_std] #![no_main] #![feature(trait_alias)] @@ -10,16 +9,15 @@ #[path = "../example_common.rs"] mod example_common; use cortex_m::prelude::_embedded_hal_blocking_serial_Write; +use cortex_m_rt::entry; use embassy::executor::Executor; use embassy::time::Clock; use embassy::util::Forever; +use embassy_stm32::dma_traits::NoDma; +use embassy_stm32::pac; use embassy_stm32::usart::{Config, Uart}; use example_common::*; -use cortex_m_rt::entry; -use stm32l4::stm32l4x5 as pac; -use embassy_stm32::dma_traits::NoDma; - #[embassy::task] async fn main_task() { let p = embassy_stm32::init(Default::default()); @@ -51,38 +49,34 @@ static EXECUTOR: Forever = Forever::new(); fn main() -> ! { info!("Hello World!"); - let pp = pac::Peripherals::take().unwrap(); - - pp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - - pp.RCC.ahb1enr.modify(|_, w| { - w.dma1en().set_bit(); - w - }); - - pp.RCC.ahb2enr.modify(|_, w| { - w.gpioaen().set_bit(); - w.gpioben().set_bit(); - w.gpiocen().set_bit(); - w.gpioden().set_bit(); - w.gpioeen().set_bit(); - w.gpiofen().set_bit(); - w - }); - - pp.RCC.apb1enr1.modify(|_, w| { - w.uart4en().set_bit(); - w - }); - - pp.RCC.apb2enr.modify(|_, w| { - w.syscfgen().set_bit(); - w - }); + unsafe { + pac::DBGMCU.cr().modify(|w| { + w.set_dbg_sleep(true); + w.set_dbg_standby(true); + w.set_dbg_stop(true); + }); + + pac::RCC.ahb1enr().modify(|w| { + w.set_dma1en(true); + }); + + pac::RCC.ahb2enr().modify(|w| { + w.set_gpioaen(true); + w.set_gpioben(true); + w.set_gpiocen(true); + w.set_gpioden(true); + w.set_gpioeen(true); + w.set_gpiofen(true); + }); + + pac::RCC.apb1enr1().modify(|w| { + w.set_uart4en(true); + }); + + pac::RCC.apb2enr().modify(|w| { + w.set_syscfgen(true); + }); + } unsafe { embassy::time::set_clock(&ZeroClock) }; @@ -91,4 +85,4 @@ fn main() -> ! { executor.run(|spawner| { unwrap!(spawner.spawn(main_task())); }) -} \ No newline at end of file +} diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs index 6a234185..1eadd3ad 100644 --- a/examples/stm32l4/src/bin/usart_dma.rs +++ b/examples/stm32l4/src/bin/usart_dma.rs @@ -13,12 +13,12 @@ use cortex_m_rt::entry; use embassy::executor::Executor; use embassy::time::Clock; use embassy::util::Forever; +use embassy_stm32::dma_traits::NoDma; +use embassy_stm32::pac; use embassy_stm32::usart::{Config, Uart}; +use embassy_traits::uart::Write as _; use example_common::*; use heapless::String; -use stm32l4::stm32l4x5 as pac; -use embassy_stm32::dma_traits::NoDma; -use embassy_traits::uart::Write as AsyncWrite; #[embassy::task] async fn main_task() { @@ -31,7 +31,7 @@ async fn main_task() { let mut s: String<128> = String::new(); core::write!(&mut s, "Hello DMA World {}!\r\n", n).unwrap(); - usart.write( s.as_bytes() ).await.ok(); + usart.write(s.as_bytes()).await.ok(); info!("wrote DMA"); } @@ -51,40 +51,32 @@ static EXECUTOR: Forever = Forever::new(); fn main() -> ! { info!("Hello World!"); - let pp = pac::Peripherals::take().unwrap(); - - pp.DBGMCU.cr.modify(|_, w| { - w.dbg_sleep().set_bit(); - w.dbg_standby().set_bit(); - w.dbg_stop().set_bit() - }); - - pp.RCC.ahb1enr.modify(|_, w| { - unsafe { - w.bits( 0x07 ); - } - w - //w.dmamuxen().set_bit(); - //w.dma1en().set_bit(); - //w.dma2en().set_bit(); - //w - }); - - pp.RCC.ahb2enr.modify(|_, w| { - w.gpioaen().set_bit(); - w.gpioben().set_bit(); - w.gpiocen().set_bit(); - w.gpioden().set_bit(); - w.gpioeen().set_bit(); - w.gpiofen().set_bit(); - w - }); - - pp.RCC.apb2enr.modify(|_, w| { - w.syscfgen().set_bit(); - w - }); - + unsafe { + pac::DBGMCU.cr().modify(|w| { + w.set_dbg_sleep(true); + w.set_dbg_standby(true); + w.set_dbg_stop(true); + }); + + pac::RCC.apb2enr().modify(|w| { + w.set_syscfgen(true); + }); + + pac::RCC.ahb1enr().modify(|w| { + w.set_dmamux1en(true); + w.set_dma1en(true); + w.set_dma2en(true); + }); + + pac::RCC.ahb2enr().modify(|w| { + w.set_gpioaen(true); + w.set_gpioben(true); + w.set_gpiocen(true); + w.set_gpioden(true); + w.set_gpioeen(true); + w.set_gpiofen(true); + }); + } unsafe { embassy::time::set_clock(&ZeroClock) }; -- cgit v1.2.3