summaryrefslogtreecommitdiff
path: root/examples/stm32l4
diff options
context:
space:
mode:
authorTimo Kröger <timokroeger93@gmail.com>2021-07-29 15:54:11 +0200
committerTimo Kröger <timokroeger93@gmail.com>2021-07-29 15:54:11 +0200
commit4ccac69929b7025ee715c224584c8bebeb868763 (patch)
tree1708c2792d5edf07e8fd8b9d56b40c9c354a8e65 /examples/stm32l4
parent2a4890165d460324966a718fde9b712b06e3cc38 (diff)
downloadembassy-4ccac69929b7025ee715c224584c8bebeb868763.zip
stm32l4: Cleanup examples
* Use `cortex_m_rt::entry` for sync examples * Use `Dbgmcu::enable_all()` everywhere
Diffstat (limited to 'examples/stm32l4')
-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 f2a8bfb7..457def6c 100644
--- a/examples/stm32l4/src/bin/adc.rs
+++ b/examples/stm32l4/src/bin/adc.rs
@@ -9,29 +9,27 @@
#[path = "../example_common.rs"]
mod example_common;
-use defmt::panic;
-use embassy::executor::Spawner;
use embassy::time::Delay;
use embassy_stm32::adc::{Adc, Resolution};
-use embassy_stm32::{pac, Peripherals};
+use embassy_stm32::dbgmcu::Dbgmcu;
+use embassy_stm32::pac;
use example_common::*;
-#[embassy::main]
-async fn main(_spawner: Spawner, p: Peripherals) {
+#[cortex_m_rt::entry]
+fn main() -> ! {
info!("Hello World!");
unsafe {
+ Dbgmcu::enable_all();
+
pac::RCC.ccipr().modify(|w| {
w.set_adcsel(0b11);
});
- 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_adcen(true));
}
+ let p = embassy_stm32::init(Default::default());
+
let mut adc = Adc::new(p.ADC1, &mut Delay);
//adc.enable_vref();
adc.set_resolution(Resolution::EightBit);
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs
index 1064bcd5..c9803383 100644
--- a/examples/stm32l4/src/bin/blinky.rs
+++ b/examples/stm32l4/src/bin/blinky.rs
@@ -11,8 +11,9 @@ mod example_common;
use defmt::panic;
use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
+use embassy_stm32::dbgmcu::Dbgmcu;
use embassy_stm32::gpio::{Level, Output, Speed};
-use embassy_stm32::{pac, Peripherals};
+use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
@@ -21,11 +22,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
- pac::DBGMCU.cr().modify(|w| {
- w.set_dbg_sleep(true);
- w.set_dbg_standby(true);
- w.set_dbg_stop(true);
- });
+ Dbgmcu::enable_all();
}
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 08c20ce4..5bebfae7 100644
--- a/examples/stm32l4/src/bin/button.rs
+++ b/examples/stm32l4/src/bin/button.rs
@@ -8,25 +8,21 @@
#[path = "../example_common.rs"]
mod example_common;
-use defmt::panic;
-use embassy::executor::Spawner;
+use embassy_stm32::dbgmcu::Dbgmcu;
use embassy_stm32::gpio::{Input, Pull};
-use embassy_stm32::{pac, Peripherals};
use embedded_hal::digital::v2::InputPin;
use example_common::*;
-#[embassy::main]
-async fn main(_spawner: Spawner, p: Peripherals) {
+#[cortex_m_rt::entry]
+fn main() -> ! {
info!("Hello World!");
unsafe {
- pac::DBGMCU.cr().modify(|w| {
- w.set_dbg_sleep(true);
- w.set_dbg_standby(true);
- w.set_dbg_stop(true);
- });
+ Dbgmcu::enable_all();
}
+ let p = embassy_stm32::init(Default::default());
+
let button = Input::new(p.PC13, Pull::Up);
loop {
diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs
index 5ab7dd9a..42efa0d6 100644
--- a/examples/stm32l4/src/bin/button_exti.rs
+++ b/examples/stm32l4/src/bin/button_exti.rs
@@ -10,9 +10,10 @@
mod example_common;
use defmt::panic;
use embassy::executor::Spawner;
+use embassy_stm32::dbgmcu::Dbgmcu;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::{Input, Pull};
-use embassy_stm32::{pac, Peripherals};
+use embassy_stm32::Peripherals;
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
use example_common::*;
@@ -21,11 +22,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
- pac::DBGMCU.cr().modify(|w| {
- w.set_dbg_sleep(true);
- w.set_dbg_standby(true);
- w.set_dbg_stop(true);
- });
+ Dbgmcu::enable_all();
}
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 46f59ec1..8e2431ec 100644
--- a/examples/stm32l4/src/bin/dac.rs
+++ b/examples/stm32l4/src/bin/dac.rs
@@ -9,28 +9,26 @@
#[path = "../example_common.rs"]
mod example_common;
-use defmt::panic;
-use embassy::executor::Spawner;
use embassy_stm32::dac::{Channel, Dac, Value};
+use embassy_stm32::dbgmcu::Dbgmcu;
use embassy_stm32::gpio::NoPin;
-use embassy_stm32::{pac, Peripherals};
+use embassy_stm32::pac;
use example_common::*;
-#[embassy::main]
-async fn main(_spawner: Spawner, p: Peripherals) {
+#[cortex_m_rt::entry]
+fn main() -> ! {
info!("Hello World!");
unsafe {
- pac::DBGMCU.cr().modify(|w| {
- w.set_dbg_sleep(true);
- w.set_dbg_standby(true);
- w.set_dbg_stop(true);
- });
+ Dbgmcu::enable_all();
+
pac::RCC.apb1enr1().modify(|w| {
w.set_dac1en(true);
});
}
+ let p = embassy_stm32::init(Default::default());
+
let mut dac = Dac::new(p.DAC1, p.PA4, NoPin);
loop {
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index 14bfae51..e082b74e 100644
--- a/examples/stm32l4/src/bin/spi.rs
+++ b/examples/stm32l4/src/bin/spi.rs
@@ -9,29 +9,25 @@
#[path = "../example_common.rs"]
mod example_common;
-use defmt::panic;
-use embassy::executor::Spawner;
+use embassy_stm32::dbgmcu::Dbgmcu;
use embassy_stm32::dma::NoDma;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
-use embassy_stm32::{pac, Peripherals};
use embedded_hal::blocking::spi::Transfer;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
-#[embassy::main]
-async fn main(_spawner: Spawner, p: Peripherals) {
+#[cortex_m_rt::entry]
+fn main() -> ! {
info!("Hello World!");
unsafe {
- pac::DBGMCU.cr().modify(|w| {
- w.set_dbg_sleep(true);
- w.set_dbg_standby(true);
- w.set_dbg_stop(true);
- });
+ Dbgmcu::enable_all();
}
+ let p = embassy_stm32::init(Default::default());
+
let mut spi = Spi::new(
p.SPI3,
p.PC10,
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 9672e245..e32ff17f 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -11,10 +11,11 @@ mod example_common;
use defmt::panic;
use embassy::executor::Spawner;
+use embassy_stm32::dbgmcu::Dbgmcu;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
-use embassy_stm32::{pac, Peripherals};
+use embassy_stm32::Peripherals;
use embassy_traits::spi::FullDuplex;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
@@ -24,11 +25,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
- pac::DBGMCU.cr().modify(|w| {
- w.set_dbg_sleep(true);
- w.set_dbg_standby(true);
- w.set_dbg_stop(true);
- });
+ Dbgmcu::enable_all();
}
let mut spi = Spi::new(
diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs
index b93b5ab5..06abd41a 100644
--- a/examples/stm32l4/src/bin/usart.rs
+++ b/examples/stm32l4/src/bin/usart.rs
@@ -8,26 +8,23 @@
#[path = "../example_common.rs"]
mod example_common;
-use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
-use defmt::panic;
-use embassy::executor::Spawner;
+
+use embassy_stm32::dbgmcu::Dbgmcu;
use embassy_stm32::dma::NoDma;
use embassy_stm32::usart::{Config, Uart};
-use embassy_stm32::{pac, Peripherals};
+use embedded_hal::blocking::serial::Write;
use example_common::*;
-#[embassy::main]
-async fn main(_spawner: Spawner, p: Peripherals) {
+#[cortex_m_rt::entry]
+fn main() -> ! {
info!("Hello World!");
unsafe {
- pac::DBGMCU.cr().modify(|w| {
- w.set_dbg_sleep(true);
- w.set_dbg_standby(true);
- w.set_dbg_stop(true);
- });
+ Dbgmcu::enable_all();
}
+ let p = embassy_stm32::init(Default::default());
+
let config = Config::default();
let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config);
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs
index cb01a2b5..a90732ae 100644
--- a/examples/stm32l4/src/bin/usart_dma.rs
+++ b/examples/stm32l4/src/bin/usart_dma.rs
@@ -11,9 +11,10 @@ mod example_common;
use core::fmt::Write;
use defmt::panic;
use embassy::executor::Spawner;
+use embassy_stm32::dbgmcu::Dbgmcu;
use embassy_stm32::dma::NoDma;
use embassy_stm32::usart::{Config, Uart};
-use embassy_stm32::{pac, Peripherals};
+use embassy_stm32::Peripherals;
use embassy_traits::uart::Write as _;
use example_common::*;
use heapless::String;
@@ -23,11 +24,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
unsafe {
- pac::DBGMCU.cr().modify(|w| {
- w.set_dbg_sleep(true);
- w.set_dbg_standby(true);
- w.set_dbg_stop(true);
- });
+ Dbgmcu::enable_all();
}
let config = Config::default();