aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2021-07-21 23:12:36 +0200
committerTimo Kröger <[email protected]>2021-07-21 23:12:36 +0200
commit5e998d1a6c2a3307faae6b3a2f55d6712a394d59 (patch)
tree4d56cffd2a40930c2c91b605b5adbaacaf970531 /examples
parent40ea8298eedbe2430b647ab969d4a2e627b6ece8 (diff)
Cleanup stm32f4 examples
* Remove dependency on stm32f4 pac crate * Remove unused `ZeroClock`
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f4/Cargo.toml3
-rw-r--r--examples/stm32f4/src/bin/blinky.rs36
-rw-r--r--examples/stm32f4/src/bin/button.rs39
-rw-r--r--examples/stm32f4/src/bin/button_exti.rs56
-rw-r--r--examples/stm32f4/src/bin/spi.rs41
-rw-r--r--examples/stm32f4/src/bin/usart.rs55
-rw-r--r--examples/stm32f4/src/bin/usart_dma.rs51
7 files changed, 106 insertions, 175 deletions
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index 8625f83b5..704a76390 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -19,9 +19,8 @@ defmt-error = []
19[dependencies] 19[dependencies]
20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } 20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f429zi"] } 22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f429zi", "unstable-pac"] }
23embassy-extras = {version = "0.1.0", path = "../../embassy-extras" } 23embassy-extras = {version = "0.1.0", path = "../../embassy-extras" }
24stm32f4 = { version = "0.13", features = ["stm32f429"] }
25 24
26defmt = "0.2.0" 25defmt = "0.2.0"
27defmt-rtt = "0.2.0" 26defmt-rtt = "0.2.0"
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs
index d2b607c2c..0e411d782 100644
--- a/examples/stm32f4/src/bin/blinky.rs
+++ b/examples/stm32f4/src/bin/blinky.rs
@@ -9,34 +9,32 @@
9#[path = "../example_common.rs"] 9#[path = "../example_common.rs"]
10mod example_common; 10mod example_common;
11use embassy_stm32::gpio::{Level, Output, Speed}; 11use embassy_stm32::gpio::{Level, Output, Speed};
12use embassy_stm32::pac;
12use embedded_hal::digital::v2::OutputPin; 13use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 14use example_common::*;
14 15
15use cortex_m_rt::entry; 16use cortex_m_rt::entry;
16use stm32f4::stm32f429 as pac;
17 17
18#[entry] 18#[entry]
19fn main() -> ! { 19fn main() -> ! {
20 info!("Hello World!"); 20 info!("Hello World!");
21 21
22 let pp = pac::Peripherals::take().unwrap(); 22 unsafe {
23 23 pac::DBGMCU.cr().modify(|w| {
24 pp.DBGMCU.cr.modify(|_, w| { 24 w.set_dbg_sleep(true);
25 w.dbg_sleep().set_bit(); 25 w.set_dbg_standby(true);
26 w.dbg_standby().set_bit(); 26 w.set_dbg_stop(true);
27 w.dbg_stop().set_bit() 27 });
28 }); 28
29 pp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); 29 pac::RCC.ahb1enr().modify(|w| {
30 30 w.set_gpioaen(true);
31 pp.RCC.ahb1enr.modify(|_, w| { 31 w.set_gpioben(true);
32 w.gpioaen().enabled(); 32 w.set_gpiocen(true);
33 w.gpioben().enabled(); 33 w.set_gpioden(true);
34 w.gpiocen().enabled(); 34 w.set_gpioeen(true);
35 w.gpioden().enabled(); 35 w.set_gpiofen(true);
36 w.gpioeen().enabled(); 36 });
37 w.gpiofen().enabled(); 37 }
38 w
39 });
40 38
41 let p = embassy_stm32::init(Default::default()); 39 let p = embassy_stm32::init(Default::default());
42 40
diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs
index c7160d219..901fce418 100644
--- a/examples/stm32f4/src/bin/button.rs
+++ b/examples/stm32f4/src/bin/button.rs
@@ -8,35 +8,32 @@
8 8
9#[path = "../example_common.rs"] 9#[path = "../example_common.rs"]
10mod example_common; 10mod example_common;
11use cortex_m_rt::entry;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_stm32::pac;
12use embedded_hal::digital::v2::{InputPin, OutputPin}; 14use embedded_hal::digital::v2::{InputPin, OutputPin};
13use example_common::*; 15use example_common::*;
14 16
15use cortex_m_rt::entry;
16use stm32f4::stm32f429 as pac;
17
18#[entry] 17#[entry]
19fn main() -> ! { 18fn main() -> ! {
20 info!("Hello World!"); 19 info!("Hello World!");
21 20
22 let pp = pac::Peripherals::take().unwrap(); 21 unsafe {
23 22 pac::DBGMCU.cr().modify(|w| {
24 pp.DBGMCU.cr.modify(|_, w| { 23 w.set_dbg_sleep(true);
25 w.dbg_sleep().set_bit(); 24 w.set_dbg_standby(true);
26 w.dbg_standby().set_bit(); 25 w.set_dbg_stop(true);
27 w.dbg_stop().set_bit() 26 });
28 }); 27
29 pp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); 28 pac::RCC.ahb1enr().modify(|w| {
30 29 w.set_gpioaen(true);
31 pp.RCC.ahb1enr.modify(|_, w| { 30 w.set_gpioben(true);
32 w.gpioaen().enabled(); 31 w.set_gpiocen(true);
33 w.gpioben().enabled(); 32 w.set_gpioden(true);
34 w.gpiocen().enabled(); 33 w.set_gpioeen(true);
35 w.gpioden().enabled(); 34 w.set_gpiofen(true);
36 w.gpioeen().enabled(); 35 });
37 w.gpiofen().enabled(); 36 }
38 w
39 });
40 37
41 let p = embassy_stm32::init(Default::default()); 38 let p = embassy_stm32::init(Default::default());
42 39
diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs
index 8fc889dad..63c273b1a 100644
--- a/examples/stm32f4/src/bin/button_exti.rs
+++ b/examples/stm32f4/src/bin/button_exti.rs
@@ -9,7 +9,6 @@
9#[path = "../example_common.rs"] 9#[path = "../example_common.rs"]
10mod example_common; 10mod example_common;
11use embassy::executor::Executor; 11use embassy::executor::Executor;
12use embassy::time::Clock;
13use embassy::util::Forever; 12use embassy::util::Forever;
14use embassy_stm32::exti::ExtiInput; 13use embassy_stm32::exti::ExtiInput;
15use embassy_stm32::gpio::{Input, Pull}; 14use embassy_stm32::gpio::{Input, Pull};
@@ -17,7 +16,7 @@ use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
17use example_common::*; 16use example_common::*;
18 17
19use cortex_m_rt::entry; 18use cortex_m_rt::entry;
20use stm32f4::stm32f429 as pac; 19use embassy_stm32::pac;
21 20
22#[embassy::task] 21#[embassy::task]
23async fn main_task() { 22async fn main_task() {
@@ -36,44 +35,33 @@ async fn main_task() {
36 } 35 }
37} 36}
38 37
39struct ZeroClock;
40
41impl Clock for ZeroClock {
42 fn now(&self) -> u64 {
43 0
44 }
45}
46
47static EXECUTOR: Forever<Executor> = Forever::new(); 38static EXECUTOR: Forever<Executor> = Forever::new();
48 39
49#[entry] 40#[entry]
50fn main() -> ! { 41fn main() -> ! {
51 info!("Hello World!"); 42 info!("Hello World!");
52 43
53 let pp = pac::Peripherals::take().unwrap(); 44 unsafe {
54 45 pac::DBGMCU.cr().modify(|w| {
55 pp.DBGMCU.cr.modify(|_, w| { 46 w.set_dbg_sleep(true);
56 w.dbg_sleep().set_bit(); 47 w.set_dbg_standby(true);
57 w.dbg_standby().set_bit(); 48 w.set_dbg_stop(true);
58 w.dbg_stop().set_bit() 49 });
59 }); 50
60 pp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); 51 pac::RCC.ahb1enr().modify(|w| {
61 52 w.set_gpioaen(true);
62 pp.RCC.ahb1enr.modify(|_, w| { 53 w.set_gpioben(true);
63 w.gpioaen().enabled(); 54 w.set_gpiocen(true);
64 w.gpioben().enabled(); 55 w.set_gpioden(true);
65 w.gpiocen().enabled(); 56 w.set_gpioeen(true);
66 w.gpioden().enabled(); 57 w.set_gpiofen(true);
67 w.gpioeen().enabled(); 58 });
68 w.gpiofen().enabled(); 59
69 w 60 // EXTI clock
70 }); 61 pac::RCC.apb2enr().modify(|w| {
71 pp.RCC.apb2enr.modify(|_, w| { 62 w.set_syscfgen(true);
72 w.syscfgen().enabled(); 63 });
73 w 64 }
74 });
75
76 unsafe { embassy::time::set_clock(&ZeroClock) };
77 65
78 let executor = EXECUTOR.put(Executor::new()); 66 let executor = EXECUTOR.put(Executor::new());
79 67
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index aa48ceed5..7cf391394 100644
--- a/examples/stm32f4/src/bin/spi.rs
+++ b/examples/stm32f4/src/bin/spi.rs
@@ -14,38 +14,31 @@ use embedded_hal::digital::v2::OutputPin;
14use example_common::*; 14use example_common::*;
15 15
16use cortex_m_rt::entry; 16use cortex_m_rt::entry;
17use embassy_stm32::pac;
17use embassy_stm32::spi::{Config, Spi}; 18use embassy_stm32::spi::{Config, Spi};
18use embassy_stm32::time::Hertz; 19use embassy_stm32::time::Hertz;
19use embedded_hal::blocking::spi::Transfer; 20use embedded_hal::blocking::spi::Transfer;
20use stm32f4::stm32f429 as pac;
21 21
22#[entry] 22#[entry]
23fn main() -> ! { 23fn main() -> ! {
24 info!("Hello World, dude!"); 24 info!("Hello World, dude!");
25 25
26 let pp = pac::Peripherals::take().unwrap(); 26 unsafe {
27 27 pac::DBGMCU.cr().modify(|w| {
28 pp.DBGMCU.cr.modify(|_, w| { 28 w.set_dbg_sleep(true);
29 w.dbg_sleep().set_bit(); 29 w.set_dbg_standby(true);
30 w.dbg_standby().set_bit(); 30 w.set_dbg_stop(true);
31 w.dbg_stop().set_bit() 31 });
32 }); 32
33 pp.RCC.ahb1enr.modify(|_, w| w.dma1en().set_bit()); 33 pac::RCC.ahb1enr().modify(|w| {
34 34 w.set_gpioaen(true);
35 pp.RCC.apb1enr.modify(|_, w| { 35 w.set_gpioben(true);
36 w.spi3en().enabled(); 36 w.set_gpiocen(true);
37 w 37 w.set_gpioden(true);
38 }); 38 w.set_gpioeen(true);
39 39 w.set_gpiofen(true);
40 pp.RCC.ahb1enr.modify(|_, w| { 40 });
41 w.gpioaen().enabled(); 41 }
42 w.gpioben().enabled();
43 w.gpiocen().enabled();
44 w.gpioden().enabled();
45 w.gpioeen().enabled();
46 w.gpiofen().enabled();
47 w
48 });
49 42
50 let p = embassy_stm32::init(Default::default()); 43 let p = embassy_stm32::init(Default::default());
51 44
diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs
index 31525036a..dbe17c910 100644
--- a/examples/stm32f4/src/bin/usart.rs
+++ b/examples/stm32f4/src/bin/usart.rs
@@ -10,14 +10,13 @@
10mod example_common; 10mod example_common;
11use cortex_m::prelude::_embedded_hal_blocking_serial_Write; 11use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
12use embassy::executor::Executor; 12use embassy::executor::Executor;
13use embassy::time::Clock;
14use embassy::util::Forever; 13use embassy::util::Forever;
15use embassy_stm32::dma::NoDma; 14use embassy_stm32::dma::NoDma;
16use embassy_stm32::usart::{Config, Uart}; 15use embassy_stm32::usart::{Config, Uart};
17use example_common::*; 16use example_common::*;
18 17
19use cortex_m_rt::entry; 18use cortex_m_rt::entry;
20use stm32f4::stm32f429 as pac; 19use embassy_stm32::pac;
21 20
22#[embassy::task] 21#[embassy::task]
23async fn main_task() { 22async fn main_task() {
@@ -36,48 +35,28 @@ async fn main_task() {
36 } 35 }
37} 36}
38 37
39struct ZeroClock;
40
41impl Clock for ZeroClock {
42 fn now(&self) -> u64 {
43 0
44 }
45}
46
47static EXECUTOR: Forever<Executor> = Forever::new(); 38static EXECUTOR: Forever<Executor> = Forever::new();
48 39
49#[entry] 40#[entry]
50fn main() -> ! { 41fn main() -> ! {
51 info!("Hello World!"); 42 info!("Hello World!");
52 43
53 let pp = pac::Peripherals::take().unwrap(); 44 unsafe {
54 45 pac::DBGMCU.cr().modify(|w| {
55 pp.DBGMCU.cr.modify(|_, w| { 46 w.set_dbg_sleep(true);
56 w.dbg_sleep().set_bit(); 47 w.set_dbg_standby(true);
57 w.dbg_standby().set_bit(); 48 w.set_dbg_stop(true);
58 w.dbg_stop().set_bit() 49 });
59 }); 50
60 pp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled()); 51 pac::RCC.ahb1enr().modify(|w| {
61 52 w.set_gpioaen(true);
62 pp.RCC.ahb1enr.modify(|_, w| { 53 w.set_gpioben(true);
63 w.gpioaen().enabled(); 54 w.set_gpiocen(true);
64 w.gpioben().enabled(); 55 w.set_gpioden(true);
65 w.gpiocen().enabled(); 56 w.set_gpioeen(true);
66 w.gpioden().enabled(); 57 w.set_gpiofen(true);
67 w.gpioeen().enabled(); 58 });
68 w.gpiofen().enabled(); 59 }
69 w
70 });
71 pp.RCC.apb2enr.modify(|_, w| {
72 w.syscfgen().enabled();
73 w
74 });
75 pp.RCC.apb1enr.modify(|_, w| {
76 w.usart3en().enabled();
77 w
78 });
79
80 unsafe { embassy::time::set_clock(&ZeroClock) };
81 60
82 let executor = EXECUTOR.put(Executor::new()); 61 let executor = EXECUTOR.put(Executor::new());
83 62
diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs
index b578aebca..9de46375e 100644
--- a/examples/stm32f4/src/bin/usart_dma.rs
+++ b/examples/stm32f4/src/bin/usart_dma.rs
@@ -11,14 +11,13 @@ mod example_common;
11use core::fmt::Write; 11use core::fmt::Write;
12use cortex_m_rt::entry; 12use cortex_m_rt::entry;
13use embassy::executor::Executor; 13use embassy::executor::Executor;
14use embassy::time::Clock;
15use embassy::util::Forever; 14use embassy::util::Forever;
16use embassy_stm32::dma::NoDma; 15use embassy_stm32::dma::NoDma;
16use embassy_stm32::pac;
17use embassy_stm32::usart::{Config, Uart}; 17use embassy_stm32::usart::{Config, Uart};
18use embassy_traits::uart::Write as _; 18use embassy_traits::uart::Write as _;
19use example_common::*; 19use example_common::*;
20use heapless::String; 20use heapless::String;
21use stm32f4::stm32f429 as pac;
22 21
23#[embassy::task] 22#[embassy::task]
24async fn main_task() { 23async fn main_task() {
@@ -36,50 +35,28 @@ async fn main_task() {
36 } 35 }
37} 36}
38 37
39struct ZeroClock;
40
41impl Clock for ZeroClock {
42 fn now(&self) -> u64 {
43 0
44 }
45}
46
47static EXECUTOR: Forever<Executor> = Forever::new(); 38static EXECUTOR: Forever<Executor> = Forever::new();
48 39
49#[entry] 40#[entry]
50fn main() -> ! { 41fn main() -> ! {
51 info!("Hello World!"); 42 info!("Hello World!");
52 43
53 let pp = pac::Peripherals::take().unwrap(); 44 unsafe {
54 45 pac::DBGMCU.cr().modify(|w| {
55 pp.DBGMCU.cr.modify(|_, w| { 46 w.set_dbg_sleep(true);
56 w.dbg_sleep().set_bit(); 47 w.set_dbg_standby(true);
57 w.dbg_standby().set_bit(); 48 w.set_dbg_stop(true);
58 w.dbg_stop().set_bit()
59 }); 49 });
60 pp.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled());
61 50
62 pp.RCC.ahb1enr.modify(|_, w| { 51 pac::RCC.ahb1enr().modify(|w| {
63 w.gpioaen().enabled(); 52 w.set_gpioaen(true);
64 w.gpioben().enabled(); 53 w.set_gpioben(true);
65 w.gpiocen().enabled(); 54 w.set_gpiocen(true);
66 w.gpioden().enabled(); 55 w.set_gpioden(true);
67 w.gpioeen().enabled(); 56 w.set_gpioeen(true);
68 w.gpiofen().enabled(); 57 w.set_gpiofen(true);
69 w.dma1en().enabled();
70 w.dma2en().enabled();
71 w
72 }); 58 });
73 pp.RCC.apb2enr.modify(|_, w| { 59 }
74 w.syscfgen().enabled();
75 w
76 });
77 pp.RCC.apb1enr.modify(|_, w| {
78 w.usart3en().enabled();
79 w
80 });
81
82 unsafe { embassy::time::set_clock(&ZeroClock) };
83 60
84 let executor = EXECUTOR.put(Executor::new()); 61 let executor = EXECUTOR.put(Executor::new());
85 62