aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBruno Bousquet <[email protected]>2024-05-29 00:28:26 -0400
committerBruno Bousquet <[email protected]>2024-05-29 00:28:26 -0400
commit521332bdd1d682b1d43ab7896b54e280c17b9771 (patch)
treeb691a43c6870f84a5a23565836f05bccc506c6ce /examples
parenta6c419d096bf2a4d14243fe90a7e2c1881b33fdf (diff)
pwm_input is working on F446
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f1/.vscode/launch.json2
-rw-r--r--examples/stm32f1/.vscode/tasks.json2
-rw-r--r--examples/stm32f1/src/bin/pwm_input.rs50
-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
6 files changed, 106 insertions, 4 deletions
diff --git a/examples/stm32f1/.vscode/launch.json b/examples/stm32f1/.vscode/launch.json
index 7d1504a39..998508867 100644
--- a/examples/stm32f1/.vscode/launch.json
+++ b/examples/stm32f1/.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/thumbv7m-none-eabi/debug/input_capture", 18 "executable": "./target/thumbv7m-none-eabi/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": "STM32F103TB", 21 "device": "STM32F103TB",
diff --git a/examples/stm32f1/.vscode/tasks.json b/examples/stm32f1/.vscode/tasks.json
index e153722da..de7013b12 100644
--- a/examples/stm32f1/.vscode/tasks.json
+++ b/examples/stm32f1/.vscode/tasks.json
@@ -9,7 +9,7 @@
9 ], 9 ],
10 "args": [ 10 "args": [
11 "--bin", 11 "--bin",
12 "input_capture" 12 "pwm_input"
13 ], 13 ],
14 "group": { 14 "group": {
15 "kind": "build", 15 "kind": "build",
diff --git a/examples/stm32f1/src/bin/pwm_input.rs b/examples/stm32f1/src/bin/pwm_input.rs
new file mode 100644
index 000000000..14978f817
--- /dev/null
+++ b/examples/stm32f1/src/bin/pwm_input.rs
@@ -0,0 +1,50 @@
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::{self, pwm_input::PwmInput};
9use embassy_stm32::{bind_interrupts, peripherals};
10use embassy_time::Timer;
11use {defmt_rtt as _, panic_probe as _};
12
13/// Connect PB2 and PB10 with a 1k Ohm resistor
14
15#[embassy_executor::task]
16async fn blinky(led: peripherals::PC13) {
17 let mut led = Output::new(led, Level::High, Speed::Low);
18
19 loop {
20 info!("high");
21 led.set_high();
22 Timer::after_millis(300).await;
23
24 info!("low");
25 led.set_low();
26 Timer::after_millis(300).await;
27 }
28}
29
30bind_interrupts!(struct Irqs {
31 TIM2 => timer::CaptureCompareInterruptHandler<peripherals::TIM2>;
32});
33
34#[embassy_executor::main]
35async fn main(spawner: Spawner) {
36 let p = embassy_stm32::init(Default::default());
37 info!("Hello World!");
38
39 unwrap!(spawner.spawn(blinky(p.PC13)));
40
41 let pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(1000));
42
43 loop {
44 Timer::after_millis(500).await;
45 let _per = pwm_input.get_period_ticks();
46 let _dc = pwm_input.get_duty_ticks();
47 let _pc = pwm_input.get_duty_cycle();
48 asm::nop();
49 }
50}
diff --git a/examples/stm32f4/.vscode/launch.json b/examples/stm32f4/.vscode/launch.json
index 20cd4d2e8..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/input_capture", 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 e153722da..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 "input_capture" 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..e57e58c22
--- /dev/null
+++ b/examples/stm32f4/src/bin/pwm_input.rs
@@ -0,0 +1,52 @@
1#![no_std]
2#![no_main]
3
4use cortex_m::asm;
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::gpio::{Level, Output, Pull, Speed};
8use embassy_stm32::time::khz;
9use embassy_stm32::timer::{self, pwm_input::PwmInput};
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 mut pwm_input = PwmInput::new(p.TIM3, p.PA6, Pull::None, khz(10));
43 pwm_input.enable();
44
45 loop {
46 Timer::after_millis(500).await;
47 let _per = pwm_input.get_period_ticks();
48 let _dc = pwm_input.get_duty_ticks();
49 let _pc = pwm_input.get_duty_cycle();
50 asm::nop();
51 }
52}