aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Bousquet <[email protected]>2024-05-28 20:36:23 -0400
committerBruno Bousquet <[email protected]>2024-05-28 20:36:23 -0400
commit41b9a12574f9ad992ca986b87926838fbe1f1775 (patch)
tree1dc5a01710fe2e9420566558d5aeb7a4c563be27
parent642465a7da64333b9339283f3b3a14cb04bd349e (diff)
compile pwm_input example
-rw-r--r--examples/stm32f4/.vscode/launch.json2
-rw-r--r--examples/stm32f4/.vscode/tasks.json2
-rw-r--r--examples/stm32f4/src/bin/pwm_input.rs52
-rw-r--r--rust-toolchain.toml2
4 files changed, 55 insertions, 3 deletions
diff --git a/examples/stm32f4/.vscode/launch.json b/examples/stm32f4/.vscode/launch.json
index 59f98070d..a9849e0da 100644
--- a/examples/stm32f4/.vscode/launch.json
+++ b/examples/stm32f4/.vscode/launch.json
@@ -15,7 +15,7 @@
15 "cwd": "${workspaceRoot}", 15 "cwd": "${workspaceRoot}",
16 "preLaunchTask": "Cargo Build (debug)", 16 "preLaunchTask": "Cargo Build (debug)",
17 "runToEntryPoint": "main", 17 "runToEntryPoint": "main",
18 "executable": "./target/thumbv7em-none-eabihf/debug/multiprio", 18 "executable": "./target/thumbv7em-none-eabihf/debug/pwm_input",
19 /* Run `cargo build --example itm` and uncomment this line to run itm example */ 19 /* Run `cargo build --example itm` and uncomment this line to run itm example */
20 // "executable": "./target/thumbv7em-none-eabihf/debug/examples/itm", 20 // "executable": "./target/thumbv7em-none-eabihf/debug/examples/itm",
21 "device": "STM32F446RET6", 21 "device": "STM32F446RET6",
diff --git a/examples/stm32f4/.vscode/tasks.json b/examples/stm32f4/.vscode/tasks.json
index 3cbed84b4..de7013b12 100644
--- a/examples/stm32f4/.vscode/tasks.json
+++ b/examples/stm32f4/.vscode/tasks.json
@@ -9,7 +9,7 @@
9 ], 9 ],
10 "args": [ 10 "args": [
11 "--bin", 11 "--bin",
12 "multiprio" 12 "pwm_input"
13 ], 13 ],
14 "group": { 14 "group": {
15 "kind": "build", 15 "kind": "build",
diff --git a/examples/stm32f4/src/bin/pwm_input.rs b/examples/stm32f4/src/bin/pwm_input.rs
new file mode 100644
index 000000000..49de33d2b
--- /dev/null
+++ b/examples/stm32f4/src/bin/pwm_input.rs
@@ -0,0 +1,52 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_stm32::gpio::{Level, Output, Pull, Speed};
7use embassy_stm32::time::khz;
8use embassy_stm32::timer::input_capture::{CapturePin, InputCapture};
9use embassy_stm32::timer::{self, Channel};
10use embassy_stm32::{bind_interrupts, peripherals};
11use embassy_time::Timer;
12use {defmt_rtt as _, panic_probe as _};
13
14/// Connect PB2 and PB10 with a 1k Ohm resistor
15
16#[embassy_executor::task]
17async fn blinky(led: peripherals::PB2) {
18 let mut led = Output::new(led, Level::High, Speed::Low);
19
20 loop {
21 info!("high");
22 led.set_high();
23 Timer::after_millis(300).await;
24
25 info!("low");
26 led.set_low();
27 Timer::after_millis(300).await;
28 }
29}
30
31bind_interrupts!(struct Irqs {
32 TIM2 => timer::CaptureCompareInterruptHandler<peripherals::TIM2>;
33});
34
35#[embassy_executor::main]
36async fn main(spawner: Spawner) {
37 let p = embassy_stm32::init(Default::default());
38 info!("Hello World!");
39
40 unwrap!(spawner.spawn(blinky(p.PB2)));
41
42 let ch3 = CapturePin::new_ch3(p.PB10, Pull::None);
43 let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, Irqs, khz(1000), Default::default());
44
45 loop {
46 info!("wait for risign edge");
47 ic.wait_for_rising_edge(Channel::Ch3).await;
48
49 let capture_value = ic.get_capture_value(Channel::Ch3);
50 info!("new capture! {}", capture_value);
51 }
52}
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index 57185e217..2f5d17069 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,5 +1,5 @@
1[toolchain] 1[toolchain]
2channel = "1.78" 2channel = "1.77"
3components = [ "rust-src", "rustfmt", "llvm-tools" ] 3components = [ "rust-src", "rustfmt", "llvm-tools" ]
4targets = [ 4targets = [
5 "thumbv7em-none-eabi", 5 "thumbv7em-none-eabi",