diff options
| author | Bruno Bousquet <[email protected]> | 2024-05-29 00:28:26 -0400 |
|---|---|---|
| committer | Bruno Bousquet <[email protected]> | 2024-05-29 00:28:26 -0400 |
| commit | 521332bdd1d682b1d43ab7896b54e280c17b9771 (patch) | |
| tree | b691a43c6870f84a5a23565836f05bccc506c6ce /examples | |
| parent | a6c419d096bf2a4d14243fe90a7e2c1881b33fdf (diff) | |
pwm_input is working on F446
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f1/.vscode/launch.json | 2 | ||||
| -rw-r--r-- | examples/stm32f1/.vscode/tasks.json | 2 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/pwm_input.rs | 50 | ||||
| -rw-r--r-- | examples/stm32f4/.vscode/launch.json | 2 | ||||
| -rw-r--r-- | examples/stm32f4/.vscode/tasks.json | 2 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/pwm_input.rs | 52 |
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 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | ||
| 7 | use embassy_stm32::time::khz; | ||
| 8 | use embassy_stm32::timer::{self, pwm_input::PwmInput}; | ||
| 9 | use embassy_stm32::{bind_interrupts, peripherals}; | ||
| 10 | use embassy_time::Timer; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | /// Connect PB2 and PB10 with a 1k Ohm resistor | ||
| 14 | |||
| 15 | #[embassy_executor::task] | ||
| 16 | async 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 | |||
| 30 | bind_interrupts!(struct Irqs { | ||
| 31 | TIM2 => timer::CaptureCompareInterruptHandler<peripherals::TIM2>; | ||
| 32 | }); | ||
| 33 | |||
| 34 | #[embassy_executor::main] | ||
| 35 | async 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 | |||
| 4 | use cortex_m::asm; | ||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | ||
| 8 | use embassy_stm32::time::khz; | ||
| 9 | use embassy_stm32::timer::{self, pwm_input::PwmInput}; | ||
| 10 | use embassy_stm32::{bind_interrupts, peripherals}; | ||
| 11 | use embassy_time::Timer; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | /// Connect PB2 and PB10 with a 1k Ohm resistor | ||
| 15 | |||
| 16 | #[embassy_executor::task] | ||
| 17 | async 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 | |||
| 31 | bind_interrupts!(struct Irqs { | ||
| 32 | TIM2 => timer::CaptureCompareInterruptHandler<peripherals::TIM2>; | ||
| 33 | }); | ||
| 34 | |||
| 35 | #[embassy_executor::main] | ||
| 36 | async 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 | } | ||
