aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32l0/src/bin/blinky.rs23
-rw-r--r--examples/stm32l0/src/bin/button_exti.rs38
2 files changed, 17 insertions, 44 deletions
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs
index 833c14fbf..7ccebae55 100644
--- a/examples/stm32l0/src/bin/blinky.rs
+++ b/examples/stm32l0/src/bin/blinky.rs
@@ -8,21 +8,20 @@
8 8
9#[path = "../example_common.rs"] 9#[path = "../example_common.rs"]
10mod example_common; 10mod example_common;
11use embassy_stm32::{ 11
12 gpio::{Level, Output, Speed}, 12use defmt::panic;
13 rcc::*, 13use embassy::executor::Spawner;
14}; 14use embassy::time::{Duration, Timer};
15use embassy_stm32::gpio::{Level, Output, Speed};
16use embassy_stm32::rcc::Rcc;
17use embassy_stm32::Peripherals;
15use embedded_hal::digital::v2::OutputPin; 18use embedded_hal::digital::v2::OutputPin;
16use example_common::*; 19use example_common::*;
17 20
18use cortex_m_rt::entry; 21#[embassy::main]
19 22async fn main(_spawner: Spawner, mut p: Peripherals) {
20#[entry]
21fn main() -> ! {
22 info!("Hello World!"); 23 info!("Hello World!");
23 24
24 let mut p = embassy_stm32::init(Default::default());
25
26 Rcc::new(p.RCC).enable_debug_wfe(&mut p.DBGMCU, true); 25 Rcc::new(p.RCC).enable_debug_wfe(&mut p.DBGMCU, true);
27 26
28 let mut led = Output::new(p.PB5, Level::High, Speed::Low); 27 let mut led = Output::new(p.PB5, Level::High, Speed::Low);
@@ -30,10 +29,10 @@ fn main() -> ! {
30 loop { 29 loop {
31 info!("high"); 30 info!("high");
32 led.set_high().unwrap(); 31 led.set_high().unwrap();
33 cortex_m::asm::delay(1_000_000); 32 Timer::after(Duration::from_millis(300)).await;
34 33
35 info!("low"); 34 info!("low");
36 led.set_low().unwrap(); 35 led.set_low().unwrap();
37 cortex_m::asm::delay(1_000_000); 36 Timer::after(Duration::from_millis(300)).await;
38 } 37 }
39} 38}
diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs
index a7f734942..6ea0d9cc9 100644
--- a/examples/stm32l0/src/bin/button_exti.rs
+++ b/examples/stm32l0/src/bin/button_exti.rs
@@ -8,20 +8,17 @@
8 8
9#[path = "../example_common.rs"] 9#[path = "../example_common.rs"]
10mod example_common; 10mod example_common;
11use embassy::executor::Executor; 11
12use embassy::time::Clock; 12use defmt::panic;
13use embassy::util::Forever; 13use embassy::executor::Spawner;
14use embassy_stm32::exti::ExtiInput; 14use embassy_stm32::exti::ExtiInput;
15use embassy_stm32::gpio::{Input, Pull}; 15use embassy_stm32::gpio::{Input, Pull};
16use embassy_stm32::rcc; 16use embassy_stm32::{rcc, Peripherals};
17use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; 17use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
18use example_common::*; 18use example_common::*;
19 19
20use cortex_m_rt::entry; 20#[embassy::main]
21 21async fn main(_spawner: Spawner, mut p: Peripherals) {
22#[embassy::task]
23async fn main_task() {
24 let mut p = embassy_stm32::init(Default::default());
25 let mut rcc = rcc::Rcc::new(p.RCC); 22 let mut rcc = rcc::Rcc::new(p.RCC);
26 rcc.enable_debug_wfe(&mut p.DBGMCU, true); 23 rcc.enable_debug_wfe(&mut p.DBGMCU, true);
27 // Enables SYSCFG 24 // Enables SYSCFG
@@ -39,26 +36,3 @@ async fn main_task() {
39 info!("Released!"); 36 info!("Released!");
40 } 37 }
41} 38}
42
43struct ZeroClock;
44
45impl Clock for ZeroClock {
46 fn now(&self) -> u64 {
47 0
48 }
49}
50
51static EXECUTOR: Forever<Executor> = Forever::new();
52
53#[entry]
54fn main() -> ! {
55 info!("Hello World!");
56
57 unsafe { embassy::time::set_clock(&ZeroClock) };
58
59 let executor = EXECUTOR.put(Executor::new());
60
61 executor.run(|spawner| {
62 unwrap!(spawner.spawn(main_task()));
63 })
64}