aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f4/src/bin/pwm.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs
new file mode 100644
index 000000000..cd20c68bb
--- /dev/null
+++ b/examples/stm32f4/src/bin/pwm.rs
@@ -0,0 +1,35 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::SimplePwm;
9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::U32Ext;
11use embassy_stm32::Peripherals;
12use {defmt_rtt as _, panic_probe as _};
13
14#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!");
17
18 let mut pwm = SimplePwm::new_1ch(p.TIM1, p.PE9, 10000.hz());
19 let max = pwm.get_max_duty();
20 pwm.enable(Channel::Ch1);
21
22 info!("PWM initialized");
23 info!("PWM max duty {}", max);
24
25 loop {
26 pwm.set_duty(Channel::Ch1, 0);
27 Timer::after(Duration::from_millis(300)).await;
28 pwm.set_duty(Channel::Ch1, max / 4);
29 Timer::after(Duration::from_millis(300)).await;
30 pwm.set_duty(Channel::Ch1, max / 2);
31 Timer::after(Duration::from_millis(300)).await;
32 pwm.set_duty(Channel::Ch1, max - 1);
33 Timer::after(Duration::from_millis(300)).await;
34 }
35}