aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2021-07-29 15:54:11 +0200
committerTimo Kröger <[email protected]>2021-07-29 15:54:11 +0200
commit4ccac69929b7025ee715c224584c8bebeb868763 (patch)
tree1708c2792d5edf07e8fd8b9d56b40c9c354a8e65
parent2a4890165d460324966a718fde9b712b06e3cc38 (diff)
stm32l4: Cleanup examples
* Use `cortex_m_rt::entry` for sync examples * Use `Dbgmcu::enable_all()` everywhere
-rw-r--r--examples/stm32l4/src/bin/adc.rs18
-rw-r--r--examples/stm32l4/src/bin/blinky.rs9
-rw-r--r--examples/stm32l4/src/bin/button.rs16
-rw-r--r--examples/stm32l4/src/bin/button_exti.rs9
-rw-r--r--examples/stm32l4/src/bin/dac.rs18
-rw-r--r--examples/stm32l4/src/bin/spi.rs16
-rw-r--r--examples/stm32l4/src/bin/spi_dma.rs9
-rw-r--r--examples/stm32l4/src/bin/usart.rs19
-rw-r--r--examples/stm32l4/src/bin/usart_dma.rs9
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"]
10mod example_common; 10mod example_common;
11 11
12use defmt::panic;
13use embassy::executor::Spawner;
14use embassy::time::Delay; 12use embassy::time::Delay;
15use embassy_stm32::adc::{Adc, Resolution}; 13use embassy_stm32::adc::{Adc, Resolution};
16use embassy_stm32::{pac, Peripherals}; 14use embassy_stm32::dbgmcu::Dbgmcu;
15use embassy_stm32::pac;
17use example_common::*; 16use example_common::*;
18 17
19#[embassy::main] 18#[cortex_m_rt::entry]
20async fn main(_spawner: Spawner, p: Peripherals) { 19fn 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;
11use defmt::panic; 11use defmt::panic;
12use embassy::executor::Spawner; 12use embassy::executor::Spawner;
13use embassy::time::{Duration, Timer}; 13use embassy::time::{Duration, Timer};
14use embassy_stm32::dbgmcu::Dbgmcu;
14use embassy_stm32::gpio::{Level, Output, Speed}; 15use embassy_stm32::gpio::{Level, Output, Speed};
15use embassy_stm32::{pac, Peripherals}; 16use embassy_stm32::Peripherals;
16use embedded_hal::digital::v2::OutputPin; 17use embedded_hal::digital::v2::OutputPin;
17use example_common::*; 18use 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"]
10mod example_common; 10mod example_common;
11use defmt::panic; 11use embassy_stm32::dbgmcu::Dbgmcu;
12use embassy::executor::Spawner;
13use embassy_stm32::gpio::{Input, Pull}; 12use embassy_stm32::gpio::{Input, Pull};
14use embassy_stm32::{pac, Peripherals};
15use embedded_hal::digital::v2::InputPin; 13use embedded_hal::digital::v2::InputPin;
16use example_common::*; 14use example_common::*;
17 15
18#[embassy::main] 16#[cortex_m_rt::entry]
19async fn main(_spawner: Spawner, p: Peripherals) { 17fn 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 @@
10mod example_common; 10mod example_common;
11use defmt::panic; 11use defmt::panic;
12use embassy::executor::Spawner; 12use embassy::executor::Spawner;
13use embassy_stm32::dbgmcu::Dbgmcu;
13use embassy_stm32::exti::ExtiInput; 14use embassy_stm32::exti::ExtiInput;
14use embassy_stm32::gpio::{Input, Pull}; 15use embassy_stm32::gpio::{Input, Pull};
15use embassy_stm32::{pac, Peripherals}; 16use embassy_stm32::Peripherals;
16use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; 17use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
17use example_common::*; 18use 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"]
10mod example_common; 10mod example_common;
11 11
12use defmt::panic;
13use embassy::executor::Spawner;
14use embassy_stm32::dac::{Channel, Dac, Value}; 12use embassy_stm32::dac::{Channel, Dac, Value};
13use embassy_stm32::dbgmcu::Dbgmcu;
15use embassy_stm32::gpio::NoPin; 14use embassy_stm32::gpio::NoPin;
16use embassy_stm32::{pac, Peripherals}; 15use embassy_stm32::pac;
17use example_common::*; 16use example_common::*;
18 17
19#[embassy::main] 18#[cortex_m_rt::entry]
20async fn main(_spawner: Spawner, p: Peripherals) { 19fn 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"]
10mod example_common; 10mod example_common;
11 11
12use defmt::panic; 12use embassy_stm32::dbgmcu::Dbgmcu;
13use embassy::executor::Spawner;
14use embassy_stm32::dma::NoDma; 13use embassy_stm32::dma::NoDma;
15use embassy_stm32::gpio::{Level, Output, Speed}; 14use embassy_stm32::gpio::{Level, Output, Speed};
16use embassy_stm32::spi::{Config, Spi}; 15use embassy_stm32::spi::{Config, Spi};
17use embassy_stm32::time::Hertz; 16use embassy_stm32::time::Hertz;
18use embassy_stm32::{pac, Peripherals};
19use embedded_hal::blocking::spi::Transfer; 17use embedded_hal::blocking::spi::Transfer;
20use embedded_hal::digital::v2::OutputPin; 18use embedded_hal::digital::v2::OutputPin;
21use example_common::*; 19use example_common::*;
22 20
23#[embassy::main] 21#[cortex_m_rt::entry]
24async fn main(_spawner: Spawner, p: Peripherals) { 22fn 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
12use defmt::panic; 12use defmt::panic;
13use embassy::executor::Spawner; 13use embassy::executor::Spawner;
14use embassy_stm32::dbgmcu::Dbgmcu;
14use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 15use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
15use embassy_stm32::spi::{Config, Spi}; 16use embassy_stm32::spi::{Config, Spi};
16use embassy_stm32::time::Hertz; 17use embassy_stm32::time::Hertz;
17use embassy_stm32::{pac, Peripherals}; 18use embassy_stm32::Peripherals;
18use embassy_traits::spi::FullDuplex; 19use embassy_traits::spi::FullDuplex;
19use embedded_hal::digital::v2::{InputPin, OutputPin}; 20use embedded_hal::digital::v2::{InputPin, OutputPin};
20use example_common::*; 21use 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"]
10mod example_common; 10mod example_common;
11use cortex_m::prelude::_embedded_hal_blocking_serial_Write; 11
12use defmt::panic; 12use embassy_stm32::dbgmcu::Dbgmcu;
13use embassy::executor::Spawner;
14use embassy_stm32::dma::NoDma; 13use embassy_stm32::dma::NoDma;
15use embassy_stm32::usart::{Config, Uart}; 14use embassy_stm32::usart::{Config, Uart};
16use embassy_stm32::{pac, Peripherals}; 15use embedded_hal::blocking::serial::Write;
17use example_common::*; 16use example_common::*;
18 17
19#[embassy::main] 18#[cortex_m_rt::entry]
20async fn main(_spawner: Spawner, p: Peripherals) { 19fn 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;
11use core::fmt::Write; 11use core::fmt::Write;
12use defmt::panic; 12use defmt::panic;
13use embassy::executor::Spawner; 13use embassy::executor::Spawner;
14use embassy_stm32::dbgmcu::Dbgmcu;
14use embassy_stm32::dma::NoDma; 15use embassy_stm32::dma::NoDma;
15use embassy_stm32::usart::{Config, Uart}; 16use embassy_stm32::usart::{Config, Uart};
16use embassy_stm32::{pac, Peripherals}; 17use embassy_stm32::Peripherals;
17use embassy_traits::uart::Write as _; 18use embassy_traits::uart::Write as _;
18use example_common::*; 19use example_common::*;
19use heapless::String; 20use 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();