diff options
| author | Timo Kröger <[email protected]> | 2021-07-29 15:54:11 +0200 |
|---|---|---|
| committer | Timo Kröger <[email protected]> | 2021-07-29 15:54:11 +0200 |
| commit | 4ccac69929b7025ee715c224584c8bebeb868763 (patch) | |
| tree | 1708c2792d5edf07e8fd8b9d56b40c9c354a8e65 /examples | |
| parent | 2a4890165d460324966a718fde9b712b06e3cc38 (diff) | |
stm32l4: Cleanup examples
* Use `cortex_m_rt::entry` for sync examples
* Use `Dbgmcu::enable_all()` everywhere
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32l4/src/bin/adc.rs | 18 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/blinky.rs | 9 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/button.rs | 16 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/button_exti.rs | 9 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/dac.rs | 18 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/spi.rs | 16 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/spi_dma.rs | 9 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/usart.rs | 19 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/usart_dma.rs | 9 |
9 files changed, 48 insertions, 75 deletions
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index f2a8bfb7f..457def6c2 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs | |||
| @@ -9,29 +9,27 @@ | |||
| 9 | #[path = "../example_common.rs"] | 9 | #[path = "../example_common.rs"] |
| 10 | mod example_common; | 10 | mod example_common; |
| 11 | 11 | ||
| 12 | use defmt::panic; | ||
| 13 | use embassy::executor::Spawner; | ||
| 14 | use embassy::time::Delay; | 12 | use embassy::time::Delay; |
| 15 | use embassy_stm32::adc::{Adc, Resolution}; | 13 | use embassy_stm32::adc::{Adc, Resolution}; |
| 16 | use embassy_stm32::{pac, Peripherals}; | 14 | use embassy_stm32::dbgmcu::Dbgmcu; |
| 15 | use embassy_stm32::pac; | ||
| 17 | use example_common::*; | 16 | use example_common::*; |
| 18 | 17 | ||
| 19 | #[embassy::main] | 18 | #[cortex_m_rt::entry] |
| 20 | async fn main(_spawner: Spawner, p: Peripherals) { | 19 | fn main() -> ! { |
| 21 | info!("Hello World!"); | 20 | info!("Hello World!"); |
| 22 | 21 | ||
| 23 | unsafe { | 22 | unsafe { |
| 23 | Dbgmcu::enable_all(); | ||
| 24 | |||
| 24 | pac::RCC.ccipr().modify(|w| { | 25 | pac::RCC.ccipr().modify(|w| { |
| 25 | w.set_adcsel(0b11); | 26 | w.set_adcsel(0b11); |
| 26 | }); | 27 | }); |
| 27 | pac::DBGMCU.cr().modify(|w| { | ||
| 28 | w.set_dbg_sleep(true); | ||
| 29 | w.set_dbg_standby(true); | ||
| 30 | w.set_dbg_stop(true); | ||
| 31 | }); | ||
| 32 | pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); | 28 | pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); |
| 33 | } | 29 | } |
| 34 | 30 | ||
| 31 | let p = embassy_stm32::init(Default::default()); | ||
| 32 | |||
| 35 | let mut adc = Adc::new(p.ADC1, &mut Delay); | 33 | let mut adc = Adc::new(p.ADC1, &mut Delay); |
| 36 | //adc.enable_vref(); | 34 | //adc.enable_vref(); |
| 37 | adc.set_resolution(Resolution::EightBit); | 35 | adc.set_resolution(Resolution::EightBit); |
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs index 1064bcd55..c98033831 100644 --- a/examples/stm32l4/src/bin/blinky.rs +++ b/examples/stm32l4/src/bin/blinky.rs | |||
| @@ -11,8 +11,9 @@ mod example_common; | |||
| 11 | use defmt::panic; | 11 | use defmt::panic; |
| 12 | use embassy::executor::Spawner; | 12 | use embassy::executor::Spawner; |
| 13 | use embassy::time::{Duration, Timer}; | 13 | use embassy::time::{Duration, Timer}; |
| 14 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 14 | use embassy_stm32::gpio::{Level, Output, Speed}; | 15 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 15 | use embassy_stm32::{pac, Peripherals}; | 16 | use embassy_stm32::Peripherals; |
| 16 | use embedded_hal::digital::v2::OutputPin; | 17 | use embedded_hal::digital::v2::OutputPin; |
| 17 | use example_common::*; | 18 | use example_common::*; |
| 18 | 19 | ||
| @@ -21,11 +22,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 21 | info!("Hello World!"); | 22 | info!("Hello World!"); |
| 22 | 23 | ||
| 23 | unsafe { | 24 | unsafe { |
| 24 | pac::DBGMCU.cr().modify(|w| { | 25 | Dbgmcu::enable_all(); |
| 25 | w.set_dbg_sleep(true); | ||
| 26 | w.set_dbg_standby(true); | ||
| 27 | w.set_dbg_stop(true); | ||
| 28 | }); | ||
| 29 | } | 26 | } |
| 30 | 27 | ||
| 31 | let mut led = Output::new(p.PB14, Level::High, Speed::Low); | 28 | let mut led = Output::new(p.PB14, Level::High, Speed::Low); |
diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs index 08c20ce4b..5bebfae7f 100644 --- a/examples/stm32l4/src/bin/button.rs +++ b/examples/stm32l4/src/bin/button.rs | |||
| @@ -8,25 +8,21 @@ | |||
| 8 | 8 | ||
| 9 | #[path = "../example_common.rs"] | 9 | #[path = "../example_common.rs"] |
| 10 | mod example_common; | 10 | mod example_common; |
| 11 | use defmt::panic; | 11 | use embassy_stm32::dbgmcu::Dbgmcu; |
| 12 | use embassy::executor::Spawner; | ||
| 13 | use embassy_stm32::gpio::{Input, Pull}; | 12 | use embassy_stm32::gpio::{Input, Pull}; |
| 14 | use embassy_stm32::{pac, Peripherals}; | ||
| 15 | use embedded_hal::digital::v2::InputPin; | 13 | use embedded_hal::digital::v2::InputPin; |
| 16 | use example_common::*; | 14 | use example_common::*; |
| 17 | 15 | ||
| 18 | #[embassy::main] | 16 | #[cortex_m_rt::entry] |
| 19 | async fn main(_spawner: Spawner, p: Peripherals) { | 17 | fn main() -> ! { |
| 20 | info!("Hello World!"); | 18 | info!("Hello World!"); |
| 21 | 19 | ||
| 22 | unsafe { | 20 | unsafe { |
| 23 | pac::DBGMCU.cr().modify(|w| { | 21 | Dbgmcu::enable_all(); |
| 24 | w.set_dbg_sleep(true); | ||
| 25 | w.set_dbg_standby(true); | ||
| 26 | w.set_dbg_stop(true); | ||
| 27 | }); | ||
| 28 | } | 22 | } |
| 29 | 23 | ||
| 24 | let p = embassy_stm32::init(Default::default()); | ||
| 25 | |||
| 30 | let button = Input::new(p.PC13, Pull::Up); | 26 | let button = Input::new(p.PC13, Pull::Up); |
| 31 | 27 | ||
| 32 | loop { | 28 | loop { |
diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs index 5ab7dd9ab..42efa0d6c 100644 --- a/examples/stm32l4/src/bin/button_exti.rs +++ b/examples/stm32l4/src/bin/button_exti.rs | |||
| @@ -10,9 +10,10 @@ | |||
| 10 | mod example_common; | 10 | mod example_common; |
| 11 | use defmt::panic; | 11 | use defmt::panic; |
| 12 | use embassy::executor::Spawner; | 12 | use embassy::executor::Spawner; |
| 13 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 13 | use embassy_stm32::exti::ExtiInput; | 14 | use embassy_stm32::exti::ExtiInput; |
| 14 | use embassy_stm32::gpio::{Input, Pull}; | 15 | use embassy_stm32::gpio::{Input, Pull}; |
| 15 | use embassy_stm32::{pac, Peripherals}; | 16 | use embassy_stm32::Peripherals; |
| 16 | use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; | 17 | use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; |
| 17 | use example_common::*; | 18 | use example_common::*; |
| 18 | 19 | ||
| @@ -21,11 +22,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 21 | info!("Hello World!"); | 22 | info!("Hello World!"); |
| 22 | 23 | ||
| 23 | unsafe { | 24 | unsafe { |
| 24 | pac::DBGMCU.cr().modify(|w| { | 25 | Dbgmcu::enable_all(); |
| 25 | w.set_dbg_sleep(true); | ||
| 26 | w.set_dbg_standby(true); | ||
| 27 | w.set_dbg_stop(true); | ||
| 28 | }); | ||
| 29 | } | 26 | } |
| 30 | 27 | ||
| 31 | let button = Input::new(p.PC13, Pull::Up); | 28 | let button = Input::new(p.PC13, Pull::Up); |
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index 46f59ec12..8e2431ec7 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs | |||
| @@ -9,28 +9,26 @@ | |||
| 9 | #[path = "../example_common.rs"] | 9 | #[path = "../example_common.rs"] |
| 10 | mod example_common; | 10 | mod example_common; |
| 11 | 11 | ||
| 12 | use defmt::panic; | ||
| 13 | use embassy::executor::Spawner; | ||
| 14 | use embassy_stm32::dac::{Channel, Dac, Value}; | 12 | use embassy_stm32::dac::{Channel, Dac, Value}; |
| 13 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 15 | use embassy_stm32::gpio::NoPin; | 14 | use embassy_stm32::gpio::NoPin; |
| 16 | use embassy_stm32::{pac, Peripherals}; | 15 | use embassy_stm32::pac; |
| 17 | use example_common::*; | 16 | use example_common::*; |
| 18 | 17 | ||
| 19 | #[embassy::main] | 18 | #[cortex_m_rt::entry] |
| 20 | async fn main(_spawner: Spawner, p: Peripherals) { | 19 | fn main() -> ! { |
| 21 | info!("Hello World!"); | 20 | info!("Hello World!"); |
| 22 | 21 | ||
| 23 | unsafe { | 22 | unsafe { |
| 24 | pac::DBGMCU.cr().modify(|w| { | 23 | Dbgmcu::enable_all(); |
| 25 | w.set_dbg_sleep(true); | 24 | |
| 26 | w.set_dbg_standby(true); | ||
| 27 | w.set_dbg_stop(true); | ||
| 28 | }); | ||
| 29 | pac::RCC.apb1enr1().modify(|w| { | 25 | pac::RCC.apb1enr1().modify(|w| { |
| 30 | w.set_dac1en(true); | 26 | w.set_dac1en(true); |
| 31 | }); | 27 | }); |
| 32 | } | 28 | } |
| 33 | 29 | ||
| 30 | let p = embassy_stm32::init(Default::default()); | ||
| 31 | |||
| 34 | let mut dac = Dac::new(p.DAC1, p.PA4, NoPin); | 32 | let mut dac = Dac::new(p.DAC1, p.PA4, NoPin); |
| 35 | 33 | ||
| 36 | loop { | 34 | loop { |
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs index 14bfae512..e082b74e5 100644 --- a/examples/stm32l4/src/bin/spi.rs +++ b/examples/stm32l4/src/bin/spi.rs | |||
| @@ -9,29 +9,25 @@ | |||
| 9 | #[path = "../example_common.rs"] | 9 | #[path = "../example_common.rs"] |
| 10 | mod example_common; | 10 | mod example_common; |
| 11 | 11 | ||
| 12 | use defmt::panic; | 12 | use embassy_stm32::dbgmcu::Dbgmcu; |
| 13 | use embassy::executor::Spawner; | ||
| 14 | use embassy_stm32::dma::NoDma; | 13 | use embassy_stm32::dma::NoDma; |
| 15 | use embassy_stm32::gpio::{Level, Output, Speed}; | 14 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 16 | use embassy_stm32::spi::{Config, Spi}; | 15 | use embassy_stm32::spi::{Config, Spi}; |
| 17 | use embassy_stm32::time::Hertz; | 16 | use embassy_stm32::time::Hertz; |
| 18 | use embassy_stm32::{pac, Peripherals}; | ||
| 19 | use embedded_hal::blocking::spi::Transfer; | 17 | use embedded_hal::blocking::spi::Transfer; |
| 20 | use embedded_hal::digital::v2::OutputPin; | 18 | use embedded_hal::digital::v2::OutputPin; |
| 21 | use example_common::*; | 19 | use example_common::*; |
| 22 | 20 | ||
| 23 | #[embassy::main] | 21 | #[cortex_m_rt::entry] |
| 24 | async fn main(_spawner: Spawner, p: Peripherals) { | 22 | fn main() -> ! { |
| 25 | info!("Hello World!"); | 23 | info!("Hello World!"); |
| 26 | 24 | ||
| 27 | unsafe { | 25 | unsafe { |
| 28 | pac::DBGMCU.cr().modify(|w| { | 26 | Dbgmcu::enable_all(); |
| 29 | w.set_dbg_sleep(true); | ||
| 30 | w.set_dbg_standby(true); | ||
| 31 | w.set_dbg_stop(true); | ||
| 32 | }); | ||
| 33 | } | 27 | } |
| 34 | 28 | ||
| 29 | let p = embassy_stm32::init(Default::default()); | ||
| 30 | |||
| 35 | let mut spi = Spi::new( | 31 | let mut spi = Spi::new( |
| 36 | p.SPI3, | 32 | p.SPI3, |
| 37 | p.PC10, | 33 | p.PC10, |
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs index 9672e2459..e32ff17f9 100644 --- a/examples/stm32l4/src/bin/spi_dma.rs +++ b/examples/stm32l4/src/bin/spi_dma.rs | |||
| @@ -11,10 +11,11 @@ mod example_common; | |||
| 11 | 11 | ||
| 12 | use defmt::panic; | 12 | use defmt::panic; |
| 13 | use embassy::executor::Spawner; | 13 | use embassy::executor::Spawner; |
| 14 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 14 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 15 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 15 | use embassy_stm32::spi::{Config, Spi}; | 16 | use embassy_stm32::spi::{Config, Spi}; |
| 16 | use embassy_stm32::time::Hertz; | 17 | use embassy_stm32::time::Hertz; |
| 17 | use embassy_stm32::{pac, Peripherals}; | 18 | use embassy_stm32::Peripherals; |
| 18 | use embassy_traits::spi::FullDuplex; | 19 | use embassy_traits::spi::FullDuplex; |
| 19 | use embedded_hal::digital::v2::{InputPin, OutputPin}; | 20 | use embedded_hal::digital::v2::{InputPin, OutputPin}; |
| 20 | use example_common::*; | 21 | use example_common::*; |
| @@ -24,11 +25,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 24 | info!("Hello World!"); | 25 | info!("Hello World!"); |
| 25 | 26 | ||
| 26 | unsafe { | 27 | unsafe { |
| 27 | pac::DBGMCU.cr().modify(|w| { | 28 | Dbgmcu::enable_all(); |
| 28 | w.set_dbg_sleep(true); | ||
| 29 | w.set_dbg_standby(true); | ||
| 30 | w.set_dbg_stop(true); | ||
| 31 | }); | ||
| 32 | } | 29 | } |
| 33 | 30 | ||
| 34 | let mut spi = Spi::new( | 31 | let mut spi = Spi::new( |
diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs index b93b5ab52..06abd41a2 100644 --- a/examples/stm32l4/src/bin/usart.rs +++ b/examples/stm32l4/src/bin/usart.rs | |||
| @@ -8,26 +8,23 @@ | |||
| 8 | 8 | ||
| 9 | #[path = "../example_common.rs"] | 9 | #[path = "../example_common.rs"] |
| 10 | mod example_common; | 10 | mod example_common; |
| 11 | use cortex_m::prelude::_embedded_hal_blocking_serial_Write; | 11 | |
| 12 | use defmt::panic; | 12 | use embassy_stm32::dbgmcu::Dbgmcu; |
| 13 | use embassy::executor::Spawner; | ||
| 14 | use embassy_stm32::dma::NoDma; | 13 | use embassy_stm32::dma::NoDma; |
| 15 | use embassy_stm32::usart::{Config, Uart}; | 14 | use embassy_stm32::usart::{Config, Uart}; |
| 16 | use embassy_stm32::{pac, Peripherals}; | 15 | use embedded_hal::blocking::serial::Write; |
| 17 | use example_common::*; | 16 | use example_common::*; |
| 18 | 17 | ||
| 19 | #[embassy::main] | 18 | #[cortex_m_rt::entry] |
| 20 | async fn main(_spawner: Spawner, p: Peripherals) { | 19 | fn main() -> ! { |
| 21 | info!("Hello World!"); | 20 | info!("Hello World!"); |
| 22 | 21 | ||
| 23 | unsafe { | 22 | unsafe { |
| 24 | pac::DBGMCU.cr().modify(|w| { | 23 | Dbgmcu::enable_all(); |
| 25 | w.set_dbg_sleep(true); | ||
| 26 | w.set_dbg_standby(true); | ||
| 27 | w.set_dbg_stop(true); | ||
| 28 | }); | ||
| 29 | } | 24 | } |
| 30 | 25 | ||
| 26 | let p = embassy_stm32::init(Default::default()); | ||
| 27 | |||
| 31 | let config = Config::default(); | 28 | let config = Config::default(); |
| 32 | let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config); | 29 | let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config); |
| 33 | 30 | ||
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs index cb01a2b5b..a90732ae0 100644 --- a/examples/stm32l4/src/bin/usart_dma.rs +++ b/examples/stm32l4/src/bin/usart_dma.rs | |||
| @@ -11,9 +11,10 @@ mod example_common; | |||
| 11 | use core::fmt::Write; | 11 | use core::fmt::Write; |
| 12 | use defmt::panic; | 12 | use defmt::panic; |
| 13 | use embassy::executor::Spawner; | 13 | use embassy::executor::Spawner; |
| 14 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 14 | use embassy_stm32::dma::NoDma; | 15 | use embassy_stm32::dma::NoDma; |
| 15 | use embassy_stm32::usart::{Config, Uart}; | 16 | use embassy_stm32::usart::{Config, Uart}; |
| 16 | use embassy_stm32::{pac, Peripherals}; | 17 | use embassy_stm32::Peripherals; |
| 17 | use embassy_traits::uart::Write as _; | 18 | use embassy_traits::uart::Write as _; |
| 18 | use example_common::*; | 19 | use example_common::*; |
| 19 | use heapless::String; | 20 | use heapless::String; |
| @@ -23,11 +24,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 23 | info!("Hello World!"); | 24 | info!("Hello World!"); |
| 24 | 25 | ||
| 25 | unsafe { | 26 | unsafe { |
| 26 | pac::DBGMCU.cr().modify(|w| { | 27 | Dbgmcu::enable_all(); |
| 27 | w.set_dbg_sleep(true); | ||
| 28 | w.set_dbg_standby(true); | ||
| 29 | w.set_dbg_stop(true); | ||
| 30 | }); | ||
| 31 | } | 28 | } |
| 32 | 29 | ||
| 33 | let config = Config::default(); | 30 | let config = Config::default(); |
